File tree Expand file tree Collapse file tree 1 file changed +30
-20
lines changed Expand file tree Collapse file tree 1 file changed +30
-20
lines changed Original file line number Diff line number Diff line change @@ -6,32 +6,42 @@ One day hopefully a simple Swift interpreter for the Pascal language inspired by
66Lexer, parser and interpreter for the following grammar
77
88````
9- program : compound_statement DOT
10-
9+ program : PROGRAM variable SEMI block DOT
10+
11+ block : declarations compound_statement
12+
13+ declarations : VAR (variable_declaration SEMI)+
14+ | empty
15+
16+ variable_declaration : ID (COMMA ID)* COLON type_spec
17+
18+ type_spec : INTEGER
19+
1120compound_statement : BEGIN statement_list END
12-
21+
1322statement_list : statement
14- | statement SEMI statement_list
15-
23+ | statement SEMI statement_list
24+
1625statement : compound_statement
17- | assignment_statement
18- | empty
19-
26+ | assignment_statement
27+ | empty
28+
2029assignment_statement : variable ASSIGN expr
21-
30+
2231empty :
23-
24- expr: term ((PLUS | MINUS) term)*
25-
26- term: factor ((MUL | DIV ) factor)*
27-
32+
33+ expr : term ((PLUS | MINUS) term)*
34+
35+ term : factor ((MUL | INTEGER_DIV | FLOAT_DIV ) factor)*
36+
2837factor : PLUS factor
29- | MINUS factor
30- | INTEGER
31- | LPAREN expr RPAREN
32- | variable
33-
34- variable: ID
38+ | MINUS factor
39+ | INTEGER_CONST
40+ | REAL_CONST
41+ | LPAREN expr RPAREN
42+ | variable
43+
44+ variable: ID
3545````
3646
3747## Try it out
You can’t perform that action at this time.
0 commit comments