File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,7 +17,23 @@ A simple Pascal interpreter based on [Let's Build a Simple Interpreter](https://
1717## Grammar
1818
1919``` ebnf
20- <program> ::= <compound_statement> <DOT>
20+ # Program
21+
22+ <program> ::= <PROGRAM> <variable> <SEMI> <block> <DOT>
23+
24+ # Block
25+
26+ <block> ::= <declarations> <compound_statement>
27+
28+ # Declaration
29+
30+ <declarations> ::= [ <VAR> { <variable_declaration> <SEMI> }+ ]
31+
32+ <variable_declaration> ::= <ID> { <COMMA> <ID> }* <COLON> <type_spec>
33+
34+ <type_spec> ::= <INTEGER_TYPE> | <REAL_TYPE>
35+
36+ # Statement
2137
2238<compound_statement> ::= <BEGIN> <statement_list> <END>
2339
@@ -31,36 +47,58 @@ A simple Pascal interpreter based on [Let's Build a Simple Interpreter](https://
3147
3248<empty> ::= ''
3349
50+ # Mathemathical Expression
51+
52+ <expression> ::= <term> { (<PLUS> | <MINUS>) <term> }*
53+
54+ <term> ::= <factor> { (<MUL> | <INTEGER_DIV> | <FLOAT_DIV>) <factor> }*
55+
3456<factor> ::= <PLUS> <factor>
3557 | <MINUS> <factor>
3658 | <INTEGER>
59+ | <REAL>
3760 | <LPAREN> <expression> <RPAREN>
3861 | <variable>
3962
40- <expression> ::= <term> { (<PLUS> | <MINUS>) <term> }*
41-
42- <term> ::= <factor> { (<MUL> | <DIV>) <factor> }*
63+ # Variables
4364
4465<variable> ::= <ID>
4566
4667<ID> ::= [a-zA-Z_][a-zA-Z0-9_]*
4768
69+ # Numerical Values
70+
4871<INTEGER> ::= <digit>+
72+ <REAL> ::= <digit>+ [ <DOT> <digit>+ ]
4973
5074<digit> ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
5175
76+ # Reserved words
77+
78+ <PROGRAM> ::= 'PROGRAM'
5279<BEGIN> ::= 'BEGIN'
5380<END> ::= 'END'
81+ <VAR> ::= 'VAR'
82+ <INTEGER_TYPE> ::= 'INTEGER'
83+ <REAL_TYPE> ::= 'REAL'
84+
85+ # Symbols
86+
5487<DOT> ::= '.'
5588<SEMI> ::= ';'
89+ <COMMA> ::= ','
90+ <COLON> ::= ':'
91+ <LPAREN> ::= '('
92+ <RPAREN> ::= ')'
93+
94+ # Operators
95+
5696<ASSIGN> ::= ':='
5797<PLUS> ::= '+'
5898<MINUS> ::= '-'
5999<MUL> ::= '*'
60- <DIV> ::= 'DIV'
61- <LPAREN> ::= '('
62- <RPAREN> ::= ')'
63-
100+ <FLOAT_DIV> ::= '/'
101+ <INTEGER_DIV> ::= 'DIV'
64102```
65103
66104## Diagram
You can’t perform that action at this time.
0 commit comments