BNF lite - C++ template library for lightweight parsers

BNF lite - C++ template library for lightweight parsers

Postby alexander_ss » 28 Feb 2017, 12:38

Once I had problem with configuration language develiping game.
there is solution now:
https://github.com/r35382/bnflite

[/spoiler]-----------
Concept
BNF Notation
BNF (Backus–Naur form) specificates rules of a context-free grammar. Each computer language should have a complete BNF syntactic specification. Formal BNF term is called "production rule". Each rule except "terminal" is a conjunction of a series of of more concrete rules or terminals:
production_rule ::= <rule_1>...<rule_n> | <rule_n_1>...<rule_m>;
For example:
<digit> ::= <0> | <1> | <2> | <3> | <4> | <5> | <6> | <7> | <8> | <9>
<number> ::= <digit> | <digit> <number>```
which means that the number is just a digit or another number with one more digit. Generally terminal is a symbol called "token". There are two kind of productions rules: Lexical production is called "lexem". We will call syntax production rule as just a "rule".

BNF Lite notation
All above can be presented in C++ friendly notation
Lexem Digit = Token("0") | "1" | "2" | "4" | "5" | "6" | "7" | "8" | "9"; //C++11: ="0"_T + "1" ...
LEXEM(Number) = Digit | Digit + Number;
These both expressions are executable due to this "bnflite.h" source code library which supports "Token", "Lexem" and "Rule" classes with overloaded "+" and "|" operators. More practical and faster way is to use simpler form:
Token Digit("01234567");
Lexem Number = Iterate(1, Digit);
Now e.g. Parser::Analyze(Number, "532") can be called with success.[/spoiler]
alexander_ss
 
Posts: 1
Joined: 28 Feb 2017, 12:16

Re: BNF lite - C++ template library for lightweight parsers

Postby Sauer2 » 28 Feb 2017, 19:37

Hm, cool.
So it's basically a lightweight, better readable version of Boost Spirit?
User avatar
Sauer2
 
Posts: 430
Joined: 19 Jan 2010, 14:02

Who is online

Users browsing this forum: No registered users and 1 guest