Re: Parsing fully context-free grammars



> "Paul Mann" <paul@xxxxxxxxxxxx> wrote
>> It's just plain ambiguous and shows one of the pitfalls of GLR systems.
>
> I don't see why this is pitfall of GLR parsers; rather I think is a
> pitfall of the grammar notation we use.

There is nothing wrong with notation that allows a dangling else.
The problem is the dangling else, not the notation.

> If the grammar is ambiguous but we always mean shift 'else' and not
> reduce the <if-statement> then the problem is profoundly that we have
> not stated it in the grammar.

Nope, shift-reduce conflicts are valid conflicts. To avoid these
additional notation could be added which would work like the PEG '/'
notation.

IfStmt -> if '(' Exp ')' Stmt else Stmt
/ if '(' Exp ')' Stmt

In PEG parser generators this will not cause a conflict,
because by definition it will choose the shift action. It will
not cause a conflict in an LR parser generator that has an option
to ignore all shift-reduce conflicts (like LRgen has).

> We could disambiguate by restating the grammar as:
>
> <stmt> ::= <if-stmt>
> | <if-else-stmt>
>
> <if-stmt> ::= if ( cond ) <stmt>
>
> <if-else-stmt> ::= if ( cond ) <non-if-stmt> else <stmt>
>
> <non-if-stmt> ::= <if-else-stmt>

This grammar does not have the dangling else problem, so it is
a different grammar and different language.

BTW, this grammar is unworkable in LR/LALR parser generators.
<stmt> is unreducible. It is a circular grammar.

Paul Mann
http://parsetec.com
.



Relevant Pages

  • Early access availability of a C++/Java PG
    ... Its supported notation is described ... "Syntaxis.jar" is a zero installation visual Parser/Scanner Generator ... One defines a BNF Grammar and can construct a Lexical Analyzer ... or a Parser, with the following restrictions: ...
    (comp.compilers)
  • Re: terminological problem (EBNF & regular expressions)
    ... And the other notation is widely used also (e.g. Microsoft guide to ... > I am looking for a word for this kind of regular expressions. ... > to emphasize, that one has not to learn a new grammar, to use the ... Yes, this is more concise, but it's new to me and therefore I would ...
    (comp.compilers)
  • Re: What annoys you in mathematical text?
    ... What I really like in a book is a kind of road map that tells the reader where we are going, and/or why we are doing it. ... Style for style's sake (like grammar or spelling) are not things I worry about, so if you put a math symbol at the beginning of a sentence I am not going to get bent out of shape. ... If you do insist on non-standard terminology or notation, at least make sure that you have a very good index. ... Also, if I might brag a little, on MathSciNet, two of my more recent papers got a nice comment on how well they were written. ...
    (sci.math)
  • Re: Reduce/Reduce conflict in Algol60 grammar
    ... that requires a context sensitive grammar. ... problem, or more correctly, it is a lousy formalism for solving that ... good notation for expressing typing decisions. ...
    (comp.compilers)
  • Re: Is pyparsing really a recursive descent parser?
    ... There are an enormous variety of parsing tools, ... For instance, the Earley parser ... Okay, in some contexts, an ambiguous grammar may be considered ... over the other through the context of the parse results? ...
    (comp.lang.python)