On Oct 27, 2008, at 9:50 PM, Loring Craymer wrote:
> Ter
>
> Interesting. I thought that you just imported the production
> methods, but if you truly support polymorphism, then rules are
> imported not just on the basis of their names but on their
> signatures as well. Somehow I missed that in the code.
>
> Are you sure that grammar composition does not look more like module
> importation?
Well, not sure what you call it but manual explains it as:
> Rules in delegate grammars that reference rules overridden in a
> delegator reference the overridden rule. This is identical to the
> rules for overridden methods in an object oriented programming
> language.
>
Here is a unit test. Now that i look at it, it sucks but it does
indicate that it matches "c" via S.a then M.b from M. S.b does not
match 'c' (or anything actually).
public void testDelegatorRuleOverridesDelegate() throws Exception {
String slave =
"parser grammar S;\n" +
"a : b {System.out.println(\"S.a\");} ;\n" +
"b : B ;\n" ;
mkdir(tmpdir);
writeFile(tmpdir, "S.g", slave);
String master =
"grammar M;\n" +
"import S;\n" +
"b : 'b'|'c' ;\n" +
"WS : (' '|'\\n') {skip();} ;\n" ;
String found = execParser("M.g", master, "MParser", "MLexer",
"a", "c", debug);
assertEquals("S.a\n", found);
}
So if you have an S parser, a invokes S.b. BUT, if you import S into
M and then invoke 'a' from M, you get S.a calling S.b. It's using
delegate pointers. Basically M defines
a() { gS.a(); }
and S defines:
b() { gParent.b(); }
if I remember. So, it behaves as you'd expect: "the receiver, M,
decides how to answer message b". If I'm an S, a calls S.b. If I'm
an M, a calls M.b. the gS and gParent act sort of like a vtable I
think.
Ter
--~--~---------~--~----~------------~-------~--~----~
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:8080/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address