[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Calling a parser from a parser
From: |
Frank Heckenbach |
Subject: |
Re: Calling a parser from a parser |
Date: |
Wed, 27 Oct 2004 18:17:17 +0200 |
User-agent: |
semail 20041018 |
Hans Aberg wrote:
> There is in fact a situation where one writes a parser within a parser, and
> that is the case when the inner parser is dynamic in a way that it cannot be
> handled by the outer parser. This happens, for example, when the grammar has
> a large number of precedence levels (as in say Pascal): One can then let the
> outer parser just collect the tokens into a sequence, and let another parser
> sort out the semantics by the use of the precedence levels. In a language
> with just a few precedence levels, like Haskell, which only has ten, one can
> do it either way: Use this method, or write a .y section for each precedence
> level.
I really don't know what's it with you and Pascal, but just FYI,
Pascal has only 5 levels of precedence:
parentheses
exponentiating-operator
multiplying-operator
adding-operator
relational-operator
Some dialects may have one or two more, but that's still quite a bit
less than C (which has 15 according to gcc's grammar) or Haskell (10
according to you).
Apart from that, why do you think that a simple parser couldn't
handle even many more levels of precedence? In fact, that's one of
the strengths of LALR(1), and the canonical examplel are of this
kind.
Frank
--
Frank Heckenbach, address@hidden
http://fjf.gnu.de/
GnuPG and PGP keys: http://fjf.gnu.de/plan (7977168E)