Can I use assigned actions to create different parse rules that have common prefix? #730
Replies: 1 comment 1 reply
-
Hey @luan-xiaokun,
You're right, such an expression always requires parentheses to split the upper bound expression from the array declaration part.
The way I'm imagining your grammar/language to look like, I don't believe that LL(k) is able to handle your language without resorting to assigned actions. Even increasing k wouldn't help (note that this is possible by supplying a However, I could be wrong. Do you mind sharing a snippet of what you already have? It might be possible to do this, if your grammar doesn't look the way I imagine it to llok. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi guys, I'm here for help, again.
My problem is that, the language I'm working on has two integer types: the normal integer type
int
and the bounded integer typeint lbound=Expression '..' ubound=Expression
, and there is also the array type, which can be declared byint[]
or(int 0 .. 1)[3]
. The parentheses for array of bounded integer should be necessary since there may be something likea[0]
in the upper bound expression and we cannot tell whether such a last pair of brackets belongs to the upper bound expression or the array type without the parentheses (please correct me if there is a way to do so).Therefore, I think that the normal integer type and the bounded integer type should be declared as different parse rules so that I can write the array type parse rule. If I use different parse rules for these two integer types, then I get an error for common prefix in these two rules since the underlying algorithm is LL(k), and if I use the assigned actions to fix the error, then it will end up only one parse rule with different semantic types.
Is there any way to solve this problem? Or is this a case that the LL(k) algorithm cannot handle?
PS: in this language, variable declaration is in the form of
Id: Type
, not in the C styleType Id
Beta Was this translation helpful? Give feedback.
All reactions