[antlr-interest] [AntlrDT] Q: How do I set token directory?

Austin Hastings Austin_Hastings at Yahoo.com
Wed Aug 20 17:40:55 PDT 2008


Gerald,

It's spelled correctly. ;)

The output directory is working, and the HlasmParser.java, 
HlasmLexer.java, and Hlasm.tokens are all generated correctly.

The Hlasm.g3 file starts out like this:

grammar Hlasm;

options {
    language = Java;
    output = AST;
    ASTLabelType = CommonTree;
}

tokens {
    A_SIMPLE = '=';
//===========================

And the HlasmAST.g3 file starts like this:

tree grammar HlasmAST;

options {
    language = Java;
    output = AST;
    ASTLabelType = CommonTree;
    tokenVocab = Hlasm;
}

@header {
package perl6.hlasm;
}
//==========================


Could it be caused by the .g3 extension?

For whatever reason, I get two copies of the error:

Description    Resource    Path    Location    Type
cannot find tokens file <unset-dir>\Hlasm.tokens    HlasmAST.g3    
hlasm/src/main/antlr/parrot/hlasm    line 2    DLTK Problem
cannot find tokens file <unset-dir>\Hlasm.tokens    HlasmAST.g3    
hlasm/src/main/antlr/parrot/hlasm    line 2    DLTK Problem

The <unset-dir> is bugging me -- that's something right out of Tool.java 
(http://fisheye2.atlassian.com/browse/antlr/src/org/antlr/Tool.java?r=5214  
line 42 in this version).

I notice that the outputDirectory member is protected, and that the 
getOutputDirectory method does a pretty good job of checking for uninit. 
I kind of suspect that you (or someone) may be calling 
getImportedVocabFile(String fname) in the "wrong" order, since it 
returns outputDirectory instead of calling the accessor. (f*****g 
amateurs.) Alternatively, is it possible that you are creating multiple 
instances of the tool, and failing to initialize one of them correctly?

When I cd to the directory that contains the .g3 files, and run Antlr 
directly, I get this:

$ java org.antlr.Tool -o 
../../../../../target/generated-sources/antlr/parrot/hlasm HlasmAST.g3
ANTLR Parser Generator  Version 3.1 (August 12, 2008)  1989-2008
error(210):  The following sets of rules are mutually left-recursive 
[decl_postfix, decl_atom, declarator]

So the grammar isn't perfect, but it should be updating the error window 
with something.

=Austin


Gerald Rosenberg wrote:
> At 09:38 PM 8/17/2008, Austin Hastings wrote:
>> w/ AntlrDT 0.5
>>
>> I've got my output directory set to a relative path 
>> (../../../target/generated-sources/antlr) in 
>> Window>Preferences>AntlrDT, but when I try to build a tree parser, I 
>> am getting this error:
>>
>> cannot find tokens file <unset-dir>\Hlasm.tokens    HlasmAST.g3    
>
> Spelling error?  Note, Antlr will automatically append the ".tokens" 
> extension. 
>
> AntlrDT relies on the "-o" option to set the output directory and 
> expects the relevant .tokens file to be in that same directory.  
> Antlr's Tool#getImportedVocabFile(String vocabName) will look for the 
> named .tokens file in any "-lib" specified directory (not used by 
> AntlrDT) and, if not found, then in the "-o" specified directory.  



More information about the antlr-interest mailing list