ebnf

Grako - How to do error handling?

梦想的初衷 提交于 2019-12-12 04:17:28
问题 How do I do error handling with Grako? EBNF (MyGrammar.ebnf): pattern = { tag | function }* ; tag = tag:( "%" name:id "%" ); function = function:("$" name:id "()" ); id = ?/([^\\%$,()=])+/? ; I'm generating the parser with python -m grako --whitespace '' MyGrammar.ebnf > my_parser.py Parsing an empty string and a "bad" string (that could not be matched by the grammar) both results to an empty AST Closure. parser = MyGrammarParser() ast = parser.parse(u"%test%", rule_name='pattern') #ast

How does a parser for the infix notation detect the missing multiplication sign?

本小妞迷上赌 提交于 2019-12-11 20:42:19
问题 I am writing a parser that parses mathematical expressions based on a syntax diagram very similar to this one. I have not found a way to handle a missing multiplication sign (for example in 3(x+y) ). Where in the syntax diagram do I have to handle this? 回答1: You'd make the * optional in the definition of term . ASCII diagram: o-->-->--[factor]->-->--o / \ \ / ---<--[*]--<--- \ / --<-- 来源: https://stackoverflow.com/questions/31629984/how-does-a-parser-for-the-infix-notation-detect-the-missing

How to use infragistics syntax parsing engine?

心已入冬 提交于 2019-12-11 11:57:53
问题 I want to make use of infragistics syntax parsing engine to do something like this: User defines grammar for a language in an EBNF format. The grammar defined above is used to verify whether a user input in a textbox is valid (i.e. matches or could match the above grammar) or not. I have read all the documentation they have and I cannot see what a good first step would be. Any help will be appreciated. 回答1: I work on the parsing engine for Infragistics and this sounds like a perfect way to

Extended Backus–Naur Form order of operations

笑着哭i 提交于 2019-12-10 15:44:03
问题 I am creating a formal spec for a very simple rule language, very simple. I want to use EBNF as this is a standard but I can't figure out how to specify order of operations. Here is the specification so far. rule = statement, { (‘AND’|’OR’), statement}; variable = ‘$’,alphabetic character, {alphabetic character | digit}; statement = variable, [ ‘count’,[white space ],’>’,[white space],number ]; alphabetic character = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M"

Generate BNF diagrams from an antlr grammar?

家住魔仙堡 提交于 2019-12-10 10:41:34
问题 I may well be asking something not achievable here.. Maybe someone can point out either (a) What would be some steps (/tools?) to at least partially achieve creation of bnf diagrams from a (rather complex) antlr grammar (b) why (if it were the case) this simply can not be achieved. E.g. maybe since antlr is extended BNF and its recursive structure differs from bnf requirements.. Along those lines. 回答1: ANTLRWorks 1 works for generating diagrams, one at a time, for rule. for v4, ANTLRWorks 2

Implementing parser for markdown-like language

我的梦境 提交于 2019-12-09 04:45:03
问题 I have markup language which is similar to markdown and the one used by SO. Legacy parser was based on regexes and was complete nightmare to maintain, so I've come up with my own solution based on EBNF grammar and implemented via mxTextTools/SimpleParse. However, there are issues with some tokens which may include each other, and I don't see a 'right' way to do it. Here is part of my grammar: newline := "\r\n"/"\n"/"\r" indent := ("\r\n"/"\n"/"\r"), [ \t] number := [0-9]+ whitespace := [ \t]+

bnf/ebnf for xml schema

≯℡__Kan透↙ 提交于 2019-12-07 22:54:35
问题 I'm looking for a BNF/EBNF of XML Schema. I just found the one for XML (http://www.w3.org/TR/REC-xml or extracted at http://www.jelks.nu/XML/xmlebnf.html). Well it's a starting point, but I'm curious that I couldn't find a more specific one for XML Schema. 回答1: I guess because nobody finds that useful, and it would be too complex. If somebody want to define an XML language, such as XML Schema, they would probably use XML primitives like elements or attributes (using XML Schema, Relax NG, DTD,

Generate BNF diagrams from an antlr grammar?

拈花ヽ惹草 提交于 2019-12-06 11:54:31
I may well be asking something not achievable here.. Maybe someone can point out either (a) What would be some steps (/tools?) to at least partially achieve creation of bnf diagrams from a (rather complex) antlr grammar (b) why (if it were the case) this simply can not be achieved. E.g. maybe since antlr is extended BNF and its recursive structure differs from bnf requirements.. Along those lines. ANTLRWorks 1 works for generating diagrams, one at a time, for rule. for v4, ANTLRWorks 2 also generates them though I'm not sure it can save them to disk. Ter If it is an ANTLR 3 grammar, you could

bnf/ebnf for xml schema

ε祈祈猫儿з 提交于 2019-12-06 09:38:34
I'm looking for a BNF/EBNF of XML Schema. I just found the one for XML ( http://www.w3.org/TR/REC-xml or extracted at http://www.jelks.nu/XML/xmlebnf.html ). Well it's a starting point, but I'm curious that I couldn't find a more specific one for XML Schema. I guess because nobody finds that useful, and it would be too complex. If somebody want to define an XML language, such as XML Schema, they would probably use XML primitives like elements or attributes (using XML Schema, Relax NG, DTD, etc.), not characters. One of the reasons XML was invented is to have a meta language for creating other

Is ANTLR an appropriate tool to serialize/deserialize a binary data format?

雨燕双飞 提交于 2019-12-05 01:37:41
I need to read and write octet streams to send over various networks to communicate with smart electric meters. There is an ANSI standard, ANSI C12.19, that describes the binary data format. While the data format is not overly complex the standard is very large (500+ pages) in that it describes many distinct types. The standard is fully described by an EBNF grammar. I am considering utilizing ANTLR to read the EBNF grammar or a modified version of it and create C# classes that can read and write the octet stream. Is this a good use of ANTLR? If so, what do I need to do to be able to utilize