-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.mly
125 lines (95 loc) · 3.31 KB
/
parser.mly
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
%{
open Ast
%}
%token <int> NUMBER
%token <string> STRING
%token <string> ATOM
%token <string> VARIABLE
%token <string> ACTION
%token DO
%token LARROW
%token LPAR RPAR
%token LBRACK RBRACK
%token PLUS MINUS MUL DIV
%token AMPERSAND
%token PIPE
%token EMARK EMARK2 QMARK QMARK2
%token COMMA PERIOD SEMICOLON COLON
%token SQUOTE DQUOTE
%token EOF
%type <Ast.toplevel_entry list> parse
%start parse
%%
parse: toplevel { $1 }
toplevel:
| toplevel_entry { [$1] }
| toplevel_entry toplevel { $1::$2 }
toplevel_entry:
| formula annotations PERIOD { Belief ($1, $2) }
| clause { Clause $1 }
clause:
| triggering_event annotations PERIOD { { triggering_event = $1;
annotations = $2;
context = TAtom "true";
body = ActionNop } }
| triggering_event annotations plan_context LARROW plan_body PERIOD { { triggering_event = $1;
annotations = $2;
context = $3;
body = $5 } }
triggering_event: event_type goal_type formula { { event_type = $1;
goal_type = $2;
formula = $3 } }
formula:
| ATOM { ($1, []) }
| ATOM LPAR term_seq RPAR { ($1, $3) }
event_type:
| PLUS { Add }
| MINUS { Del }
goal_type:
| EMARK { Achievement }
| QMARK { Test }
plan_context:
| { TAtom "true" }
| COLON logic_exp { $2 }
plan_body:
| plan_action { Action $1 }
| plan_action SEMICOLON plan_body { ActionSeq ($1, $3) }
| DO plan_action SEMICOLON plan_body { ActionDo ($2, $4) }
plan_action:
| plan_action_prefix formula { ($1, $2) }
| ACTION LPAR term_seq RPAR { (ActionCall, ($1, $3)) }
plan_action_prefix:
| EMARK { Call }
| EMARK2 { AsyncCall }
| QMARK { MVarTake }
| QMARK2 { MVarRead }
| PLUS { MVarPut }
term:
NUMBER { TNumber $1 }
| STRING { TString $1 }
| ATOM { TAtom $1 }
| VARIABLE { TVariable $1 }
| ATOM LPAR term_seq RPAR { TStructure ($1, $3) }
| LBRACK list_literal_elements RBRACK { $2 }
| term PLUS term { TBinOp ("+", $1, $3) }
| term MINUS term { TBinOp ("-", $1, $3) }
| term MUL term { TBinOp ("*", $1, $3) }
| term DIV term { TBinOp ("/", $1, $3) }
term_seq:
term { [$1] }
| term COMMA term_seq { $1::$3 }
list_literal_elements: { nil }
| term { TStructure ("$cons", [$1; nil]) }
| term COMMA list_literal_elements { TStructure ("$cons", [$1; $3]) }
| term PIPE term { TStructure ("$cons", [$1; $3]) }
logic_exp:
| term { $1 }
| term AMPERSAND logic_exp { TStructure ("$and", [$1; $3]) }
| term PIPE logic_exp { TStructure ("$or", [$1; $3]) }
formula_seq:
| { [] }
| formula { [$1] }
| formula COMMA formula_seq { $1::$3 }
annotations:
| { [] }
| LBRACK formula_seq RBRACK { $2 }