[antlr-interest] Cannot find symbol?

Jones, Keith kpj1 at wustl.edu
Fri Mar 9 13:10:06 PST 2012


I'm testing a simple grammar I've written, but for some reason when I try to run it through the debugger it fails to compile, giving me multiple "Cannot find symbol" errors. Is it a problem with my syntax or what? Here are the relevant portions:

min    returns [String result]

@init {
    List<String> names = new ArrayList<String>();
    result = "";
}:

    col=COLUMN { $names.add($col); }
        (COMMA col=COLUMN {$names.add($col);} )+
        {$result = $names.get(0);
        for (int i = 0; i < names.size; i++) {
            if ($result.compareToIgnoreCase(names.get(i)) < 0)
                $result = names.get(i);
        }};


COLUMN returns [String name]

@init {
    name = "";
}:
    OPENPAREN (c=COLUMNNAME {$name = c.text();}) CLOSEPAREN;


COLUMNNAME    :    ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
    ;


These give me the following errors when I attempt to run the debugger:

[15:05:56] cannot find symbol
[15:05:56] symbol  : variable $names
[15:05:56] location: class autocompleteParser
[15:05:56]              $names.add(col);
[15:05:56]              ^
[15:05:56] cannot find symbol
[15:05:56] symbol  : variable $names
[15:05:56] location: class autocompleteParser
[15:05:56]                     $names.add(col);
[15:05:56]                     ^
[15:05:56] cannot find symbol
[15:05:56] symbol  : variable $names
[15:05:56] location: class autocompleteParser
[15:05:56]             result = $names.get(0);
[15:05:56]                      ^
[15:05:56] cannot find symbol
[15:05:56] symbol  : method text()
[15:05:56] location: class org.antlr.runtime.CommonToken
[15:05:56]             name = c.text();
[15:05:56]                     ^

Why is this happening? I've stuck as closely to the provided examples as I could.

Any help would be greatly appreciated!


More information about the antlr-interest mailing list