-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParser.y
72 lines (62 loc) · 1.21 KB
/
Parser.y
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
{
module Parser where
import Model
}
%name parseTokens
%tokentype { Token }
%token
"->" { TArrow }
"." { TDot}
"," { TComma}
go { TGo}
take { TTake}
mark { TMark}
nothing {TNothing}
turn { TTurn}
case { TCase}
of {TOf}
end {TEnd}
left {TLeft}
right {TRight}
front { TFront}
";" {TSemicolon}
empty {TEmpty }
lambda {TLambda }
debris {TDebris}
asteroid {TAsteroid }
boundary {TBoundary }
"_" {TUnderscore}
ident {TIdent $$}
%%
Program : Rulel { Program $1}
Rulel : Rule {[$1]}
| Rulel Rule {$2:$1}
Rule : ident "->" Cmds "." {Rule $1 $3}
Cmds : Cmdsl {Cmds $1}
Cmdsl : {- empty -} { []}
| Cmd { [$1]}
| Cmdsl "," Cmd { $3:$1}
Cmd : go {Go}
| take {Take}
| mark {Mark}
| nothing {Nothin}
| turn Dir {Turn $2}
| case Dir of Alts end {Case $2 $4}
| ident {Ident $1}
Dir : left {Lef}
| right {Righ}
| front {Fron}
Alts : Altsl {Alts $1}
Altsl : {- empty -} {[]}
| Alt { [$1]}
| Altsl ";" Alt { $3:$1}
Alt : Contents "->" Cmds {Alt $1 $3}
Contents : empty {Empty}
| lambda {Lambda}
| debris {Debris}
| asteroid {Asteroid}
| boundary {Boundary}
| "_" {Underscore}
{
happyError _ = error "parse error"
}