-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGRAMMAR
More file actions
23 lines (18 loc) · 1.04 KB
/
GRAMMAR
File metadata and controls
23 lines (18 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
compilation-unit ::= ( global-variable | function-definition | function-declaration )*
global-variable ::= type IDENTIFIER ( '=' expression )?
function-definition ::= function-prototype block
function-declaration ::= function-prototype ';'
function-prototype ::= type IDENTIFIER '(' ( type IDENTIFIER ( ',' type IDENTIFIER)* )? ')'
block ::= '{' local-variable* statement* '}'
local-variable ::= type IDENTIFIER ( '=' expression ) ( ',' IDENTIFIER ('=' expression )? )* ';'
statement ::= expression ';'
| block
| IF '(' expression ')' statement ( ELSE statement )?
| FOR '(' expression ';' expression ';' expression ')' statement
| WHILE '(' expression ')' statement
| DO statement WHILE '(' expression ')' ';'
//TODO: boolean logic, relations, bitwise logic
expression ::= expression '*' factor | expression '/' factor | factor
factor ::= factor '+' addend | factor '-' addend | addend | '-' addend
addend ::= '(' expression ') | IDENTIFIER | FLOAT | INT
type ::= 'int' | 'float' | 'ptr'