help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calling a parser from a parser


From: Hans Aberg
Subject: Re: Calling a parser from a parser
Date: Tue, 26 Oct 2004 18:54:31 +0200
User-agent: Microsoft-Outlook-Express-Macintosh-Edition/5.0.6

on 2004/10/26 08:38, Tim Van Holder at address@hidden wrote:

> Antoine Fink wrote:
>> Hi,
>> 
>> Is it possible with Bison/Yacc to parse a language using 2 parsers for
>> different sections ?
> 
> Sure, I think it is, provided you don't need any lex state from before
> the section (if you do, that /might/ make things harder).
> What I would try is:
> 
> - assuming you have 2 languages, foo and bar, with 'bar' sections
> within 'foo' sources, ...

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.

  Hans Aberg






reply via email to

[Prev in Thread] Current Thread [Next in Thread]