[antlr-interest] Lexer.java output in wrong directory

Martijn Reuvers martijn.reuvers at gmail.com
Sun Sep 13 11:27:59 PDT 2009


I think a configuration says more than spelling it letter by letter. :)
This isthe structure that outputs in nl/test (both lexer and parser):


│   pom.xml
│
├───src
│   └───main
│       ├───antlr3
│       │   └───nl
│       │       └───test
│       │               L.g
│       │               P.g
│       │
│       └───java
└───target
    │   pom-transformed.xml
    │   test-1.0-SNAPSHOT.jar
    │
    ├───classes
    │   └───nl
    │       └───test
    │               L.class
    │               P.class
    │
    ├───generated-sources
    │   └───antlr3
    │       │   L.tokens
    │       │   P.tokens
    │       │
    │       └───nl
    │           └───test
    │                   L.java
    │                   P.java
    │
    └───maven-archiver
            pom.properties

L.g is the lexer and contains:

lexer grammar L;

@header {
  package nl.test;
}

LETTER
  : 'X'
  ;

SMALL_LETTER
  : 'x'
  ;


P.g is the parser and contains:

parser grammar P;

options {
  tokenVocab=L;
}

@header {
  package nl.test;
}

x : SMALL_LETTER LETTER
  ;

Notice the tokenVocab in the parser, that matches the lexer's file
name without extension (in fact its token file name). And both lexer
and parser grammars need to define their package for it to be
generated in the files. The location of the grammar files determines
their output location (you can see in the tree above as I did a maven
run).

Martijn


On Sun, Sep 13, 2009 at 7:29 PM, Hilco Wijbenga
<hilco.wijbenga at gmail.com> wrote:
> 2009/9/13 Martijn Reuvers <martijn.reuvers at gmail.com>:
>> Not sure what you want with the import statement in the parser, but I
>> assume you just want to just use the lexer grammar as input for your
>> parser grammar, then you should use:
>
> Yep, I'm just trying to break up the grammar into smaller pieces.
>
>> L.g
>>
>> @header {
>>  package x;
>> }
>>
>>
>> X.g:
>>
>> options {
>>    tokenVocab=X;
>> }
>>
>> @header {
>>  package x;
>> }
>
> I'm probably not understanding you correctly but I can't get this to
> even compile. I've tried some variations of what you listed above
> ("tokenVocab = L;"; with the import statement and without; with L.g in
> x instead of imports) but none of it works. And in the cases where it
> does output something, the lexer is still in the wrong directory.
>
> Could you spell it out for me? :-) What should L.g say and where
> should it be located? What should X.g say? Did you actually run it?
>
> Cheers,
> Hilco
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


More information about the antlr-interest mailing list