-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathParser.vy
More file actions
40 lines (29 loc) · 663 Bytes
/
Parser.vy
File metadata and controls
40 lines (29 loc) · 663 Bytes
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
%{
Require Import String.
Inductive ast :=
| OpExpr : string -> ast -> ast -> ast
| Num : nat -> ast.
(* We make a type synonym to differentiate
from nat extracted from other files. *)
Definition num : Type := nat % type.
%}
%token<num> NUM
(*
This represents all operators. Giving each
operator its own token probably would have
been cleaner, but I wanted to include
strings in the example.
*)
%token<string> OP
%token LPAREN RPAREN EOF
%type<ast> expr
%start<ast> top_expr
%%
top_expr:
| e=expr EOF
{ e }
expr:
| i=NUM
{ Num i }
| LPAREN op=OP e1=expr e2=expr RPAREN
{ OpExpr op e1 e2 }