ambiguous-grammar

Simple ambiguous grammar with reduce-reduce conflict

独自空忆成欢 提交于 2019-12-11 03:24:43
问题 The following simple grammar to parse a logical expression results in a reduce/reduce conflict: %token AND OR %token NUMBER VARIABLE %% logical_expr : logical_expr AND logical_term | logical_expr OR logical_term | logical_term ; logical_term : VARIABLE | comparison | '(' logical_expr ')' ; comparison : expr '<' expr | expr '>' expr ; expr : expr '+' term | expr '-' term | term ; term : NUMBER | VARIABLE | '(' expr ')' ; %% The status report from bison has: state 2 4 logical_term: VARIABLE .

what is an ambiguous context free grammar?

大憨熊 提交于 2019-12-10 20:53:36
问题 I'm not really very clear on the concept of ambiguity in context free grammars. If anybody could help me out and explain the concept or provide a good resource I'd greatly appreciate it. 回答1: T * U; Is that a pointer declaration or a multiplication? You can't tell until you know what T and U actually are . So the syntax of the expression depends on the semantics (meaning) of the expression. That's not context-free -- in a context-free language, that could only be one thing, not two. (This is

How does Swift disambiguate Type Arguments in Expression Contexts?

浪尽此生 提交于 2019-12-08 00:59:40
问题 Take a look at the following two expressions: baz(Foo<Bar, Bar>(0)) baz(Foo < Bar, Bar > (0)) Without knowing what, baz , Foo and Bar are ( baz can be a type or a method, Foo and Bar can be types or variables), there is no way of disambiguating whether the < represents a type argument list or a less-than operator. // two different outcomes, difference shown with parentheses baz((Foo<Bar,Bar>(0))) // generics baz((Foo < Bar), (Bar > 0)) // less-than Any sane programming language should not

How does Swift disambiguate Type Arguments in Expression Contexts?

拈花ヽ惹草 提交于 2019-12-06 04:28:23
Take a look at the following two expressions: baz(Foo<Bar, Bar>(0)) baz(Foo < Bar, Bar > (0)) Without knowing what, baz , Foo and Bar are ( baz can be a type or a method, Foo and Bar can be types or variables), there is no way of disambiguating whether the < represents a type argument list or a less-than operator. // two different outcomes, difference shown with parentheses baz((Foo<Bar,Bar>(0))) // generics baz((Foo < Bar), (Bar > 0)) // less-than Any sane programming language should not rely on what baz , Foo and Bar are when parsing an expression like this. Yet, Swift manages to

What is the easiest way of telling whether a BNF grammar is ambiguous or not?

怎甘沉沦 提交于 2019-12-01 03:10:35
Namely, is there a tool out there that will automatically show the full language for a given grammar, including highlighting ambiguities (if any)? There might be some peculiarity about BNF-style grammars, but in general, deciding whether a given context-free grammar (such as BNF) is ambiguous is not possible. In short, there does not exist a tool because in general, that tool is mathematically impossible. There might be some special cases that could work for you, though. In general, no. But as a practical approach, what you can do, is given a grammar, is for each rule, to enumerate possible

What is the easiest way of telling whether a BNF grammar is ambiguous or not?

梦想与她 提交于 2019-11-30 23:13:14
问题 Namely, is there a tool out there that will automatically show the full language for a given grammar, including highlighting ambiguities (if any)? 回答1: There might be some peculiarity about BNF-style grammars, but in general, deciding whether a given context-free grammar (such as BNF) is ambiguous is not possible. In short, there does not exist a tool because in general, that tool is mathematically impossible. There might be some special cases that could work for you, though. 回答2: In general,

Removing sensitive data from Git. “fatal: ambiguous argument 'rm'”

蓝咒 提交于 2019-11-30 17:46:28
I'm trying to run this command: git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch filename.js' --prune-empty --tag-name-filter cat -- --all but I keep getting this error: fatal: ambiguous argument 'rm': unknown revision or path not in the working tree . Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]' It depends on the shell you are using. On Windows, with msysgit for instance, see issue 477 : Single quotes do not have a special meaning with CMD. Do not expect that they work the same as with a POSIX shell. Call filter

Removing sensitive data from Git. “fatal: ambiguous argument 'rm'”

一世执手 提交于 2019-11-30 01:19:25
问题 I'm trying to run this command: git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch filename.js' --prune-empty --tag-name-filter cat -- --all but I keep getting this error: fatal: ambiguous argument 'rm': unknown revision or path not in the working tree . Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]' 回答1: It depends on the shell you are using. On Windows, with msysgit for instance, see issue 477: Single quotes do

How are ambiguous enum values resolved in C#?

◇◆丶佛笑我妖孽 提交于 2019-11-29 15:59:47
问题 I checked the section of the C# language specification regarding enums, but was unable to explain the output for the following code: enum en { a = 1, b = 1, c = 1, d = 2, e = 2, f = 2, g = 3, h = 3, i = 3, j = 4, k = 4, l = 4 } en[] list = new en[] { en.a, en.b, en.c, en.d, en.e, en.f, en.g, en.h, en.i, en.j, en.k, en.l }; foreach (en ele in list) { Console.WriteLine("{1}: {0}", (int)ele, ele); } It outputs: c: 1 c: 1 c: 1 d: 2 d: 2 d: 2 g: 3 g: 3 g: 3 k: 4 k: 4 k: 4 Now, why would it select