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
|
%source {
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef DO_PARSE_DEBUG
static const char *dbg_str[] = { "Evaluating rule", "Matched rule", "Abandoning rule" };
#define PCC_DEBUG(auxil, event, rule, level, pos, buffer, length) \
fprintf(stderr, "%*s%s %s @%zu [%.*s]\n", (int)((level) * 2), "", dbg_str[event], rule, pos, (int)(length), buffer)
#endif
#define PCC_GETCHAR(auxil) fgetc(auxil)
}
%common {
#include "ast.h"
}
%value "AstNode"
%auxil "FILE *"
expr <-
l:list { $$ = l; }
/ n:number { $$ = n; }
/ i:ident { $$ = i; }
/ t:string { $$ = t; }
/ a:array { $$ = a; }
list <- { $$ = astnode_new_list(); }
'('
( e:expr { astnode_append(&$$, e); }
)*
')' _
array <- { $$ = astnode_new_arr(); }
'['
( e:expr { astnode_append(&$$, e); }
)*
']' _
number <- < [0-9]+ > (! ident_char) _ { $$ = astnode_new_num(atoi($1)); }
ident <- < ident_char+ > _ { $$ = astnode_new_ident($1); }
string <- '"' < [^"]* > '"' _ { $$ = astnode_new_string($1); }
ident_char <- [-_a-zA-Z'+*/\\%=0-9<>]
_ <- [ \t\n]*
|