[antlr-interest] Help Fixing Alternate Paths Problem

William Koscho wkoscho at gmail.com
Fri Mar 26 12:22:19 PDT 2010


Hi All,

My grammar results in the error:
Decision can match input such as "'component' ID '{' '}'" using multiple
alternatives: 1, 2.

I know the problem, but just am not sure of the best way to fix this.
Ultimately, I'm trying to construct the AST with type information in the
tree nodes, and the type information comes from my java class SymbolTable.
How can I fix this and still get the type info from my SymbolTable class?

Grammar:
elementDef : componentDef  | interfaceDef ;

componentDef  :  ( type ID '{' interfaceRef* '}' )  -> ^(type ID
interfaceRef*);
interfaceDef  :  ( type ID '{' messageDef* '}' ) -> ^(type ID messageDef*);

type returns [Type t]
 : 'component' { $t = (Type)m_symbolTable.resolve("component"); }
 | 'interface' { $t = (Type)m_symbolTable.resolve("interface"); }
 | 'message'   { $t = (Type)m_symbolTable.resolve("message"); } ;

Thanks
Bill


More information about the antlr-interest mailing list