register wrote:
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,

This has been discussed before. It is a bug in your grammar which you can solve in one of a number of ways:

1) The best thing to do would be to move the scope up the rule hierarchy so that you cannot call this rule without a scope in place.
2) Protect the code your self.
3) Use a different rule when the same syntax is parsed

The problem is that if I change the code generated code to check for the scope size being 0, then then only thing that can be returned is NULL anyway, which means you get a different access violation, or an incorrect value because the fact that the stack was accessed incorrectly was masked from you (in fact one of the examples we give out was suffering this problem and it wasn't noticed until the scopes stopped returning NULL if empty). So, instead the code generator does not give you rope to hang yourself with, but expects that you use the scopes correctly.

So, the solution isn't to change teh code generation, but to fix your scope access basically.

Jim

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

Reply via email to