Reputation: 110382
What would be the difference between the following two ways to define a SQL script, which I've come across from a few existing grammar files:
root
: stmtblock EOF
;
stmtblock
: stmtmulti
;
stmtmulti
: (stmt SEMI?)*
;
stmt
: selectstmt // | or others ...
;
And:
root
: stmtmulti EOF
;
stmtmulti
: stmt*
;
stmt
: selectstmt ';' // | or others ...
;
It seems that:
SEMI
is pushed to the container statement, so it wouldn't have to be suffixed to every stmt
alternation.stmtblock : stmtmulti ;
Which of these two versions would be preferable and why?
Upvotes: 0
Views: 53
Reputation: 6785
The main difference is that the first example treats the ‘;’ as optional (and not part of the stmt
context. The second example makes the ‘;’ a necessary part of the stmt
and won’t match the rule without it being present.
Upvotes: 1