%source { #include #include #include } %common { #include "ast.h" } %value "AstNode" expr <- l:list { $$ = l; } / n:number { $$ = n; } / s:symbol { $$ = s; } list <- { $$ = astnode_new_list(); } '(' ( e:expr { astnode_append(&$$, e); } )* ')' _ number <- < [0-9]+ > _ (! ident_char) { $$ = astnode_new_num(atoi($1)); } symbol <- < ident_char+ > _ { $$ = astnode_new_symbol(strdup($1)); } ident_char <- [-_a-zA-Z'+*0-9] _ <- [ \t]* %% int main() { pcc_context_t *ctx = pcc_create(NULL); AstNode ret; memset(&ret, 0, sizeof ret); pcc_parse(ctx, &ret); astnode_disp(&ret); putchar('\n'); pcc_destroy(ctx); return 0; }