[antlr-interest] [C Target][3.1.3] Parser crashes when looking up a scoped attribute outside of a scope context.
register
register72 at gmail.com
Wed Jun 3 07:53:39 PDT 2009
I noticed that the parser crashes whenever a scoped attribute is referenced
outside of a scope context.
This kind of situation arises when a rule B that is referencing a scoped
attribute defined in a rule A may match on its own without requiring a
previous match to A.
In my specific case the crash occurs because the following code is
generated:
scfSetAttrAsIntRef(curAttr,intRef, (SCOPE_TOP(record))->curRecord);.
Since SCOPE_TOP(record) is null I get an access violation.
One can obviously avoid this problem defining rules that are able to
discriminate between the outside-scope and in-scope invocation of B. However
I see a lot of redundancy in this approach so I propose to modify the
generated code in the following way:
scfSetAttrAsIntRef(curAttr,intRef, (SCOPE_TOP(record))==0 ? 0 :
(SCOPE_TOP(record))->curRecord);
Doing so one has two benefits:
- The code doesn't crash.
- Discrimination between the in-scope and outside-scope invocation can be
detected and handled inside actions.
Greets,
Luca
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090603/bdd21354/attachment.html
More information about the antlr-interest
mailing list