help-bison
[Top][All Lists]
Advanced

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

"nested" languages


From: Neil Conway
Subject: "nested" languages
Date: Tue, 28 Jun 2005 11:40:45 +1000
User-agent: Debian Thunderbird 1.0.2 (X11/20050602)

I'm trying to use Bison to construct a parser for a language A that needs to allow syntax from a second language B to be embedded within it (at well-defined positions within A). For example, suppose a production from the grammar of A is:

        if_stmt: IF expr THEN if_body END IF ;

where "expr" is a production in *another* Bison grammar. Language B is defined by a fairly complex grammar that changes with some regularity (in this case, the embedded language B is SQL, defined by an ~8500 line bison grammar). B's grammar is maintained separately -- merging B's grammar into the grammar for A and maintaining two copies is a headache I'd like to avoid, if possible. Ideally I'd like to have A's parser "call into" B's parser, have it accept as much input as it can, and then return control to A's parser.

Is this possible? One idea would be to use hand-written parsers for both languages, although it would be nice to stick with Bison if possible.

(At present this is implemented by having the lexer look for a delimiter in the input that we know marks the end of the tokens of the embedded language. We then concatenate these tokens into a string, and eventually pass that string to the yyparse() of the embedded language's parser. So in the above example we would basically consume tokens until we see a "THEN", and assume that anything between the "IF" and the "THEN" is a SQL statement. This is ugly, to say the least.)

-Neil




reply via email to

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