
I have a grammar that is not quite so LL as I would like. My newest stumbling block is that any keyword can also be an identifier. For example, the language has a delete statement, but there is also a built-in Delete method. Plus, I could just use Delete as a variable name:
Delete Table, Key else
// Handle Error
end
NewArray = Delete(Array, 1, 0, 0)
Delete = "Hello, World!"
Here are the relavant grammar rules:
AssignmentOrMethodStatement
: VarOrMethod ( PostfixExpression? (
@Plus
| @Minus
| @Colon
)? @EqualSign Expression )? StatementTerminator
;
DeleteStatement
: @Delete @Cursor? Expression @Comma Expression ThenElse
;
VarOrMethod
: Identifier ( @OpenParenthesis ExpressionList? @CloseParenthesis )?
;
Identifier
: @IdentifierTerminal | @VariabelAt | @VariableDollar | @VariablePercent | @LabelInGoSub
;
If I add @Delete to the Identifier alternation, then I'll get an ambiguity issue that I don't see as being easily solved using a CanMatchCallback.
It seems what I need is the ability for parser to always look at AssignmentOrMethodStatement first and, if it errors out, to then try the DeleteStatement. I see there is are OnErrorIgnore and OnErrorContinue options, but that doesn't solve the ambiguity issue unless I can somehow convert the delete token's id and classification on the fly at that exact moment to make it a standard identifier.
I know the language I bring to you is unusual: it's a deriviative of BASIC that allows for some very nasty code:
If Return = Return() then
Return
end else
Return = Return()
end
I guess I'm trying to determine if I need to cut my losses and abandon the LLParser framework in favor of a custom IParser. I thought I'd check first to see if there is something I overlooked.