A multi-pass compiler written in Go comprised of scanner, recursive-descent parser, generation of AST, intermediate representation (ILOC), and code generation (Armv8).

Overview

GoLite Project - Go Huskies!

This is a project conducted and led in the course MPCS 51300 Compilers at the University of Chicago. In a group of two, we developed a multi-pass compiler in Go through building scanner, recursive-descent parser, generation of AST, intermediate representation (ILOC), and code generation (Armv8) from scratch.

Group Members

Qi An: [email protected]
Yuanheng Zhao: [email protected], [email protected]

MileStone 1 - Scanner

Testing for Scanner:

  1. The tested files should be saved in the directory of proj/golite/scanner.
  2. Usage of -lex: Run the command below from the directory ../proj-gohuskies/proj/golite/, go run golite.go -lex scanner/test1.golite

Expected test result: The expected output is displayed sequentially in the format of {token_type}({line_number})

Example Output:

Token.PACK(1)
Token.ID(1)       
Token.SEMICOLON(1)
Token.COMMENT(1)  
Token.IMPORT(3)   
Token.QTDMARK(3)  
Token.FMT(3)      
Token.QTDMARK(3)  
Token.SEMICOLON(3)
Token.ID(4)       
Token.ASSIGN(4)   
Token.NUM(4)      
Token.SEMICOLON(4)
Token.EOF(4)

MileStone 2 - Parser and Semantic Analysis

Testing for Parser:

  1. The tested files should be saved in the directory of proj/golite/parser.
  2. Usage of -ast: Run the command below from the directory ../proj-gohuskies/proj/golite/, go run golite.go -ast parser/test1_parser.golite

Expected test result: The displayed output is expected to be the same as the content of the test file.

Example Output:

package main;
import "fmt";
func main () {
var a int;
a = 1+1;

}

MileStone 3 - ILOC

Testing for ILOC:

  1. The tested files should be saved in the directory of proj/golite/iloc.
  2. Usage of -iloc: Run the command below from the directory ../proj-gohuskies/proj/golite/, go run golite.go -iloc iloc/test3_iloc.golite

Expected test result: The expected output is displayed sequentially of the ILOC instructions of the source code in test file.

Example Output:

main:
    mov r2,#3
    mov r1,r2
    mov r3,#6
    add r4,r1,r3
    mov r0,r4
    print r0
    b condLabel_L1
loopBody_L2:
    mov r5,#1
    sub r6,r1,r5
    mov r1,r6
    print r1
condLabel_L1:
    mov r7,#0
    mov r8,#0
    cmp r1,r7
    movgt r8,#1
    cmp r8,#1
    beq loopBody_L2

MileStone 4 (Final Submission) - Assembly

Usage of -S:

  1. go to directory ../proj-gohuskies/proj/golite/
  2. Example: go run golite.go -S .\arm\test1_arm.golite
  3. check the directory of ../proj-gohuskies/proj/golite, the output file should be in the same folder as golite.go

Example Output:

	.arch armv8-a
	.comm d,8,8
	.comm e,8,8
	.text
	.type main,%function
	.global main
	.p2align		2
main:
	sub sp,sp,16
	stp x29,x30,[sp]
	mov x29,sp
	sub sp,sp,#48
	mov x1,#7
	str x1,[x29,#-8]
	ldr x2,[x29,#-8]
	mov x1,x2
	str x1,[x29,#-16]
	mov x1,#3
	str x1,[x29,#-24]
	ldr x2,[x29,#-24]
	mov x1,x2
	str x1,[x29,#-32]
	ldr x1,[x29,#-16]
	ldr x2,[x29,#-32]
	add x3,x1,x2
	str x3,[x29,#-40]
	ldr x2,[x29,#-40]
	mov x1,x2
	str x1,[x29,#-48]
	add sp,sp,#48
	ldp x29,x30,[sp]
	add sp,sp,16
	ret
	.size main,(.-main)
You might also like...
Floppa programming language inspired by the brainf*ck programming language. Created just for fun and you can convert your brainf*ck code to floppa code.

Floppa Programming Language Created just for fun. But if you want to contribute, why not? Floppa p.l. inspired by the brainf*ck programming language.

A shell parser, formatter, and interpreter with bash support; includes shfmt

sh A shell parser, formatter, and interpreter. Supports POSIX Shell, Bash, and mksh. Requires Go 1.14 or later. Quick start To parse shell scripts, in

Port of the lemon parser generator to the Go programming language

From the golang-nuts mailing list (with few modifications): --== intro ==-- Hi. I just want to announce a simple port of the lemon parser generator

An LL(1) parser generator for the Go programming language.

What is it? I have implemented an LL(1) parser generator for the Go programming language. I did this to build parse trees for my HAML parser. You can

CxGo is a tool for translating C source code to Go

C to Go translator CxGo is a tool for translating C source code to Go (aka transpiler, source-to-source compiler). It uses cc for preprocessing and pa

❄️ Elsa is a minimal, fast and secure runtime for JavaScript and TypeScript written in Go

Elsa Elsa is a minimal, fast and secure runtime for JavaScript and TypeScript written in Go, leveraging the power from QuickJS. Features URL based imp

A standalone nREPL/prepl client written in Go and heavily inspired by Grenchman

Trenchman A standalone nREPL/prepl client written in Go, heavily inspired by Grenchman Trenchman is a standalone nREPL/prepl client, which means that

Scriptable interpreter written in golang
Scriptable interpreter written in golang

Anko Anko is a scriptable interpreter written in Go. (Picture licensed under CC BY-SA 3.0, photo by Ocdp) Usage Example - Embedded package main impor

A POSIX-compliant AWK interpreter written in Go

GoAWK: an AWK interpreter written in Go AWK is a fascinating text-processing language, and somehow after reading the delightfully-terse The AWK Progra

Owner
ocd_with_naming
Hello! I am a masters student currently studying Computer Science at the University of Chicago, with interests in software and data engineering.
ocd_with_naming
ReCT-Go-Compiler - A compiler for the ReCT programming language written in Golang

ReCT-Go-Compiler A compiler for the ReCT programming language written in Golang

null 6 Nov 30, 2022
Go compiler made from scratch, which can compile itself. It's going to be the smallest and simplest go compiler in the world.

Babygo, a go compiler made from scratch Babygo is a small and simple go compiler. (Smallest and simplest in the world, I believe.) It is made from scr

DQNEO 231 Jan 8, 2023
Gentee - script programming language for automation. It uses VM and compiler written in Go (Golang).

Gentee script programming language Gentee is a free open source script programming language. The Gentee programming language is designed to create scr

Alexey Krivonogov 101 Dec 15, 2022
A simple virtual machine - compiler & interpreter - written in golang

go.vm Installation Build without Go Modules (Go before 1.11) Build with Go Modules (Go 1.11 or higher) Usage Opcodes Notes The compiler The interprete

Steve Kemp 262 Dec 17, 2022
GopherLua: VM and compiler for Lua in Go

GopherLua: VM and compiler for Lua in Go. GopherLua is a Lua5.1 VM and compiler written in Go. GopherLua has a same goal with Lua: Be a scripting lang

Yusuke Inuzuka 5.2k Dec 31, 2022
Monkey programming language project from 'Writing An Interpreter In Go'and 'Writing A Compiler In Go' Books

Monkey Monkey programming language ?? project from "Writing An Interpreter In Go

Amr Hesham 1 Dec 16, 2021
Compiler for a small language into x86-64 Assembly

Compiler This project is a small compiler, that compiles my own little language into X86-64 Assembly. It then uses yasm and ld to assemble and link in

Maurice Tollmien 242 Dec 13, 2022
Cc - Toy C compiler for golang

Grammars program = funcDecl* decl = declspec declarator ("{" compou

Kazuki Nitta 1 May 2, 2022
Bfc - A compiler for brainfuck by someone who has no idea how compilers work

bfc bfc is a bad (probably) Brainfuck compiler. It compiles only to x64 assembly

Liam Galvin 3 Feb 5, 2022
A basic Forth parser written in Go.

GoForth ======= I got really interested in Forth and thus I began making a parser, of sorts, in Go. Though I don't intend for it to catch on, it's st

Artem Titoulenko 21 Mar 1, 2022