-
Notifications
You must be signed in to change notification settings - Fork 1
/
parser.mly
38 lines (29 loc) · 947 Bytes
/
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
%{ open Main %}
%token <string> LWORD
%token <string> UWORD
%token COMMA CDASH QDASH LPAREN RPAREN DOT SHOW CLEAR
%start main
%type <Main.command> main
%%
main:
| rule DOT { $1 }
| inquery DOT { $1 }
| CLEAR { ClearComm }
| SHOW { ShowComm }
rule:
| term { Rule($1, []) }
| term CDASH term_list { Rule($1, $3) }
inquery:
| QDASH term { Inquery $2 }
term:
| lword { ConstTerm $1 }
| uword { VarTerm $1 }
| lword LPAREN RPAREN { ComplexTerm($1, []) }
| lword LPAREN term_list RPAREN { ComplexTerm($1, $3) }
term_list:
| term { [$1] }
| term COMMA term_list { $1::$3 }
lword:
| LWORD { Const $1 }
uword:
| UWORD { Var $1 }