1.0.1 • Published 7 years ago
@alu0100973914/infix2egg-in-jison v1.0.1
Practice 9 of PL: Infix to Egg in Jison (i2eij)
Egg repository
Infix to Egg repository
Compatibilities
Infix to Egg in Jison has the same features than Infix to Egg. The same tests created for testing Infix to Egg behaviour are passed by Infix to Egg in Jison (51/51):+1:.
Grammar
Jison grammar with semantic actions can be found in the file i2e-parser.jison of the lib folder. To generate the parser try the command below:
jison lib/i2e-parser.jison -o lib/i2e-parser.js
Jison file without semantic actions
%lex
%%
(\s+|"//".*|"/*"[^]*?"*/") /* whitespace */
[-+]?[0-9]*"."?[0-9]+([eE][+-]?[0-9]+)? return 'NUMBER'
"\"".*?"\"" return 'STRING'
("true"|"false") return 'LOGICVALUE'
("&&"|"||") return 'LOGOP'
("<"|">"|"=="|"<="|">=") return 'COMPOP'
("+"|"-") return 'ADDOP'
("*"|"/") return 'MULOP'
"(" return 'LP'
")" return 'RP'
"{" return 'LB'
"}" return 'RB'
"," return 'COMMA'
";" return 'SEMICOLON'
"=" return 'ASSIGN'
"var" return 'KW_VAR'
"function" return 'KW_FUNCTION'
"if" return 'KW_IF'
"else" return 'KW_ELSE'
"while" return 'KW_WHILE'
[^\s(){},"'?:;]+ return 'WORD'
<<EOF>> return 'EOF'
/lex
/* operator associations and precedence */
%right 'ASSIGN'
%left 'LOGOP'
%left 'COMPOP'
%left 'ADDOP'
%left 'MULOP'
%start program
%% /* language grammar */
program
: statements EOF
;
statements
: statements statement
| statement
;
statement
: declaration
| assignment
| conditional
| function_call
| function
| loop
;
declaration
: KW_VAR assignment
;
assignment
: WORD ASSIGN expr SEMICOLON
| WORD ASSIGN anonym_function
;
anonym_function
: KW_FUNCTION LP arguments_list RP block
| KW_FUNCTION LP RP block
;
function_call
: WORD LP arguments_list RP SEMICOLON
| WORD LP RP SEMICOLON
;
function
: KW_FUNCTION WORD LP arguments_list RP block
| KW_FUNCTION WORD LP RP block
;
arguments_list
: expr
| arguments_list COMMA expr
;
block
: LB statements RB
;
conditional
: KW_IF LP expr RP block
| KW_IF LP expr RP block KW_ELSE block
| KW_IF LP expr RP block KW_ELSE conditional
;
loop
: KW_WHILE LP expr RP block
;
expr
: comp_expr
| expr LOGOP comp_expr
;
comp_expr
: ar_expr
| comp_expr COMPOP ar_expr
;
ar_expr
: product
| ar_expr ADDOP product
;
product
: final_expression
| product MULOP final_expression
;
final_expression
: LP expr RP
| WORD
| NUMBER
| STRING
| LOGICVALUE
;