diff options
Diffstat (limited to 'g.peg')
-rw-r--r-- | g.peg | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -0,0 +1,41 @@ +%source { +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +/* +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) + + +*/ +} + + + +%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\n]* + + |