Coder Social home page Coder Social logo

onlyuser / ebnf2yacc Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 0.0 207 KB

ebnf2yacc is a kleene closure preprocessor for yacc

Home Page: http://onlyuser.github.io/

Shell 2.54% C++ 74.82% C 0.27% Makefile 7.29% Lex 4.55% Yacc 10.53%
parser-framework yacc lex flex bison visitor-pattern kleene-closure-preprocessor preprocessor parser ebnf

ebnf2yacc's Introduction

Build Status

ebnf2yacc

Copyright (C) 2011-2017 mailto:[email protected]

About

ebnf2yacc is a kleene closure preprocessor for yacc. It takes an ebnf specification as input and generates a yacc grammar.

A Motivating Example

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; };

%%

Usage

cat input.ebnf | ./app/bin/ebnf2yacc -y > output.y

Requirements

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

Make Targets

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

References

"Kleene star"
http://en.wikipedia.org/wiki/Kleene_star

Keywords

Lex, Yacc, Flex, Bison, Parser, EBNF, Kleene Closure, Kleene Star

ebnf2yacc's People

Contributors

onlyuser avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.