Ter--
Indirect execution is a very weak form of polymorphism, and the mechanism you
describe depends on compiler type awareness.
Assume that you have two versions of rule b, defined in separate but included
grammars
b[int foo] : a b c ; // version 1
b returns int : d e f ; // version 2
These have different type signatures; in an OO system, b[int x] would translate
to version 1, and z = b would imply version 2. As you mention, interpretation
depends on the message sent, and part of the message are the data type
expectations.
On another note, ANTLR lacks the data abstractions that go with the OO idea of
inheritance. The mechanism implemented in ANTLR 3 looks much more like
Python's module import facility than it does inheritance.
--Loring
________________________________
From: Terence Parr <[EMAIL PROTECTED]>
To: Loring Craymer <[EMAIL PROTECTED]>
Cc: antlr-interest Interest <[EMAIL PROTECTED]>
Sent: Monday, October 27, 2008 10:49:16 PM
Subject: Re: [antlr-interest] Duplicate members when generating code with 2
import levels in Java with ANTLR-3.1.1
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