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

Re: Line-by-line evaluation or all at once?

-------- Original Message --------
From: Marco Ladermann <ladermann@hbg.dpa.de>
Organization: dpa - Deutsche Presse-Agentur GmbH
To: SableCC List <sablecc-list@sable.mcgill.ca>
Subject: Re: Line-by-line evaluation or all at once?
Date: Tue, 17 Apr 2001 11:46:59 +0200

Dan Sandberg wrote:
> Parsing line by line relates to two other SableCC feature possibilities:
> 1 - Being able to parse constructs in the grammar other than just the
> starting production.  If you have a bunch of different kinds of
> statements that need to be parsed, and they share common helpers,
> tokens, etc, it would be nice if they could all be in one grammar file,
> and you could instruct SableCC to parse one or the other.  Right now you
> need completely different parsers for each production you want to be
> able to parse.

The following trick can do the job: Introduce "selector" tokens to the 
grammar and than prepend the input with that token to select the part of
grammar you want to use.


         javaSelector = "java:";
         pascalSelector = "pascal:";

         grammar = {java} javaSelector javaGrammar
                 |   {pascal} pascalSelector pascalGrammar;


Prepending the selector can be done by: 

Marco Ladermann
dpa, Deutsche Presse-Agentur GmbH
ladermann@hbg.dpa.de (PGP-Schlüssel auf Anfrage)
Tel. +49 40 4113 2414   Fax  +49 40 4113 2479