-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparser.rb.y
More file actions
52 lines (39 loc) · 1.49 KB
/
parser.rb.y
File metadata and controls
52 lines (39 loc) · 1.49 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
45
46
47
48
49
50
51
class Calcp
prechigh
left '->'
right '^'
left '*' '/'
left '+' '-'
preclow
rule
target: Expr
| /* none */ { result = 0 }
| LET IDENT EQ Expr { result = Decl.new(val[1],val[3])}
| FIX IDENT EQ FUN IDENT ARROW Expr { result = Fixdecl.new(val[1],val[4],val[6])}
Expr: IfExpr
| RelExpr
| LetExpr
| FunExpr
| FixExpr
FixExpr: FIX IDENT EQ FUN IDENT ARROW Expr IN Expr { result = Fixexp.new(val[1],val[4],val[6],val[8])}
LetExpr: LET IDENT EQ Expr IN Expr { result = Letexp.new(val[1],val[3],val[5])}
FunExpr: FUN IDENT ARROW Expr { result = Funexp.new(val[1],val[3]) }
RelExpr: ASExpr LT ASExpr { result = Binexp.new('<',val[0],val[2])}
| ASExpr GT ASExpr { result = Binexp.new('>',val[0],val[2])}
| ASExpr
ASExpr: ASExpr PLUS MDExpr { result = Binexp.new('+',val[0],val[2])}
| ASExpr MINUS MDExpr { result = Binexp.new('-',val[0],val[2])}
| MDExpr
MDExpr: MDExpr MULT AppExpr { result = Binexp.new('*',val[0],val[2])}
| MDExpr DIV AppExpr { result = Binexp.new('/',val[0],val[2])}
| AppExpr
AppExpr: AppExpr AExpr { result = Appexp.new(val[0],val[1])}
| AExpr
IfExpr: IF Expr THEN Expr ELSE Expr { result = Ifexp.new(val[1],val[3],val[5])}
AExpr: LPAREN Expr RPAREN { result = val[1] }
| NUMBER {result = IntV.new(val[0])}
| boolean
| IDENT
boolean: TRUE { result = BoolV.new("true") }
| FALSE { result = BoolV.new("false") }
end