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

Mix 'n match grammars??



I am quickly learning just how much I don't know about building parsers; but I appreciate the help.

I think I have come to the conclusion that I have a fundamental problem in trying to write a parser for my tool,
because it has essentially 2 modes. On the one hand, it allows typical arithmetic operations like a programming
language, but on the other hand you can mix in "commands" with keywords.  Thus, you can have things like:

CALL Sub(A,B)
A = 1. + (B/3)
IF A > 1.2 THEN
   CmdA operation=xyz scale=1+2*(b/3) 1 2 mesg='Option 1'
ELSE
   CmdB operation=xyz scale=1-2*(b/3) 3 4 mesg='Option 2'
ENDIF

And unfortunately, the syntaxes are slightly different.  Most notably, in the CmdA and CmdB lines, spaces are
used to delimit the keywords (which may/may not be prefixed by "keywordname="... ie they can be positional) while 
everywhere else spaces are ignored.

So, now I am thinking that I should write two separate grammars, and somehow switch between the two depending on what
kind of line I am on.  However, I am not sure just exactly how to proceed.  Can anyone offer any suggestions as to
how this might be done, or is it simply not possible?

Thanks for any help!

Roger


-- 
___________________________________________________________
Sign-up for Ads Free at Mail.com
http://promo.mail.com/adsfreejump.htm