summaryrefslogtreecommitdiff
path: root/grammar.peg
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-07-10 12:25:53 +0100
committerubq323 <ubq323@ubq323.website>2023-07-10 12:25:53 +0100
commiteeea75fa7820f1a7ee4958b65667d0078e01f3bd (patch)
tree75850c0a3c1cbfb8b74740b208bfdaf9e8297009 /grammar.peg
initial
Diffstat (limited to 'grammar.peg')
-rw-r--r--grammar.peg27
1 files changed, 27 insertions, 0 deletions
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 <stdio.h>
+#include <stdlib.h>
+#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;
+}