-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpr.peg
80 lines (58 loc) · 2.25 KB
/
expr.peg
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# A simple languaAge for experimenting with ASTs in Rust
#
# Usage:
# $ make clean && make && ./check_parser.sh to verify all files in the examples folder
#
# $ make clean && make && ./check_parser.sh <file-name> to check a paritcular file.
#
CompilationUnit <- Whitespace Expr* Eof
Expr <- AssignExpr
AssignExpr <- LogicalOrExpr (ASSIGN_op LogicalOrExpr)*
LogicalOrExpr <- LogicalAndExpr (LOGICALOR_op LogicalAndExpr)*
LogicalAndExpr <- RelationalExpr (LOGICALAND_op RelationalExpr)*
RelationalExpr <- BitExpr (RELATIONAL_op BitExpr)*
BitExpr <- BitShiftExpr (BIT_op BitShiftExpr)*
BitShiftExpr <- AdditiveExpr (BITSHIFT_op AdditiveExpr)*
AdditiveExpr <- MultiplicativeExpr (ADDITIVE_op MultiplicativeExpr)*
MultiplicativeExpr <- UnaryExpr (MULTIPLICATIVE_op MultiplicativeExpr)*
UnaryExpr <- UNARYPLUS_op UnaryExpr
/ UNARYMINUS_opUnaryExpr
/ BITWISENOT_op UnaryExpr
/ LOGICALNOT_op UnaryExpr
/ PREFIXINC_op UnaryExpr
/ PREFIXDEC_op UnaryExpr
/ POSTFIXINC_op UnaryExpr
/ POSTFIXDEC_op UnaryExpr
/ LPAREN Expr RPAREN
/ PrintExpr
/ Identifier
/ IntegerLiteral
/ BoolLiteral
PrintExpr <- PRINT_keyword LPAREN Expr RPAREN
Identifier <- [a-zA-Z_][a-zA-Z_0-9]* Whitespace
IntegerLiteral <- [0-9]+ Whitespace
BoolLiteral <- FALSE_const / TRUE_const
FALSE_const <- 'false' Whitespace
TRUE_const <- 'true' Whitespace
ASSIGN_op <- ('=' / '+=' / '-=' / '*=' / '/=' / '%=' / '&=' / '|=' / '^=' / '<<=' / '>>=') Whitespace
LOGICALOR_op <- '||' Whitespace
LOGICALAND_op <- '&&' Whitespace
RELATIONAL_op <- ('<=' / '<' / '>=' / '>' / '==' / '!=') Whitespace
BIT_op <- ('&' / '|' / '^') Whitespace
BITSHIFT_op <- ('<<' / '>>') Whitespace
ADDITIVE_op <- ('+' / '-') Whitespace
MULTIPLICATIVE_op <- ('*' / '/' / '%') Whitespace
BITWISENOT_op <- '~' Whitespace
LOGICALNOT_op <- '!' Whitespace
PREFIXINC_op <- '++' Whitespace
PREFIXDEC_op <- '--' Whitespace
POSTFIXINC_op <- '++' Whitespace
POSTFIXDEC_op <- '--' Whitespace
UNARYPLUS_op <- '+' Whitespace
UNARYMINUS_opUnaryExpr <- '-' Whitespace
PRINT_keyword <- 'print' Whitespace
LPAREN <- '(' Whitespace
RPAREN <- ')' Whitespace
comment <- '//' ([^\n])*
Whitespace <- ([ \t\n] / comment)*
Eof <- !.