[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Andrew Cooke wrote:
> But then if the ID really was "if" you would parse it as a
> command instead of an ID.
> Two things might help:
> - you know more about the ID, like the number of characters, or
> that it is always capitals or something.
> - you use the context to help the parser work. For example,
> if an ID was always followed by a colon, but colons weren't used
> after commands then the parser would have no problem.
> There may be other ways too - I'm no expert on this :-)
My favourite method - when possible, this depends a little on the rules
for recognising keywords in your language - is to *LET* "if" be an ID in
the lexer. Just pre-declare it in the global scope as a symbol with an
extra attribute that triggers/suppresses the appropriate syntactic
rules. Since you have a symbol table anyway, this actually gives you
- From: Andrew Cooke <firstname.lastname@example.org>