Previous: Parsing keywords, Up: Syntax parsing



12.3.3 forward, near and far as weak keywords

forward is a little special in ISO 7185 in that it is no keyword, so it may be used as an identifier and a directive at the same time. That's more than what our weak keywords allow.

This problem would be easy to solve if we just parsed it as a plain identifier (LEX_ID) and then check that it was in fact forward.

However, the same applies to the BP directives near and far. (At least so it seems – the BP documentation claims they're reserved words, but the compiler seems to think otherwise.)

Parsing all the three together as an identifier and then checking which one it was fails because forward is a remote directive, i.e. a routine declared so has no body, while near and far are not. So it makes a syntactical difference for what follows.

So we lex the three like regular (non-weak) keywords, but throw their tokens together with LEX_ID very early in the parser, in the id rule which is used everywhere an existing identifier is expected. But in the context of these three directives, no identifier is allowed, so the three tokens can be used without conflicts between each other or with id.