Table of Contents
This is the final project of the Principles of Compiler Design course using Lex & Yacc.
Distributed under the GNU License. See LICENSE.txt
for more information.
Your Name - Mahan Ahmadvand
Project Link: https://github.com/2000mahan/web-engineering-HW1
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" | |
"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! |
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