Skip to content

The final project of the Principles of Compiler Design course

License

Notifications You must be signed in to change notification settings

2000mahan/Internet-Engineering-HW1-Q1

Repository files navigation

Compiler Design Project

Table of Contents
  1. About The Project
  2. License
  3. Contact
  4. Acknowledgments
  5. Phases

About The Project

This is the final project of the Principles of Compiler Design course using Lex & Yacc.

Contributers

Mahan Ahmadvand
Mohammad Sami

Built With

License

Distributed under the GNU License. See LICENSE.txt for more information.

(back to top)

Contact

Your Name - Mahan Ahmadvand

Project Link: https://github.com/2000mahan/web-engineering-HW1

(back to top)

Acknowledgments

(back to top)

Phases

Phase 1

Lexical Analyzer

Lexeme Token Value
Identifier ID
Integer number INTEGERNUMBER
Float number FLOATNUMBER
"int" INTEGER
"float" FLOAT
"bool" BOOLEAN
"fun" FUNCTION
"True" TRUE
"False" FALSE
"print" PRINT
"return" RETURN
"main" MAIN
"if" IF
"else" ELSE
"elseif" ELSEIF
"while" WHILE
"on" ON
"where" WHERE
"for" FOR
"and" AND
"or" OR
"not" NOT
"in" IN
"=" ASSIGN
"+" SUM
"-" SUB
"*" MUL
"/" DIV
"%" MOD
">" GT
">=" GE
"<" LT
"<=" LE
"==" EQ
"!=" NE
"{" LCB
"}" RCB
"(" LRB
")" RRB
"[" LSB
"]" RSB
";" SEMICOLON
":" COLON
"," COMMA
"Error" ERROR!

(back to top)

Phase 2

Parser
Grammar :
program -> declist main () block
declist -> dec | declist dec | ε
dec -> vardec | funcdec
type -> int | float | bool
iddec -> id |id [exp] | id=exp
idlist -> iddec | idlist, iddec
vardec -> idlist:type;
funcdec -> fun id (paramdecs):type block | fun id (paramdecs) block
paramdecs -> paramdecslist | ε
paramdecslist -> paramdec | paramdecslist, paramdec
paramdec -> id:type | id []:type
block -> {stmtlist}
stmtlist -> stmt | stmlist stmt | ε
lvalue -> id | id[exp]
case -> where const:stmtlist
cases -> case | cases case | ε
stmt -> return exp; | exp; | block | vardec | while (exp) stmt | on (exp) {cases}; | for (exp; exp; exp) stmt | for (id in id) stmt | if (exp) stmt elseiflist | if (exp) stmt elseif else stmt | print (id)
elseiflist -> elseif (exp) stmt | elseiflist elseif (exp) stmt | ε
relopexp -> exp relop exp | relopexp relop exp
exp -> lvalue=exp | exp operator exp | relopexp | const | lvalue | id (explist) | (exp) | id () | - exp | not exp
operator -> and | or | + | - | * | / | %
const -> intnumber | floatnumber | True | False
relop -> > | < | != | == | <= | >=
explist -> exp | explist, exp

(back to top)

Phase 3

Intermediate Code Generation
alt text

(back to top)

About

The final project of the Principles of Compiler Design course

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages