zmajeed / ebnfparser Goto Github PK
View Code? Open in Web Editor NEWA 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
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
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
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>
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);
The rule for repetition on groups works for a concatenation group but not for a group of alternatives
For example, this EBNF generates wrong BNF
<separator> ::=
{ <comment>
| <whitespace> }...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.