From 3a86e3a21394a072b9b59c68861325297f5e066d Mon Sep 17 00:00:00 2001 From: ubq323 Date: Tue, 1 Aug 2023 22:42:24 +0100 Subject: tersify --- .gitignore | 6 +++--- Makefile | 14 +++++++------- g.peg | 41 +++++++++++++++++++++++++++++++++++++++++ grammar.peg | 41 ----------------------------------------- read.h | 2 +- 5 files changed, 52 insertions(+), 52 deletions(-) create mode 100644 g.peg delete mode 100644 grammar.peg diff --git a/.gitignore b/.gitignore index 08476bc..276812f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -parser.c -parser.h -badthing +prs.c +prs.h +bþ vm diff --git a/Makefile b/Makefile index 0160897..696587b 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,14 @@ -CS=ast.c com.c dis.c parser.c read.c val.c vm.c -HS=ast.h dis.h parser.h read.h val.h vm.h +CS=ast.c com.c dis.c prs.c read.c val.c vm.c +HS=ast.h dis.h prs.h read.h val.h vm.h CFLAGS=-O3 -Wall -Wpedantic -Werror=implicit-function-declaration -badthing: $(CS) $(HS) - $(CC) $(CFLAGS) -o badthing $(CS) +bþ: $(CS) $(HS) + $(CC) $(CFLAGS) -o bþ $(CS) -parser.c: grammar.peg - packcc -o parser grammar.peg +prs.c: g.peg + packcc -o prs g.peg clean: - rm badthing parser.c + rm bþ prs.c prs.h .PHONY: clean diff --git a/g.peg b/g.peg new file mode 100644 index 0000000..3c75ab9 --- /dev/null +++ b/g.peg @@ -0,0 +1,41 @@ +%source { +#include +#include +#include + +/* +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]* + + diff --git a/grammar.peg b/grammar.peg deleted file mode 100644 index 3c75ab9..0000000 --- a/grammar.peg +++ /dev/null @@ -1,41 +0,0 @@ -%source { -#include -#include -#include - -/* -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]* - - diff --git a/read.h b/read.h index 80f0261..b47edb0 100644 --- a/read.h +++ b/read.h @@ -1,7 +1,7 @@ #ifndef _read_h #define _read_h -#include "parser.h" +#include "prs.h" #include "ast.h" AstNode read(); -- cgit v1.2.3