Coder Social home page Coder Social logo

zmajeed / ebnfparser Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 117 KB

A Bison grammar and parser for the extended BNF (EBNF) syntax used to specify the GQL language in the ISO-39075:2024 standard

License: MIT License

CMake 9.27% Yacc 21.51% Lex 11.68% C 2.98% C++ 54.56%

ebnfparser's People

Contributors

zmajeed avatar

Watchers

 avatar

ebnfparser's Issues

Support unquoted string literals

Don't require doublequotes around string and character literals. This will allow the GQL grammar file to be processed as-is with rules like

<ampersand> ::=
    &
<binary digit> ::=
    0
  | 1

Allow rule definition operator on new line

The lexer recognizes a new rule when the target nonterminal and definition operator are on the same line like <GQL-program> ::=. This simplification is fine for the GQL grammar file but not correct in general.
Fix to allow rules like

<program activity>
  ::=
    <session activity>
  | <transaction activity>

Grammar railroad diagram

Using a script using Lua string patterns we can get an EBNF understood by (IPV6) https://www.bottlecaps.de/rr/ui or (IPV4) https://rr.red-dove.com/ui to generate a nice navigable railroad diagram see instructions bellow (attached the full EBNF)

//
// EBNF to be viewd at
//    (IPV6) https://www.bottlecaps.de/rr/ui
//    (IPV4) https://rr.red-dove.com/ui
//
// Copy and paste this at one of the urls shown above in the 'Edit Grammar' tab
// then click the 'View Diagram' tab.
//
//From: https://github.com/zmajeed/ebnfparser/blob/main/docs/gqlgrammar.quotedliterals.txt
/************************************************************************************************
This file is a "digital artifact" that contains the grammar specified by "ISO_IEC" 39075.

This grammar may be used by implementers of GQL-implementations when generating parsers for the
"GQL" language.
************************************************************************************************/

GQL_program ::=
    program_activity ( session_close_command )?
  | session_close_command
...

Script:

auto fname = "gqlgrammar.quotedliterals.txt";
auto txt = readfile(fname);

auto fixOpt = function(txt){return txt.gsub("%[ ([^%[%]]+) %]", "( %1 )?");}
auto fixGroup = function(txt){return txt.gsub("{ ([^{}]+) }", "( %1 )");}

//txt = txt.replace("> ::=", "> :");
txt = txt.gsub("<(%w[%w- ].-)>", function(m){ return m.gsub("[- ]", "_");});
auto txt2 = fixOpt(txt);
while(txt != txt2) {
	txt = txt2;
	txt2 = fixOpt(txt);
}

txt2 = fixGroup(txt);
while(txt != txt2) {
	txt = txt2;
	txt2 = fixGroup(txt);
}

txt = txt.replace("!!", "//");
txt = txt.replace("...", "+");
txt = txt.replace("\"\\\"\"", "'\"'");
txt = txt.gsub("(%w)/(%w)", "%1_%2");
//txt = txt.gsub("0[xob]", "\"%1\"");
txt = txt.gsub("(%u[%u_]+)(%s)", "\"%1\"%2");
txt = txt.gsub("(%u+%d+)(%s)", "\"%1\"%2"); //INT8, FLOAT32, ...
//txt = txt.replace("\n\n", "\n  ;\n\n");

print(txt);

gqlgrammar.quotedliterals.txt.ebnf.zip

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.