First of all, before you try to add error recovery, you should make sure your grammar is OK and parses correctly some sample programs. So let's focus on correctness of the grammar. You listed only a grammar constructor code, but there are some other
important pieces that should be there. Your grammar is indent-sensitive, like Python, you use Eos symbol in grammar just like Python grammar. It means that you need to add "CodeOutlineFilter" to scanner processing chain - are you doing this? Anyway,
please post the entire source code for the grammar class. Or email me directly the zip with your project (contact me directly through codeplex, I will reply and you'll send me the zip).
Now to your current grammar - I see some problems.
1. ParamList definition
ParamList.Rule = MakeStarRule(ParamList, comma, identifier) |
"(" + MakeStarRule(ParamList,comma,ParamWithType) +
- this is a wrong way to use MakeStarRule, don't "OR" it this way. It should always be a single MakeStarRule on the right.
Block.Rule = Indent + StmtList + Dedent;
Block.ErrorRule = SyntaxError + Eos;
this is incorrect - ErrorRule should always end with the same symbol as the main "Rule". What you tell parser is that "in case of error, skip everything until this symbol" - where this symbol is the last terminal in regular Rule.
So it should be "Block.ErrorRule = SyntaxError + Dedent;"
The same goes for AssignmentStmt. For now, remove all ErrorRule assignments, let's focus on building correct grammar, and then moving to error recovery
3. qual_name_segments_opt.Rule definition.
You define name segment as "dot + identifier", and then build a star-list with null delimiter. It is better to simply build it as a star-list of identifiers with dot as list delimiter (second parameter to MakeStarRule function).
4. Minor things - I think you can simplify things a bit. Why you separate "BinOp" and "CmpOp", and define BinExpr as "OR" of two types? would be simpler to include CmpOp symbols into BinOp - they are all binary operators. CondExpr
- should be simplified, define else_clause_opt expression and use it in a single "+" expression.
Let's clear it up