[antlr-interest] few beginner questions

Jonne Zutt jonne.zutt.ml at gmail.com
Tue Sep 27 13:06:22 PDT 2011


Ok, it seems http://www.antlr.org/wiki/pages/viewpage.action?pageId=1741
answers my first question. But I came up with the following identifier
rules,
which seems to work for me:

identifier
  :  DoubleQuote ~(DoubleQuote)+ DoubleQuote
  ;

On Tue, Sep 27, 2011 at 8:42 PM, Jonne Zutt <jonne.zutt.ml at gmail.com> wrote:

> 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.
>
>
>
>
>


More information about the antlr-interest mailing list