From eeea75fa7820f1a7ee4958b65667d0078e01f3bd Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 10 Jul 2023 12:25:53 +0100 Subject: initial --- grammar.peg | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 grammar.peg (limited to 'grammar.peg') diff --git a/grammar.peg b/grammar.peg new file mode 100644 index 0000000..fc7db48 --- /dev/null +++ b/grammar.peg @@ -0,0 +1,27 @@ +%{ +#include +#include +#include "ast.h" + +AstVec numbers; +%} + + +Numberlist = ( n:NUMBER { astvec_append(&numbers, astnode_new_num(n)); } + )+ + + +NUMBER = < [0-9]+ > [ \t]* { $$ = atoi(yytext); } + +%% + +int main() { + printf("len %ld cap %ld vals %p\n", numbers.len, numbers.cap, numbers.vals); + while (yyparse()) ; + printf("len %ld cap %ld vals %p\n", numbers.len, numbers.cap, numbers.vals); + for (int i = 0; i < numbers.len; i++) { + printf("[%d] ",numbers.vals[i].as.num); + } + + return 0; +} -- cgit v1.2.3