[antlr-interest] few beginner questions

Jonne Zutt jonne.zutt.ml at gmail.com
Tue Sep 27 11:42:24 PDT 2011


Dear antlr community,

I have created a minimal project, which illustrates three "challenges" I
currently have.
I attached the source, but hope to make myself clear enough in this email as
well.

*1) How to deal with priorities*?

I have a rule like the below 'operation', where Command1 ('am') can also
occur within the 'identifier' rule.

operation
  :  Command1 Space LowerCase SemiColon
  |  Id Space identifier SemiColon
  ;

Below is the current output. It goes wrong if 'am' is part of the
identifier. I tried to fix this by moving
the order of some rules, but without success.

Running org.myantlr.test.parsers.a.TestATest
test: am e;id "some nice gAme";
--> test passed.
test: am e;id "some nice game";
BR.recoverFromMismatchedToken
MismatchedTokenException(9!=4)
       at org.antlr.runtime.BaseRecognizer.mismatch(BaseRecognizer.java:117)
       at org.antlr.runtime.BaseRecognizer.match(BaseRecognizer.java:99)
       at
org.myantlr.test.parsers.a.TestAParser.identifier(TestAParser.java:81)
       at
org.myantlr.test.parsers.a.TestAParser.operation(TestAParser.java:224)
       at org.myantlr.test.parsers.a.TestAParser.parse(TestAParser.java:155)
       at org.myantlr.test.parsers.a.TestATest.test(TestATest.java:33)
       at org.myantlr.test.parsers.a.TestATest.test2(TestATest.java:19)

*2) grammar hierarchy?*

I read about the import statement in antlr. But I was not successful in
getting these two grammers to import a Base.g.

*3) configure output directory*

After running 'mvn package' all generated sources are in the 'b' package. I
expected TestA files to be generated in the 'a' package.
Is that a bug in the antlr3-maven-plugin, or am I doing something wrong?

./target/generated-sources/antlr/org/myantlr/test/parsers
./target/generated-sources/antlr/org/myantlr/test/parsers/b
./target/generated-sources/antlr/org/myantlr/test/parsers/b/TestA.tokens
./target/generated-sources/antlr/org/myantlr/test/parsers/b/TestA__.g
./target/generated-sources/antlr/org/myantlr/test/parsers/b/TestALexer.java
./target/generated-sources/antlr/org/myantlr/test/parsers/b/TestAParser.java
./target/generated-sources/antlr/org/myantlr/test/parsers/b/TestB.tokens
./target/generated-sources/antlr/org/myantlr/test/parsers/b/TestB__.g
./target/generated-sources/antlr/org/myantlr/test/parsers/b/TestBLexer.java
./target/generated-sources/antlr/org/myantlr/test/parsers/b/TestBParser.java

Thanks,
Jonne.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: my-antlr-test.tgz
Type: application/x-gzip
Size: 1725 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20110927/3dbacfcf/attachment.tgz 


More information about the antlr-interest mailing list