From 40d7c402f7ea0269c426b58e40c790c9f771c0d4 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sun, 11 May 2014 14:23:10 +1000 Subject: [PATCH] pargergen: make use of --tag for calc grammar Rather than placing the 'calc' grammar in a separate file, add 'calc:' tags to the sections and use --tag option to extract the grammar directly from the pargergen.mdc file. Signed-off-by: NeilBrown --- csrc/parsergen.mdc | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/csrc/parsergen.mdc b/csrc/parsergen.mdc index a7d107c..9def082 100644 --- a/csrc/parsergen.mdc +++ b/csrc/parsergen.mdc @@ -17,7 +17,10 @@ There are several distinct sections. 5. `parser_run` is a library function intended to be linked together with the generated parser tables to complete the implementation of a parser. -6. `calc.cgm` is a test grammar for a simple calculator. +6. Finally `calc` is a test grammar for a simple calculator. The + `parsergen` program built from the C code in this file can extract + that grammar directly from this file and process it. + ###### File: parsergen.c #include @@ -42,12 +45,10 @@ There are several distinct sections. ## parser includes ## parser functions ## parser_run -###### File: calc.cgm - ## demo grammar ###### File: parsergen.mk CFLAGS += -Wall -g all :: parsergen calc - parsergen.c parsergen.mk calc.cgm libparser.c parser.h : parsergen.mdc + parsergen.c parsergen.mk libparser.c parser.h : parsergen.mdc ./md2c parsergen.mdc ## Reading the grammar @@ -2733,15 +2734,12 @@ better approach, but as the grammar file must have 3 components I need something like this. ###### File: parsergen.mk - calc.c : parsergen calc.cgm - ./parsergen -o calc calc.cgm + calc.c calc.h : parsergen parsergen.mdc + ./parsergen --tag calc -o calc parsergen.mdc calc : calc.o libparser.o libscanner.o libmdcode.o libnumber.o $(CC) $(CFLAGS) -o calc calc.o libparser.o libscanner.o libmdcode.o libnumber.o -licuuc -lgmp -###### demo grammar - - # header - ~~~~~ +# calc: header #include "number.h" // what do we use for a demo-grammar? A calculator of course. @@ -2751,9 +2749,7 @@ something like this. int err; }; - ~~~~~ - # code - ~~~~~ +# calc: code #include #include @@ -2794,9 +2790,7 @@ something like this. exit(0); } - ~~~~~ - # grammar - ~~~~~ +# calc: grammar Session -> Session Line | Line -- 2.43.0