Giter Site home page Giter Site logo

simple-compiler's Introduction

Simple Compiler

Simple compiler program with given grammar.

Use LL(1) Parser for parsing, and use Sethi-Ullman algorithm for register allocation.

Dependencies

  • Python == 3.7

Usage

python main.py [INPUT_FILE]

Result Example

Input file

  • Compile input_code.txt
func () {
    int a;
    int b;
    int c;
    int dd;
    a = 3;
    b = 2;
    IF a < b THEN { c = 1; } ELSE { c = 2; }
    dd = a+c;
}

Command

  • Run program as below
$ python main.py input_code.txt

The number of register used: 2

Result files

  • input_code.symbol
Scope: 0
	Symbol: func (type: FUNCTION)
Scope: 1
	Symbol: a (type: INT) [addr: 1000]
	Symbol: b (type: INT) [addr: 1004]
	Symbol: c (type: INT) [addr: 1008]
	Symbol: dd (type: INT) [addr: 1012]
  • input_code.code
BEGIN	func
LD	R0, 3
ST	R0, (1000)
LD	R0, 2
ST	R0, (1004)
LD	R0, (1000)
LD	R1, (1004)
LT	R0, R0, R1
JUMPF	R0, ELSE0
LD	R0, 1
ST	R0, (1008)
JUMP	END0
ELSE0:
LD	R0, 2
ST	R0, (1008)
END0:
LD	R0, (1000)
LD	R1, (1008)
ADD	R0, R0, R1
ST	R0, (1012)
EXIT:
END	func

Contributor

simple-compiler's People

Contributors

input0 avatar nuxlear avatar jlake310 avatar

Stargazers

Yejin Lee avatar Andrew Johnson avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.