%source { #include #include #include } %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; }