Re: Feature request for gobo yacc

Eric Bezault <ericb-D6Qt/9opevxWk0Htik3J/[email protected]>
Newsgroups gmane.comp.lang.eiffel.gobo.general
Organization Gobo
Message-ID <[email protected]>
Nicholas Allen wrote:
> Hi Eric,
> 
> Great work on the Gobo Eiffel library! I was just wondering how easy it would 
> be to add the following feature to gobo yacc. What would be great is if one 
> could specify multiple top level rules within a grammer. What I mean by this 
> is that yacc would then produce a parse table and parse routine for each top 
> level rule. This would allow one to parse small sections of a grammar without 
> having to copy those sections into another .y file and keep them in sync. For 
> example, I would like to be able to parse whole programs from my grammar but 
> also single expressions. If I could specify that expression could also be a 
> top level rule and yacc created two parse routines that would be ideal (eg 
> parse_program and parse_expression). The routine could be named by the name 
> of the top level rule automatically. In this case I would only have one 
> grammar file but would create a parser cabable of parsing different things 
> (whole programs or just expressions).
> 
> I probably didn't explain that very well....

No, I perfectly understood what you described. The algorithm used
in geyacc (and more generally in yacc) does not allow to have
several entry points. Indeed, telling geyacc to generate several
parsers (one per entry point) is a solution. For what the implementation
of geyacc is concerned, it would be easier to have it generate a
different class for each entry point. For example:

   geyacc --start=program -o program_parser.e parser.y
   geyacc --start=expression -o expression_parser.e parser.y

The problem is that even though they are generated in different
files, these parser classes will have the same name (the one
specified in the file parser.y). Your suggestion of having a single
parser class but several parse routines seems attractive. The
problem that would need to be addressed in the implementation of
geyacc is that everything would need to have to be duplicated
(with different names) in the class: not only the generated tables
as you pointed out, but also the features (either inherited from
the skeleton classes or generated in the parser class itself) that
use these tables. I will have to have a closer look at the code
in order to see if this is feasible and at what price.

In the meantime, here is a trick that I recently sent to the
Gobo developer mailing list and that might work for you:

 >> On a related issue, I did not even consider using geyacc for the
 >> parser, as XSLT needs three different entry points - one for the full
 >> XPath expression language, and two sub-languages. It is my
 >> understanding that this is not possible with geyacc and it's ilk. Am
 >> I right?
 >
 > Yes, although there are some tricks to simulate several entry points,
 > with one start rule or-ing the entry points, and then setting some
 > boolean attributes to remember which of the entry points we wanted to
 > use. If it is the semantic action of the corresponding entry point
 > which is executed then everything is fine, otherwise there is a
 > syntax error.
 >
 > %start global_entry_point
 > %%
 > global_entry_point: entry_point1
 >       {
 >          if not entry_point1_chosen then
 >              -- report syntax error
 >          else
 >              ...
 >          end
 >       }
 >   | entry_point2
 >       {
 >          if not entry_point2_chosen then
 >              -- report syntax error
 >          else
 >              ...
 >          end
 >       }
 >   | ...
 >   ;
 >
 > With this technique there is the risk of intruducing ambiguities
 > in the grammar though.

-- 
Eric Bezault
mailto:ericb-D6Qt/9opevxWk0Htik3J/[email protected]
http://www.gobosoft.com



------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com.  Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/saFolB/TM
---------------------------------------------------------------------~->

To Post a message, send it to:   [email protected]
To Unsubscribe, send a blank message to: [email protected] 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/gobo-eiffel/

<*> To unsubscribe from this group, send an email to:
     [email protected]

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.