blob: bbb5baac606f63e864f0313d50ded19f666987bd (
plain)
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
|
%source {
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
}
%common {
#include "ast.h"
}
%value "AstNode"
numberlist <- { $$ = astnode_new_list(); }
( n:number _ { astnode_append(&$$, n); } ) +
EOL
number <- < [0-9]+ > { $$ = astnode_new_num(atoi($1)); }
EOL <- '\n' / '\r\n' / '\r'
_ <- [ \t]*
%%
int main() {
pcc_context_t *ctx = pcc_create(NULL);
AstNode ret;
memset(&ret, 0, sizeof ret);
while (pcc_parse(ctx, &ret)) ;
AstVec *v = &ret.as.list;
printf("%d: %ld %ld\n",ret.ty, v->len,v->cap);
for (int i = 0; i < v->len; i++) {
printf(" %d:[%d]\n", v->vals[i].ty, v->vals[i].as.num);
}
pcc_destroy(ctx);
return 0;
}
|