-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathparser.mly
38 lines (32 loc) · 864 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
%{
(* Make available names in the Ast module *)
open Ast
(* Report a syntax error with the location of its orgin *)
let syntax_error () =
let start_pos = Parsing.rhs_start_pos 1 in
let end_pos = Parsing.rhs_end_pos 1 in
raise (Error.SyntaxError {
sl = start_pos.pos_lnum;
sc = start_pos.pos_cnum - start_pos.pos_bol;
el = end_pos.pos_lnum;
ec = end_pos.pos_cnum - end_pos.pos_bol;
})
%}
/* Tokens */
%token EOF
%token UNIT
%token <int> NUMBER
%token <string> ID
%token // TODO: Your tokens here
// TODO: Your associativity rules here
// ...
%start main
%type <Ast.prog> main
%%
main:
| prog EOF { $1 }
| error EOF { syntax_error () }
prog:
| { [] }
/* TODO: Your rules here E.g.
| <production> { <action> } */