grammar

Antlr Error Strategy to skip tokens until rule matches again

大憨熊 提交于 2019-12-07 07:01:23
问题 I tried this solution but it didn't seem to work for me Here's an excerpt from my grammer: module : BEGIN MODULE IDENT STRING module_element* END MODULE ; module_element : element_1 | element_2 | element_3 | ... ; There is a bigger tree below each element. Now when a RecognitionException occurs I want to consume tokens until either the next module_element matches or the parent END MODULE matches. Any hints on how to do this inside a class inheriting from DefaultErrorStrategy? edit: Here is a

how can i prove that this grammar is ambiguous?

让人想犯罪 __ 提交于 2019-12-07 06:04:35
问题 S -> bA|aB A -> a|aS|bAA B -> b|bS|aBB Any easy method other than trying to find a string that would generate two parse trees ? Can someone please give me a string that can prove this. 回答1: There is no easy method for proving a context-free grammar ambiguous -- in fact, the question is undecidable, by reduction to the Post correspondence problem. 回答2: There is a string though: bbaaba S -> bA -> bbAA -> bbaA -> bbaaS -> bbaabA -> bbaaba S -> bA -> bbAA -> bbaSA -> bbaaBA -> bbaabA -> bbaaba 来源

What does ^ and ! stand for in ANTLR grammar

时光怂恿深爱的人放手 提交于 2019-12-07 05:04:31
问题 I was having difficulty figuring out what does ^ and ! stand for in ANTLR grammar terminology. 回答1: Have a look at the ANTLR Cheat Sheet: ! don't include in AST ^ make AST root node And ^ can also be used in rewrite rules: ... -> ^( ... ) . For example, the following two parser rules are equivalent: expression : A '+'^ A ';'! ; and: expression : A '+' A ';' -> ^('+' A A) ; Both create the following AST: + / \ A A In other words: the + is made as root, the two A 's its children, and the ; is

What is the name of the language used for Cloud Firestore security rules?

余生颓废 提交于 2019-12-07 04:40:54
问题 I would like to know the name of the syntax used for the Cloud Firestore security rules as described at https://firebase.google.com/docs/firestore/security/get-started?authuser=0. I would like to find syntax highlighter for that syntax and maybe parsers for it. 回答1: Firebase Security Rules is a custom DSL. Condition expressions are JS like, and should work with one of those. The path matching framework is less common, but we're working on providing the grammar + additional tooling (syntax

“FOLLOW_set_in_”… is undefined in generated parser

北慕城南 提交于 2019-12-07 01:40:22
问题 I have written a grammar for vaguely Java-like DSL. While there are still some issues with it (it doesn't recognize all the inputs as I would want it to), what concerns me most is that the generated C code is not compilable. I use AntlrWorks 1.5 with Antlr 3.5 (Antlr 4 apparently does not support C target). The problem is with expression rules. I have rules prio14Expression to prio0Expression which handle operator precedence. To problem is at priority 2, which evaluates prefix and postfix

Convert regular expression to CFG

被刻印的时光 ゝ 提交于 2019-12-07 01:33:10
问题 How can I convert some regular language to its equivalent Context Free Grammar? Is it necessary to construct the DFA corresponding to that regular expression or is there some rule for such a conversion? For example, consider the following regular expression 01+10(11) * How can I describe the grammar corresponding to the above RE? 回答1: Change A+B to grammar G -> A G -> B Change A* to G -> (empty) G -> A G Change AB to G -> AB and proceed recursively on A and B. Base cases are empty language

LL(1) cannot be ambiguous

岁酱吖の 提交于 2019-12-06 20:58:10
问题 How can it be shown that no LL(1) grammar can be ambiguous? I know what is ambiguous grammar but could not prove the above theorem/lemma. 回答1: I think it's nearly a direct result of the definition of LL(1). Try proof by contradiction; assume that you have an LL(1) grammar that is ambiguous and look for something you can show to be true and not true. As a starting point "what do you always know as you process input?" As this seems like a homework problem and I actually haven't finished the

Shift reduce conflict

元气小坏坏 提交于 2019-12-06 20:02:57
问题 I'm having a problem understanding the shift/reduce confict for a grammar that I know has no ambiguity. The case is one of the if else type but it's not the 'dangling else' problem since I have mandatory END clauses delimiting code blocks. Here is the grammar for gppg (Its a Bison like compiler compiler ... and that was not an echo): %output=program.cs %start program %token FOR %token END %token THINGS %token WHILE %token SET %token IF %token ELSEIF %token ELSE %% program : statements ;

How can i see the live parse tree using Antlr4 Ide in Eclipse?

。_饼干妹妹 提交于 2019-12-06 19:31:28
问题 I'm new using Antlr4 but I know that exist a plugin for Eclipse. I have a simple question...After I created the g4 file how can I visualize the live parse tree in order to see the tree of an input expression? Thanks 回答1: Currently there is no provision for viewing live parse tree in ANTLR 4 IDE for Eclipse. Meanwhile, you can see the parse tree using -gui switch in the command line. It also provides a feature of saving the parse tree as PNG. 回答2: After installing Antlr4Ide plugin in Eclipse:

CFG for python-style tuples

泄露秘密 提交于 2019-12-06 13:13:58
After having read for the zillionth time a question about "How do I parse HTML with Regex" on Stackoverflow, I got myself interested again in grammars, grabbed my university scripts and after a few minutes I wondered how I've ever passed my exams. As a simple (well, "simple" I expected it to be) exercise I tried to write a CFG that produces valid python tuples (for simplicity's sake only using the identifiers a , b and c ). After some good time I now came up with this: G = ( {Tuple, TupleItem, Id}, {“a”, “b”, “c”, “,”, “(“, “)”}, P, Tuple) Being P: Tuple → “(“ TupleItem “)” Tuple → “(“