This project has moved. For the latest updates, please go here.

Problem with rule priority.

Jun 30, 2014 at 2:32 PM
I have a rule like that c = a | b. The prooblem is that "a" rule has "b" rule as its part. And when im trying to use "a" rule error appears because parser is trying to parse "b" rule.
Can I somwhow force parser to check "a" rule first and only then "b" rule?

Jun 30, 2014 at 5:36 PM
not sure what you mean. Parser, as it is LALR parser, does not check one thing first, then other thing - it 'explores' all paths in parallel. Or mean that 'a' and 'b' are terminals, and it is scanner that messes up? in the case of terminals you can set Priority property to force scan attempt order.
Jun 30, 2014 at 9:08 PM
i'll try ot explain my sotiation.
One rule is a definition of C-like struct "struct { some fields}" another rule is a composition of that definition and variable delcaration like "struct {some fields} var;"

When I use theese rules individually they work fine, but when i try to make new rule "first | second" and give the string "struct {some fields} var;" as input parser allways trying to parse input as first rule and allways fail because there is variable definition after struct declaration. The question is: How can i sort this problem out?
Jun 30, 2014 at 9:18 PM
ah, you should then define one structNonTerminal, with optional 'var' at the end.
Jun 30, 2014 at 9:30 PM
It's not so simple.
  1. when i declare a variable i can use not only struct definition but also typenames so the second rule is "build_in_types|struct_definition|typenames + identifier;"
  2. i created 2 rules to distinguish struct definitions and variable declarations
Jun 30, 2014 at 9:37 PM
well, that's your problem - you try to follow semantics (what is var decl) instead of first following pure grammatic structure. Focus on surface, structural similarities - that's what parser is trying to follow, and not 'meaning'/semantics
Jun 30, 2014 at 9:57 PM
Thank you. I'll try.