|
From: | Tim Van Holder |
Subject: | Re: Empty rule spoiling error reporting |
Date: | Thu, 05 Aug 2004 08:12:36 +0200 |
User-agent: | Mozilla Thunderbird 0.7.1 (Windows/20040626) |
hz kto wrote:
My grammar contains a lot of optional rules like this rule1 : token3 {...} | token2 {...} | opt_something1 token1 {...} When in certain context parser does not see token1,2,3 nor anything non-empty from opt_something1, it matches an empty rule and then, when it starts searching for tokens that could follow next, it only finds token1 since it already in the state corresponding to opt_something1.I just want to report more possible tokens. As it stands now I report only one instead of several in these cases.
Well then I'm afraid you'll have to refactor your rules: rule1 : token1 { ... } | something1 token1 { ... } | token2 { ... } | token3 { ... } ; Now the parser should be able to list more possible tokens if a bad token is seen at the start of rule1. Note that this requires a lot of work if you have all your opt_ rules in the form: opt_foo : /* empty */ | foo_format_1 | foo_format_2 | foo_format_3 ; I strongly recommend using only trivial opt_ rules from the get go: opt_foo : /* empty */ | foo ; foo : foo_format_1 | foo_format_2 | foo_format_3 ; This uses more rules but makes it much easier to work with. Similarly for mul_ an plus_ rules (to handle */+ repetition): mul_foo : /* empty */ | plus_foo ; plus_foo : foo | plus_foo foo ;
[Prev in Thread] | Current Thread | [Next in Thread] |