Re: Parsing Expression Grammar

Chris F Clark <cfc@shell01.TheWorld.com>
22 Sep 2005 23:51:43 -0400

          From comp.compilers

Related articles
[18 earlier articles]
Re: Parsing Expression Grammar DrDiettrich@compuserve.de (Hans-Peter Diettrich) (2005-09-17)
Re: Parsing Expression Grammar Meyer-Eltz@t-online.de (Detlef Meyer-Eltz) (2005-09-18)
Re: Parsing Expression Grammar cleos@nb.sympatico.ca (Cleo Saulnier) (2005-09-22)
Re: Parsing Expression Grammar schmitz@i3s.unice.fr (Sylvain Schmitz) (2005-09-22)
Re: Parsing Expression Grammar schmitz@i3s.unice.fr (Sylvain Schmitz) (2005-09-22)
Re: Parsing Expression Grammar rsc@swtch.com (Russ Cox) (2005-09-22)
Re: Parsing Expression Grammar cfc@shell01.TheWorld.com (Chris F Clark) (2005-09-22)
Re: Parsing Expression Grammar schmitz@i3s.unice.fr (Sylvain Schmitz) (2005-09-22)
Re: Parsing Expression Grammar paul@parsetec.com (Paul Mann) (2005-09-22)
Re: Parsing Expression Grammar cfc@shell01.TheWorld.com (Chris F Clark) (2005-09-23)
Re: Parsing Expression Grammar gneuner2@comcast.net (George Neuner) (2005-09-25)
Re: Parsing Expression Grammar cfc@world.std.com (Chris F Clark) (2005-09-25)
Re: Parsing Expression Grammar cfc@TheWorld.com (Chris F Clark) (2005-09-27)
[3 later articles]
| List of all articles for this month |

From: Chris F Clark <cfc@shell01.TheWorld.com>
Newsgroups: comp.compilers
Date: 22 Sep 2005 23:51:43 -0400
Organization: The World Public Access UNIX, Brookline, MA
References: 05-09-023 05-09-045 05-09-053
Keywords: parse
Posted-Date: 22 Sep 2005 23:51:43 EDT

George Neuner <gneuner2@comcast.net> writes:


> The need to embed actions depends greatly on the language ...
> resolving context sensitivity requires predication and predication
> requires mid-rule computations.


I think predicates are wonderful. I don't know that predicates
"require" mid-rule computations. Syntactic ones don't. Semantic
predicates "are" mid-rule computations, so yes they require them.


> LR can be inefficient for a context sensitive language because
> reductions aren't applied until all the tokens have already been
> constructed. The usual LALR work around is either to defer
> everything until later [the approach you seem to favor] or to create
> back channels to the lexer and perform as much disambiguation as
> possible there. But neither of these approaches handle languages
> which must be lexed differently in different contexts.


Presuming one has mid-rule computations (and those are not hard to
implement in an LR parser generator), one can also determine context
before the dependent tokens have been constructed. It is a persistent
myth that LL parsers have inheriently more context information than LR
parsers. It is only true, if one has null productions that are used
in multiple contexts and then only if one is doing SLR or LALR
parsing, so that states with different lookahead sets are merged. If
one has an LL grammar for the language, an LR parser will also have
nicely disambiguated contexts. The myth persists because an LR
grammar that is not LL will have ambiguous contexts, which is why the
grammar is not LL. Note, when using mulitple lookahead (LL(k))
grammars, there are also places where the tokens have to be
constructed before the context is determined, i.e. for the first k
tokens of rules that need the lookahead for discrimination.


However, these are just minor quibbles. It isn't context that sells
most users on LL over LR parsing, it is recursive descent output.
That is a much more "transparent" output format than the best labelled
table driven approach. So, if you need to debug your grammar, you
will probably prefer an LL generator that outputs recusrive descent
code. (Now, I agree with Cleo Saulnier, that I personally prefer LR
table output, but I've had more than a little experience dealing with
it and the Yacc++ tables reflect my mental habits.)


Hope this helps,
-Chris


*****************************************************************************
Chris Clark Internet : compres@world.std.com
Compiler Resources, Inc. Web Site : http://world.std.com/~compres
23 Bailey Rd voice : (508) 435-5016
Berlin, MA 01503 USA fax : (978) 838-0263 (24 hours)


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.