[antlr-interest] Use of multimap in grammar file.

Alfredo Perez J. xentastic at gmail.com
Wed Jan 26 08:21:43 PST 2011


I am trying to make a not too complicated translator using ANTLR, the
aproach I'm taking makes use of Multimaps in the grammar file.
However I'm having some trouble initializing them, here's how I do it:

grammar FSM;

options {output=template;}

@header {
import org.antlr.stringtemplate.*;
import org.antlr.misc.MultiMap;

   Multimap <Integer, String> CMap;
   Multimap <Integer, String> UMap;

@init {
  $model::UMap = HashMultimap.create();
  $model::CMap = HashMultimap.create();


  -> RewriteRule


When I try to debug that in ANTLWorks, or try to build project in NetBeans I
get the following error:

error(104):  cannot find an attribute name in attribute declaration
java.lang.StringIndexOutOfBoundsException: String index out of range: -1

Which seems to be a problem with the angled brackets or something. Because
If I comment out /*Multimap <Integer, String> CMap*/ the error goes away.
What would be a correct way to initialize a Multimap visible to that scope?

For your time, thank you.

 - APJ

More information about the antlr-interest mailing list