Copyright (C) 2011-2017 mailto:[email protected]
ebnf2yacc is a kleene closure preprocessor for yacc. It takes an ebnf specification as input and generates a yacc grammar.
input:
%% program: (expr)+ '\n' { for(auto p = $1->begin(); p != $1->end(); p++) { printf("%d\n", std::get<0>(*p)); } } ; expr: INTEGER { $$ = $1; }; %%
output:
%{ #include <vector> #include <tuple> typedef std::tuple<int> program_term_0_type_t; typedef std::vector<program_term_0_type_t> program_recursive_0_type_t; %} %union { program_term_0_type_t* program_term_0_type; program_recursive_0_type_t* program_recursive_0_type; } %type program_term_0 %type program_recursive_0 %% program: program_recursive_0 '\n' { { for(auto p = $1->begin(); p != $1->end(); p++) { printf("%d\n", std::get<0>(*p)); } } delete $1;}; program_recursive_0: program_term_0 { $$ = new program_recursive_0_type_t; $$->push_back(*$1); delete $1; } | program_recursive_0 program_term_0 { $1->push_back(*$2); delete $2; $$ = $1; }; program_term_0: expr { $$ = program_term_0_type_t($1); {} }; expr: INTEGER { $$ = $1; }; %%
cat input.ebnf | ./app/bin/ebnf2yacc -y > output.y
Unix tools and 3rd party components (accessible from $PATH):
gcc flex bison valgrind cppcheck doxygen graphviz ticpp
Environment variables:
- $INCLUDE_PATH_EXTERN -- where "ticpp/ticpp.h" resides
- $LIB_PATH_EXTERN -- where "libticppd.a" resides
target | action |
---|---|
all | make binaries |
test | all + run tests |
pure | test + use valgrind to check for memory leaks |
dot | test + generate .png graph for tests |
lint | use cppcheck to perform static analysis on .cpp files |
doc | use doxygen to generate documentation |
xml | test + generate .xml for tests |
import | test + use ticpp to serialize-to/deserialize-from xml |
clean | remove all intermediate files |
- "Kleene star"
- http://en.wikipedia.org/wiki/Kleene_star
Lex, Yacc, Flex, Bison, Parser, EBNF, Kleene Closure, Kleene Star