Programming language definited for the Compiler course from University.
JFlex and JavaCup integration for MyPallene language implementation.
| Token | Lexeme |
|---|---|
| FUNCTION | "function" |
| MAIN | "main" |
| LPAR | "(" |
| RPAR | ")" |
| END | "end" |
| ID | Java id format |
| COLON | ":" |
| GLOBAL | {"global"} |
| SEMI | ";" |
| COMMA | "," |
| NIL | "nil" |
| INT | "int" |
| BOOL | "bool" |
| FLOAT | "float" |
| STRING | "string" |
| BLPAR | "{" |
| BRPAR | "}" |
| ARROW | "->" |
| ASSIGN | "=" |
| NOP | "nop" |
| WHILE | "while" |
| DO | "do" |
| IF | "if" |
| THEN | "then" |
| ELSE | "else" |
| FOR | "for" |
| LOCAL | "local" |
| SLPAR | "[" |
| SRPAR | "]" |
| READ | "<==" |
| WRITE | "==>" |
| RETURN | "return" |
| TRUE | "true" |
| FALSE | "false" |
| INT_CONST | Java Decimal integer format |
| FLOAT_CONST | Java float format |
| STRING_CONST | Java format constant format |
| PLUS | "+" |
| MINUS | "-" |
| TIMES | "*" |
| DIV | "/" |
| AND | "and" |
| OR | "or" |
| GT | ">" |
| GE | ">=" |
| LT | "<" |
| LE | "<=" |
| EQ | "==" |
| NE | "!=" |
| NOT | "not" |
| SHARP | "#" |
Program ::= Global Functions
;
Global ::= GLOBAL Var_decls END
| /* empty */
;
Functions ::= Def_fun Functions
| Def_fun
;
Def_fun ::= FUNCTION ID LPAR Par_decls RPAR COLON TypeDenoter Statements END
| FUNCTION ID LPAR RPAR COLON TypeDenoter Statements END
;
Par_decls ::= ID COLON TypeDenoter COMMA Par_decls
| ID COLON TypeDenoter
;
Var_decls ::= Var_decls SEMI ID COLON TypeDenoter Var_init_value
| ID COLON TypeDenoter Var_init_value
;
Var_init_value ::= ASSIGN Expr
| /* empty */
;
TypeDenoter ::= NIL | INT | BOOL | FLOAT | STRING
| BLPAR TypeDenoter BRPAR
| LPAR Types RPAR ARROW TypeDenoter
| LPAR RPAR ARROW TypeDenoter
;
Types ::= TypeDenoter COMMA Types
| TypeDenoter
;
Statements ::= Stat SEMI Statements
| Stat
;
Stat ::= NOP
| WHILE Expr DO Statements END
| IF Expr THEN Statements END
| IF Expr THEN Statements ELSE Statements END
| FOR ID ASSIGN Expr COMMA Expr DO Statements END
| LOCAL Var_decls SEMI Statements END
| ID ASSIGN Expr
| Expr SLPAR Expr SRPAR ASSIGN Expr
| ID LPAR Exprs RPAR
| ID LPAR RPAR
| Vars READ
| Exprs WRITE
| RETURN Expr
| error
;
Vars ::= ID COMMA Vars
| ID
;
Exprs ::= Expr COMMA Exprs
| Expr
;
Expr ::= NIL
| TRUE
| FALSE
| INT_CONST
| FLOAT_CONST
| STRING_CONST
| BLPAR BRPAR COLON TypeDenoter
| ID
| Expr SLPAR Expr SRPAR
| ID LPAR Exprs RPAR
| ID LPAR RPAR
| Expr PLUS Expr
| Expr MINUS Expr
| Expr TIMES Expr
| Expr DIV Expr
| Expr AND Expr
| Expr OR Expr
| Expr GT Expr
| Expr GE Expr
| Expr LT Expr
| Expr LE Expr
| Expr EQ Expr
| Expr NE Expr
| MINUS Expr
| NOT Expr
| SHARP Expr
;The compiler is the src/cli.MyPallene.java class.
-
src-
clipackage contains the compiler class and the main class. -
distpackage contains the output files of CUP and jFlex -
errorpackage contains the error handler -
lexicalpackage contains the string table used during the compilation -
nodekindandnodetypepackage contains the kind class and the type class of a node -
resourcepackage contains the template c file -
semanticpackage contains the symbol table classes -
syntaxpackage contains the AST node classes -
templatepackage contains the template classes used in translation to XML and C -
testpackage contains some test classes -
visitorpackage contains the visitor classes used for scopechecking, typechecking and translation
-
-
srcflexcupfolder contains the CUP and jFlex input files -
test_filesfolder contains some myPallene's test files
- Execute
MyPallene2C.java <filePath>or justMyPallene2C.javalocated in theclipackage. - In the first case it compile the
-mpfile in thefilePathor it shows a menu for select an example file to compile. - Once you launched the compiler, three file are generate:
file.xml- contains the ASTfile.c- contains the .c output filefile.c.ll- contains the LLVM IR file
For compile CUP file launch:
java -jar C:\CUP\java-cup-11b.jar -dump -progress -locations -expect 5 -destdir .\src\dist\ .\srcjflexcup\Parser.cup 2>.\out.txtFor compile jFLEX file launch:
..\jflex-1.7.0\bin\jflex -d .\src\dist\ srcjflexcup\Lexer.flex