[comp.compilers] Looking for dynamic parser generator

turpin@cs.utexas.edu (Russell Turpin) (03/02/91)

Most parser generators are designed with the idea that grammar processing and
table generation take place during the development phase of a system, so that
the primary language processing function provided at run time is the ability
to parse strings in one (or perhaps a small fixed number) of languages.  I am
interested in any parser generators that work entirely as a set of C
procedures at run-time, so that one can, at run time, parse strings from many
languages and also define new languages.  This requires two primary
functions:

	grammar		->    "build parse	-> status
			       table"		-> parse table

	parse table	->    "parse		-> status
	input string	->     string"		-> parse tree 

Notice that the parser must produce a parse tree, rather than depending on C
(and hence, compiled) semantic actions.  Does anyone know how to do this
without writing such procedures from scratch?

I doubt this can be done with yacc and lex.

Russell
[I suppose you could run yacc in a subprocess and then read the y.out.c
file to load up some tables.  There have been systems that allow you to
augment the syntax as the program is being compiled such as IMP10 and EL/1.
-John]
-- 
Send compilers articles to compilers@iecc.cambridge.ma.us or
{ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.

joshua@Atherton.COM (Joshua Levy) (03/08/91)

In article <18231@cs.utexas.edu> turpin@cs.utexas.edu (Russell Turpin) writes:
>I am interested in any parser generators ... that one can, at run time, 
>parse strings from many languages and also define new languages.  ...
>
>I doubt this can be done with yacc and lex.

Ye of little faith! :-)  Read "Parsing Distfix Operators" in CACM Feb. 1986
(Vol 29, #2) by Simon L. Peyton Jones on page 118.  To quote the summary:

    We have described a simple technique whereby a fixed BNF grammar can 
    describe languages including user defined infix, postfix, and disfix 
    operators.  The technique requires only that the parts of disfix operators
    be lexically distinguishable.  Standard parser generators can then produce
    efficient parsers for such grammars ...  The idea has been successfully
    implemented with minimal effort.

The paper is only 5 pages long, easy to understand, and includes some
sample code.  They use YACC as their "standard parser generator".  Note
the limitation of the method: certain tokens must be lexically
distinguishable.  I doubt this solves your whole problem, but I think
it solves part of it.

Joshua Levy   (joshua@atherton.com)   408-734-9822

-- 
Send compilers articles to compilers@iecc.cambridge.ma.us or
{ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.