We build a compiler for a simplified language based on Lua. On the front end stages, we used a pure-Python implementation of the popular tools lex and yacc, the PLY (Python Lex-Yacc).
First, you must run the front end stages (lexical and syntatic), semantic and code generation with just one line described below. The input_file
is your source code.
$ python main.py input_file output_file
After that, you'll execute your output_file
using SPIM simulator (see details here). Download the SPIM simulator in this link.
Our language supports procedural programming. An identifier can be composed of letters, digits and underscore only. The first letter of identifier should be a letter.
The keywords below represented can't be used as identifier.
and do else while then
end for if var or
More lexical items allowed:
+ - * / <= >= < >
( ) ; , == ~= =
The syntax is described in E-BNF (Extended BNF) and BNF notations, and for Jison to display an interactive parsing table check here.
We defined the operators precedence like the convention of C language.
For this implementation, we only used the function call for print(exp)
that will be used a syscall on MIPS. Semantic errors are been checked in code generation.
The code is generated to MIPS architecture using a stack machine strategy.