-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrammar.peg
More file actions
44 lines (35 loc) · 1.14 KB
/
Copy pathgrammar.peg
File metadata and controls
44 lines (35 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
stmt <- kdefs* #eof
kdefs <- 'def' defs ';' | expressions ';'
defs <- prototype expressions
prototype <-
('unary' . decimal_const?
| 'binary' . decimal_const?
| identifier)
prototype_args
prototype_args <- '(' arg* ')' ':' type
arg <- identifier ':' type
type <- 'int' | 'double' | 'void'
expressions <- for_expr
| if_expr
| while_expr
| expression (':' expression)*
for_expr <- 'for' expression ',' expression ',' expression 'in' expressions
if_expr <- 'if' expression 'then' expressions ('else' expressions)?
while_expr <- 'while' expression 'do' expressions
expression <- unary (binop (unary | expression))*
unary <- unop unary | postfix
postfix <- primary call_expr?
call_expr <- '(' (expression (',' expression)*)? ')'
primary <- identifier
| literal
| '(' expressions ')'
identifier <- [A-Za-z][A-Za-z0-9]*
dot <- '.' !'.'
decimal_const <- [0-9]+
double_const <- (decimal_const dot [0-9]* | dot [0-9]+)
void_literal <- "()"
boolean_literal <- ("true" | "false") ![A-Za-z]
literal <- decimal_const
| double_const
| void_literal
| boolean_literal