[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Sub grammars
Hi Bert,
I think you want to parse a language embebed into other, like sql into Java, CICS into Cobol or similar.
We do that by preprocessing the source. We put a tag at the beginig and at the end of "B" sentences, and we define this production (with tags that are only possible in "B" grammar) into our "A" grammar.
When we get a "B" sentence during the reading of "A", we can call de "B" Sable-Grammar parser to get a "B" tree. We can parse and work with this. After that we continue with "A" parsing.
I'm not sure that this is the better way, but it works fine.
In the preprocessing you can do many other things to prepare the source.
I hope having help you.
Javier.
2010/6/22 Bert Vanhooff
<bert.vanhooff@xxxxxxxxx>
Hi,
I would like to specify a grammar in two parts, where one grammar is a subset of the other.
For example..
start = // Startnode of language A
{expr} some_expression
| {literal} literal;
literal = // Virtual startnode of language B, which is a subset of A
numeric_literal
| line_literal
| circly_literal;
The start production represents the main language (A). The literal production encapsulates a separately defined language to express literals (B). I would like to be able to parse language A (including what is defined in B) and also parse only the part that is defined in language B separately.
I can't give anything in the form of a literal (B) directly to the parser for the complete language (A) since it will always give me a Start node (Start tree = parser.parse()). This means that if I pass in a literal string (B), it will fail with parse errors.
What I would like is to define the grammar of the two languages in separate files and generate separate parsers for them. Language A would than have to delegate part of the parsing process to language B in some way (possibly in a tree walker ?).
However, I don't really have a good idea on how to do this. I did find a similar post on this (http://lists.sablecc.org/pipermail/sablecc-user/msg00441.html), but it didn't help me a lot.
Are there any ideas on this?
Thanks in advance,
Bert.
_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@xxxxxxxxxxxxxxxxx
http://lists.sablecc.org/listinfo/sablecc-discussion