grammar

Context-sensitivity vs Ambiguity

跟風遠走 提交于 2019-12-05 12:39:29
问题 I'm confused about how context-sensitivity and ambiguity influence each other. What i think is correct is: Ambiguity: An ambiguous grammar leads to the construction of more than one parse-tree using either left or right derivation. A language where all possible grammars are ambiguous is an ambiguous language. For instance C++ is an ambiguous language because x * y always can mean two different things as discussed in: Why can't C++ be parsed with a LR(1) parser?. Context-sensitivity: A context

How can I push the current execution state into a stack so that I can continue from it later?

给你一囗甜甜゛ 提交于 2019-12-05 12:36:45
Imagine a simple grammar: (a|ab)c Which reads (a or ab) followed by c. The parse tree would look like this: and / \ or c / \ a ab Now given it this input: abc We would traverse first down the left side of the tree, and match "a", then go back up a level. Since "a" matched, the "or" is also true, so move on to the "c". "c" does not match, and we hit the end of the road. But there was an alternate path it could have taken; had we traversed down to "ab", we would have found a match. So what I want to do for "or" nodes is essentially this: Evaluate left branch If left branch doesn't match, try

how can i prove that this grammar is ambiguous?

↘锁芯ラ 提交于 2019-12-05 10:55:08
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. 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 . Shweta There is a string though: bbaaba S -> bA -> bbAA -> bbaA -> bbaaS -> bbaabA -> bbaaba S -> bA -> bbAA -> bbaSA -> bbaaBA -> bbaabA -> bbaaba 来源: https://stackoverflow.com/questions/4878418/how-can-i-prove-that-this-grammar-is-ambiguous

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

人盡茶涼 提交于 2019-12-05 10:08:35
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. 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 highlighting, parsing, type checking, evaluators) in the future. For those interested in the history, the

init-declarator-list and the GNU GCC attribute grammar

别来无恙 提交于 2019-12-05 09:06:27
I am revamping an inhouse C language bison/flex-based parser, amongst others introducing proper __ attribute__ support. Since I cannot find any official BNF-style grammar which describes GNU GCC __ attribute__ idea (except the http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html document) I am extracting bits and pieces from the C++x11 standard and comments in various implementations found over the web. I have almost got it done (at least when it comes to parsing examples included in GCC's doc cited above) but one particular example has given me a headache with no hint of solution in

Why does this simple grammar have a shift/reduce conflict?

别等时光非礼了梦想. 提交于 2019-12-05 06:14:42
问题 %token <token> PLUS MINUS INT %left PLUS MINUS THIS WORKS: exp : exp PLUS exp; exp : exp MINUS exp; exp : INT; THIS HAS 2 SHIFT/REDUCE CONFLICTS: exp : exp binaryop exp; exp : INT; binaryop: PLUS | MINUS ; WHY? 回答1: This is because the second is in fact ambiguous. So is the first grammar, but you resolved the ambiguity by adding %left . This %left does not work in the second grammar, because associativity and precedence are not inherited from rule to rule. I.e. the binaryop nonterminal does

Grammar: difference between a top down and bottom up? (Example)

青春壹個敷衍的年華 提交于 2019-12-05 05:33:25
This is a follow up question from Grammar: difference between a top down and bottom up? I understand from that question that: the grammar itself isn't top-down or bottom-up, the parser is there are grammars that can be parsed by one but not the other (thanks Jerry Coffin So for this grammar (all possible mathematical formulas): E -> E T E E -> (E) E -> D T -> + | - | * | / D -> 0 D -> L G G -> G G G -> 0 | L L -> 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Would this be readable by a top down and bottom up parser? Could you say that this is a top down grammar or a bottom up grammar (or neither)? I am

Making a Grammar LL(1)

自闭症网瘾萝莉.ら 提交于 2019-12-05 04:46:41
I have the following grammar: S → a S b S | b S a S | ε Since I'm trying to write a small compiler for it, I'd like to make it LL(1). I see that there seems to be a FIRST/FOLLOW conflict here, and I know I have to use substitution to resolve it, but I'm not exactly sure how to go about it. Here is my proposed grammar, but I'm not sure if it's correct: S-> aSbT | epsilon T-> bFaF| epsilon F-> epsilon Can someone help out? templatetypedef In his original paper on LR parsing , Knuth gives the following grammar for this language, which he conjectures "is the briefest possible unambiguous grammar

“FOLLOW_set_in_”… is undefined in generated parser

我们两清 提交于 2019-12-05 04:16:09
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 operators: ... prio3Expression: prio2Expression (('*' | '/' | '%') prio2Expression)*; prio2Expression: ('+

Why is this c# snippet legal?

这一生的挚爱 提交于 2019-12-05 02:07:59
Silly question, but why does the following line compile? int[] i = new int[] {1,}; As you can see, I haven't entered in the second element and left a comma there. Still compiles even though you would expect it not to. I suppose because the ECMA 334 standard say: array-initializer: { variable-initializer-list(opt) } { variable-initializer-list , } variable-initializer-list: variable-initializer variable-initializer-list , variable-initializer variable-initializer: expression array-initializer As you can see, the trailing comma is allowed: { variable-initializer-list , } ↑ P.S. for a good answer