I have a ply grammar that is designed to parse as much of FORTRAN 90
as I can, in order to write a bunch of code analysis and auto-
generation tools. I have a start symbol called 'top' which contains
everything else. In writing some new tools, I often find myself
wanting to parse a fragment of a file which I know starts with a
particular token, for example a type definition or a single subroutine
call. I'd like to build a parser instance that uses a subset of my
existing grammar, ie end up with a parser that will no longer accept
full FORTRAN files, but will quickly parse a string that is known to
(or suspected to) contain a few FORTRAN constructs of interest.

My first attempt at this is to add a routine to my parser definition:
def start_symbol(st):
    global parser
    parser = yacc.yacc(start=st, debug=0)

And then to call start_symbol('new_start_symbol') before calling
yacc.parse

This seems to work, but I get a page or ten of warnings from yacc
stating that there are unreachable symbols (which there are because
I'm now using a subset of the grammar intentionally). It also seems to
insist on rebuilding the parser from scratch each time, which isn't
good news for quick fire command line tools where picking up the
cached parser tables is really essential.

Is there any way I can mess with the internals of an existing parser
object to 'prime' it to be in a different starting state? Ie let PLY
load the cached tables, create a parser, and then just tweak the
existing instance?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ply-hack" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/ply-hack?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to