It's become obvious that keywords and reserved words receive separate treatment within the Reference BrightScript Implementation (RBI), e.g.:
The as keyword is not a reserved word, so is a valid variable name.
The Type reserved word is not a keyword - just a reserved identifier.
Since these properties seem to be able to vary independently, it makes sense to handle them separately within the lexer and parser created here.
Reserved words should be lexed as regular identifiers. Handling of reserved word usage can be handled in one of two ways:
(Preferred, and probably simpler) Identifiers (see Token.ts) gain a new boolean member isReserved; the interpreter simply checks for truthiness of that value.
(Slower and likely involves lots of repeated logic) The interpreter checks all identifiers against the reserved word list at each use.
Example: type("foo") gets lexed into something like [ Identifier("type"), LefParen, Literal("foo"), RightParen ]
Keywords are lexed into Tokens with the kind property equal to their own Lexemes.
Example: foo and bar gets lexed into something like [ Identifier("foo"), And, Identifier("bar") ]
It's become obvious that keywords and reserved words receive separate treatment within the Reference BrightScript Implementation (RBI), e.g.:
as
keyword is not a reserved word, so is a valid variable name.Type
reserved word is not a keyword - just a reserved identifier.Since these properties seem to be able to vary independently, it makes sense to handle them separately within the lexer and parser created here.
Identifier
s (seeToken.ts
) gain a new boolean memberisReserved
; the interpreter simply checks for truthiness of that value.type("foo")
gets lexed into something like[ Identifier("type"), LefParen, Literal("foo"), RightParen ]
Token
s with thekind
property equal to their ownLexeme
s.foo and bar
gets lexed into something like[ Identifier("foo"), And, Identifier("bar") ]