Add production rules that seem to work

This commit is contained in:
Danila Fedorin 2019-05-12 12:53:04 -07:00
parent 8d8f3f8c10
commit 51b20b280d

View File

@ -2,6 +2,7 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <set>
#include "parser.hpp" #include "parser.hpp"
%} %}
@ -51,25 +52,87 @@ void yyerror(const char* s) {
std::cout << s << std::endl; std::cout << s << std::endl;
} }
std::set<std::string> varset;
%} %}
%% %%
program program
: program stmt : stmts
;
stmts
: stmts stmt
| stmt | stmt
; ;
stmt stmt
: expr NEWLINE; : expr NEWLINE
| if
| while
| BREAK NEWLINE
;
expr expr
: assign : assign
| INTEGER | eq
;
while
: WHILE expr COLON NEWLINE block
;
if
: IF expr COLON NEWLINE block ifend
| IF expr COLON NEWLINE block
;
ifend
: ELIF expr COLON NEWLINE block ifend
| ELIF expr COLON NEWLINE block
| ELSE COLON NEWLINE block
block
: INDENT stmts DEDENT
; ;
assign assign
: IDENTIFIER ASSIGN expr : IDENTIFIER ASSIGN expr
; ;
eq
: eq EQ rel
| eq NEQ rel
| rel
;
rel
: rel LT sum
| rel LTE sum
| rel GT sum
| rel GTE sum
| sum
;
sum
: sum PLUS factor
| sum MINUS factor
| factor
;
factor
: factor TIMES term
| factor DIVIDEDBY term
| term
;
term
: IDENTIFIER
| FLOAT
| INTEGER
| BOOLEAN
| LPAREN expr RPAREN
;
%% %%