[antlr-interest] code too large error

Jared Bunting jared.bunting at peachjean.com
Tue Dec 30 22:08:02 PST 2008


Hello All,

I am currently working on a parser for a language with predefined 
specifications.  Currently, for my "operation" rule, I am getting a 
"code too large" error from the compiler in the DFA...I am a bit 
confused by this, and I'm not sure that I understand why the prediction 
is so complicated - is there any way I can make this rule more 
explicit?  From my perspective, there really should be zero prediction 
going on other than what my gated semantic predicates do.

Also, I would note that this is the beginning, and I am using the scoped 
variables because eventually I will be adding essentially user defined 
operations that can defined min and max number of arguments.

And, for anyone not familiar, code too large occurs when a java method 
is to large (i believe the limit is 64k).

Any help or insight would be much appreciated.

Thanks,
Jared


parser grammar MyParser;

options {
  output=AST;
  ASTLabelType=CommonTree;
  tokenVocab=MyLexer;
}

tokens {
  OPERATION_ARGS;
}

@header {
package com.example;
}

expression
    :    operation
    | literal
    ;
   
operation
scope {
  int minArgs;
  int maxArgs;
}
    :    operator
    ( {$operation::maxArgs > 0}?=> limitedArgList
    | {$operation::maxArgs < 0}?=> unlimitedArgList
    )
    ;
   
limitedArgList
scope {
  int argCount;
}
@init {
  $limitedArgList::argCount = 0;
}
    :    ( {$limitedArgList::argCount < $operation::maxArgs}?=> 
expression { $limitedArgList::argCount++; } )*
    {$limitedArgList::argCount >= $operation::minArgs}? -> 
^(OPERATION_ARGS expression*)
    ;
   
unlimitedArgList
scope {
  int argCount;
}
@init {
  $unlimitedArgList::argCount = 0;
}
    : (expression { $unlimitedArgList::argCount++; })* argListTerminator
    { $unlimitedArgList::argCount >= $operation::minArgs }? -> 
^(OPERATION_ARGS expression*)
    ;
   
argListTerminator
    :
    {input.LA(1) == EOS}?=> ARG_LIST_TERM?
    | ARG_LIST_TERM
    ;
   
operator
    :    operatorBinary
    | operatorUnary
    | operatorMulti
    ;
   
operatorMulti
@init {
  $operation::minArgs = 1;
  $operation::maxArgs = -1;
}
    :    ALL
    |    ANY
    |    CONCATENATE
    ;

operatorBinary
@init {
  $operation::minArgs = 2;
  $operation::maxArgs = 2;
}
    :    SUM
    |    SUBTRACT
    |    MULTIPLY
    |    DIVIDE
    |    MOD
    |    MAX
    |    MIN
    |    AND
    |    OR
    |    XOR
    |    EQUALS
    |    NOT_EQUALS
    ;

operatorUnary
@init {
  $operation::minArgs = 1;
  $operation::maxArgs = 1;
}
    :    NOT
    | INCREMENT
    | DECREMENT
    ;

literal
    :    STRING
    |    INTEGER
    |    FLOAT
    |    boolean
    ;
   
boolean
     :    TRUE
     | FALSE
    ;
   





More information about the antlr-interest mailing list