Skip to content

Instantly share code, notes, and snippets.

View OChicken's full-sized avatar

Shouran MA OChicken

View GitHub Profile

用Moonbit实现一个小型的编译器

引言

编程语言设计与编译器实现历来被视为计算机科学领域的一个复杂而深奥的主题。传统上,学生需要在学校里学习复杂的自动机理论,类型理论,计算机底层等才能尝试开发一个自己的编程语言和编译器。Moonbit作为一门现代函数式语言,不仅拥有严谨的类型系统和出色的安全保障,更配备了专为AI时代设计的工具链,为开发者提供了丰富的语法特性,各种特性使得Moonbit成为一个特别适合用于开发编译器的语言。

本文将通过构建一个名为TinyMoonbit的小型语言的编译器,深入探讨编译器实现的核心概念。本文将简单设计编译器开发的四个阶段,词法分析,语法分析,语义分析与类型检查,以及代码生成。

关于本文的代码:由于篇幅所限,本文所展示的代码不是很全,读者可以参考https://github.com/Kaida-Amethyst/TinyMoonbit,这个仓库实现了比本文稍微复杂一点的TinyMoonbit。

@jiacai2050
jiacai2050 / podcast-fetcher.go
Created November 27, 2023 13:55
Download podcasts
package main
import (
"encoding/xml"
"flag"
"fmt"
"go-apps/pkg/flagx"
"go-apps/pkg/util"
"io"
"log"
@fergiemcdowall
fergiemcdowall / README.md
Last active March 8, 2025 10:51
How to use pandoc to generate HTML from GitHub-flavoured markdown

Here is a little recipe for generating html from github-flavoured markdown. CSS extracted and modified from https://github.com/sindresorhus/github-markdown-css on 22-05-2019. At some point this CSS will probably have to be updated, but for now it works.

  1. Install pandoc 2.x or higher

  2. Save github-markdown.css (below) to ´~/.pandoc/github-markdown.css´

  3. To convert a file called README.md (change as appropriate) run ´pandoc --standalone -c ~/.pandoc/github-markdown.css -f gfm -t html README.md´

@qpwo
qpwo / monte_carlo_tree_search.py
Last active June 12, 2025 22:56
Monte Carlo tree search (MCTS) minimal implementation in Python 3, with a tic-tac-toe example gameplay
"""
A minimal implementation of Monte Carlo tree search (MCTS) in Python 3
Luke Harold Miles, July 2019, Public Domain Dedication
See also https://en.wikipedia.org/wiki/Monte_Carlo_tree_search
https://gist.github.com/qpwo/c538c6f73727e254fdc7fab81024f6e1
"""
from abc import ABC, abstractmethod
from collections import defaultdict
import math
@bignall
bignall / dont-lose-konsole-terminal-sessions-on-reboot.md
Last active July 12, 2023 12:22 — forked from bguiz/dont-lose-gnome-terminal-sessions-on-reboot.md
Ensures that you don't lose your konsole sessions when you crash/ reboot Linux

Usage

  • Save the two files below. I put them in '~/.scripts'
  • Modify the configuration in konsole-watcher.sh to your liking
  • Modify the location of konsole-watcher.sh in konsole-watcher-autostart.sh if you chose to put it somewhere besides ~/.scripts
  • Create the directory ~/.konsole (or other location you chose for the save file)
  • Create a symlink to konsole-watcher-autostart.sh in '~/.config/autostart-scripts
  • or open System Settings > Startup and Shutdown and add a script to the Script Files (it does the same thing as creating the symlink)
  • You might want to add a menu entry as well in case KDE autostart doesn't work for some reason
@PurpleBooth
PurpleBooth / README-Template.md
Last active July 6, 2025 08:17
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

/*
SSSE3/XOP bit reversal
Written in 2014 by Samuel Neves <[email protected]>
To the extent possible under law, the author(s) have dedicated all copyright
and related and neighboring rights to this software to the public domain
worldwide. This software is distributed without any warranty.
You should have received a copy of the CC0 Public Domain Dedication along with
@hectorcorrea
hectorcorrea / webserver.js
Last active June 29, 2024 12:51
web server in node.js
// A very basic web server in node.js
// Stolen from: Node.js for Front-End Developers by Garann Means (p. 9-10)
var port = 8000;
var serverUrl = "127.0.0.1";
var http = require("http");
var path = require("path");
var fs = require("fs");
var checkMimeType = true;
@jxson
jxson / README.md
Created February 10, 2012 00:18
README.md template

Synopsis

At the top of the file there should be a short introduction and/ or overview that explains what the project is. This description should match descriptions added for package managers (Gemspec, package.json, etc.)

Code Example

Show what the library does as concisely as possible, developers should be able to figure out how your project solves their problem by looking at the code example. Make sure the API you are showing off is obvious, and that your code is short and concise.

Motivation