You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a grammar that I recently modified to remove semicolons. There's no need for statement separators now when multiple statements share a line nor is there any need for a continuation token when a statement spans multiple lines.
However it is also doing something I want it to do but I don't understand why!
Consider:
first
dcl data fixed bin(15) based(p) defined = 100
second
dcl data fixed bin(15) based(p) defined
third
dcl data fixed bin(15) based(p) = 100;
fourth
dcl data fixed bin(15) based(p)
Both the based and the defined are optional attributes on a declaration. In first it parses it as a declaration up to and including the based(p) and sees the rest as an assignment to a variable named 'defined'.
In the second it sees it as a declaration with both a based and defined attribute.
In the third it sees it as a declaration up to an including the bin(15) and sees the rest as an assignment to an array member 'based(p)`.
In the fourth it sees it as a declaration with a based attribute.
Before I tested these cased I expected the first and third to fail, being seen as declarations followed by an illegal = 100.
By design this grammar allows identifiers to be the same as keywords, that is keywords are not reserved, FYI.
This seems odd to me, like if I'd asked how to get a grammar to do these things I'd have been told "You can't, that's impossible"...
Is this LL(*) in action? is the parser looking ahead to find a match no matter how far it must look?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a grammar that I recently modified to remove semicolons. There's no need for statement separators now when multiple statements share a line nor is there any need for a continuation token when a statement spans multiple lines.
However it is also doing something I want it to do but I don't understand why!
Consider:
first
second
third
fourth
Both the
based
and thedefined
are optional attributes on a declaration. In first it parses it as a declaration up to and including thebased(p)
and sees the rest as an assignment to a variable named 'defined'.In the second it sees it as a declaration with both a
based
anddefined
attribute.In the third it sees it as a declaration up to an including the
bin(15)
and sees the rest as an assignment to an array member 'based(p)`.In the fourth it sees it as a declaration with a
based
attribute.Before I tested these cased I expected the first and third to fail, being seen as declarations followed by an illegal
= 100
.By design this grammar allows identifiers to be the same as keywords, that is keywords are not reserved, FYI.
This seems odd to me, like if I'd asked how to get a grammar to do these things I'd have been told "You can't, that's impossible"...
Is this LL(*) in action? is the parser looking ahead to find a match no matter how far it must look?
Beta Was this translation helpful? Give feedback.
All reactions