Hopefully someone can help me figure out my issue.  I have a fairly 
simple grammar.  If I verify my script using CommonTokenStream, I 
receive a Java heap out of memory exception.  However, if I use the 
ANTLR plugin to test with the same value, I do not receive the exception
 and I see the NoViableAlt exception as expected.

Here is the block I'm verifying:

Action Group 3 Needs Attention
   BranchHours
   Contact A Branch
      Call 1, Ack=Contact, NoConnect=Contact
   EndContact
EndAction

There are two errors with the script above.  The first is the Needs Attention 
text after Action Group 3.  The second is the Branch text after Contact A.  
These were values entered during negative testing that caused the out of memory 
exception.  Yet, if I copy and paste this script into the Eclipse ANTLR 
interpreter and verify I see the NoViableAltException I'm expecting.

Below is the code used to verify the script:
        CharStream charStream = new ANTLRStringStream(script.getScriptText());
        CallingScriptLexer lexer = new CallingScriptLexer(charStream);
        TokenStream tokenStream = new CommonTokenStream(lexer);
        CallingScriptParser parser = new CallingScriptParser(tokenStream);
        VerifiedScriptResponse response = new VerifiedScriptResponse(script);
        
        try
        {
            parser.callingScript();
            if (!parser.success) {
                response.setValid(false);
                
response.setValidationErrors((ValidationError[])parser.errors.toArray(new 
ValidationError[0]));                
            } else {
                response.setValid(true);
            }
        }
        catch (RecognitionException regExc)
        {
            response.setValid(false);
            ValidationError[] parseException = new ValidationError[1];
            parseException[0].setDescription(regExc.getMessage());
            parseException[0].setLineNumber(regExc.line);
            parseException[0].setCharacterPosition(regExc.charPositionInLine);
            parseException[0].setExcerpt(regExc.getCause().getMessage());
            response.setValidationErrors(parseException);
        }
        catch (Exception exc)
        {
            response.setValid(false);
            ValidationError[] parseException = new ValidationError[1];          
  
            parseException[0].setDescription(exc.getMessage());
            response.setValidationErrors(parseException);
        }
        
        return response;
 

And finally the grammar is below.  Any help would be greatly appreciated.

grammar CallingScript;

options {
  language = Java;
}

@header {
    package 
com.ncr.project24.scriptlanguagebusiness.server.antlr.antlrgenerated;
     import com.ncr.project24.scriptlanguagebusiness.server.antlr.evaluators.*;
     import com.ncr.project24.iincidentdata.dto.server.script.*;     
    
 import java.util.Vector;
}

@lexer::header {
     package 
com.ncr.project24.scriptlanguagebusiness.server.antlr.antlrgenerated;
     import com.ncr.project24.scriptlanguagebusiness.server.antlr.evaluators.*;
     import com.ncr.project24.iincidentdata.dto.server.script.*;     
     import java.util.Vector;     
}

@members {
    public boolean success = true;
    public Vector<ValidationError> errors = new Vector<ValidationError>();
    
    protected void AddError(RecognitionException exc)
    {
        success = false;
        String[] tokenNames = this.getTokenNames();
        String errorMessage =
 this.getErrorMessage(exc, tokenNames);
        
        ValidationError _valError = new ValidationError(); 
        _valError.setDescription(errorMessage);
        errors.add(_valError);        
    }
    
    protected void Evaluate(Evaluator eval, int line, int pos, String text)
    {
        try
        {
            ValidationError _valError = eval.evaluate();
            String _errDescription = _valError.getDescription();
              if (_errDescription.length() > 0) {
   
               success = false;
                  _valError.setLineNumber(line);
                  _valError.setCharacterPosition(pos);
                  _valError.setExcerpt(text);
                  errors.add(_valError);
              }        
        }
        catch (Exception exc)
        {
            success = false;
            ValidationError _valError =
 new ValidationError();
            _valError.setDescription(exc.getMessage());
            errors.add(_valError);
        }
    }
}    
callingScript
    :    actionGroupBlock+
    ;
    catch [RecognitionException ex] {
        AddError(ex);     
    }

actionGroupBlock
    :    ACTION GROUP INTEGER            
            hoursStatement+ 
            contactBlock+
        ENDACTION
    ;
    catch
 [RecognitionException ex] {
        AddError(ex);     
    }
    
contactBlock
    :    CONTACT NUMIDENT
            callStatement+
        ENDCONTACT
    ;
    catch [RecognitionException ex] {
        AddError(ex); 
    }
    
callStatement
   
 :    CALL i1=INTEGER ((',' ACK '=' CONTACT ',' NOCONNECT '=' 
CONTACT)|(',' ACK '=' t1=(INTEGERPIPETIME | TIME | TIMETICKS) ',' 
NOCONNECT '=' t2=(INTEGERPIPETIME | TIME | TIMETICKS)))?
        {
            Evaluator eval = new TimeTicksEvaluator($t1.text);
   
         Evaluate(eval, $t1.line, $t1.pos, $t1.text);
              eval = new TimeTicksEvaluator($t2.text);
            Evaluate(eval, $t2.line, $t2.pos, $t2.text);
            eval = new CallStatementEvaluator($i1.text);
            Evaluate(eval, $i1.line, $i1.pos, $i1.text); 
        }
    ;
    catch [RecognitionException ex] {
        AddError(ex);     
    }
        
hoursStatement
    :    BRANCHHOURS
    |    AFTERHOURS
    |   
 OTHERHOURS
    |    PEAKHOURS
    |    OFFPEAKHOURS
    |    hoursRange
    |    hoursHoliday        
    ;
    catch [RecognitionException ex] {
        AddError(ex);     
    }
        
hoursRange
    :    HOURSLITERAL dayRange '('t1=TIME '-' t2=TIME ')'
        {
            Evaluator eval = new TimeEvaluator($t1.text);
            Evaluate(eval, $t1.line, $t1.pos, $t1.text);
            eval = new TimeEvaluator($t2.text);
   
         Evaluate(eval, $t2.line, $t2.pos, $t2.text);
            eval = new TimeRangeEvaluator($t1.text, $t2.text);
            Evaluate(eval, $t1.line, $t1.pos, $t1.text + '-' + $t2.text);
        }        
    ;
    catch [RecognitionException ex] {
        AddError(ex);     
    }
    
hoursHoliday
    :    HOURSLITERAL INTEGER
    ;
    catch [RecognitionException ex] {
        AddError(ex);     
    }
    
numericRange
    :    i1=INTEGER ((',' |
 '-') i2=INTEGER)*
        {
            Evaluator eval = new ActionCodeEvaluator($i1.text);
            Evaluate(eval, $i1.line, $i1.pos, $i1.text);
            
            eval = new ActionCodeEvaluator($i2.text);
            Evaluate(eval, $i2.line, $i2.pos, $i2.text);
        }
    ;
    catch [RecognitionException ex] {
        AddError(ex);     
    }
        
dayRange
    :    DAYIDENT ((',' | '-') DAYIDENT)*
    ;
    catch
 [RecognitionException ex] {
        AddError(ex);     
    }
    
relation
    : ('=' | '!=' | '<' | '<=' | '>=' | '>')
    ;
    catch [RecognitionException ex] {
        AddError(ex);     
    }
    
AND: ('a' | 'A')('n' | 'N')('d' | 'D');
OR: ('o' | 'O')('r' | 'R');
MATHEMATICAL: (AND | OR | '*' | '/' | '+' | '-');
ACTION: ('a' | 'A')('c' | 'C')('t' | 'T')('i' | 'I')('o' | 'O')('n' | 'N');
GROUP: ('g' | 'G')('r' | 'R')('o' | 'O')('u' | 'U')('p' | 'P');
END: ('e' | 'E')('n' | 'N')('d' | 'D');
ENDACTION: END ACTION;
BRANCH: ('b' | 'B')('r' | 'R')('a' | 'A')('n' | 'N')('c' | 'C')('h' | 'H');
AFTER: ('a' | 'A')('f' | 'F')('t' | 'T')('e' | 'E')('r' | 'R');
OTHER: ('o' | 'O')('t' |
 'T')('h' | 'H')('e' | 'E')('r' | 'R');
PEAK: ('p' | 'P')('e' | 'E')('a' | 'A')('k' | 'K');
OFFPEAK: ('o' | 'O')('f' | 'F')('f' | 'F')PEAK;
HOURSLITERAL: ('h' | 'H')('o' | 'O')('u' | 'U')('r' | 'R')('s' | 'S');
CONTACT: ('c' | 'C')('o' | 'O')('n' | 'N')('t' | 'T')('a' | 'A')('c' | 'C')('t' 
| 'T');
CALL: ('c' | 'C')('a' | 'A')('l' | 'L')('l' | 'L');
ACK: ('a' | 'A')('c' | 'C')('k' | 'K');
NOCONNECT: ('n' | 'N')('o' | 'O')('c' | 'C')('o' | 'O')('n' | 'N')('n' | 
'N')('e' | 'E')('c' | 'C')('t' | 'T');
USE: ('u' | 'U')('s' | 'S')('e' | 'E');
SERVICE: ('s' | 'S')('e' | 'E')('r' | 'R')('v' | 'V')('i' | 'I')('c' | 'C')('e' 
| 'E');
TIMER: ('t' | 'T')('i' | 'I')('m' | 'M')('e' | 'E')('r' | 'R');
REPEAT: ('r' | 'R')('e' | 'E')('p' | 'P')('e' | 'E')('a' | 'A')('t' | 'T');
WHEN: ('w' | 'W')('h' | 'H')('e' | 'E')('n' | 'N');
ACKED: ('a' | 'A')('c' | 'C')('k' | 'K')('e' | 'E')('d' | 'D');
ARRIVAL: ('a' | 'A')('r' | 'R')('r' |
 'R')('i' | 'I')('v' | 'V')('a' | 'A')('l' | 'L');
ARRIVED: ('a' | 'A')('r' | 'R')('r' | 'R')('i' | 'I')('v' | 'V')('e' | 'E')('d' 
| 'D');
YES: ('y' | 'Y')('e' | 'E')('s' | 'S');
NO: ('n' | 'N')('o' | 'O');
TRUE: ('t' | 'T')('r' | 'R')('u' | 'U')('e' | 'E');
FALSE: ('f' | 'F')('a' | 'A')('l' | 'L')('s' | 'S')('e' | 'E');
ELAPSED: ('e' | 'E')('l' | 'L')('a' | 'A')('p' | 'P')('s' | 'S')('e' | 'E')('d' 
| 'D');
CLEAR: ('c' | 'C')('l' | 'L')('e' | 'E')('a' | 'A')('r' | 'R');
CLOSED: ('c' | 'C')('l' | 'L')('o' | 'O')('s' | 'S')('e' | 'E')('d' | 'D');
TICKET: ('t' | 'T')('i' | 'I')('c' | 'C')('k' | 'K')('e' | 'E')('t' | 'T');
CANCEL: ('c' | 'C')('a' | 'A')('n' | 'N')('c' | 'C')('e' | 'E')('l' | 'L');
CHANGE: ('c' | 'C')('h' | 'H')('a' | 'A')('n' | 'N')('g' | 'G')('e' | 'E');
GENERATE: ('g' | 'G')('e' | 'E')('n' | 'N')('e' | 'E')('r' | 'R')('a' | 
'A')('t' | 'T')('e' | 'E');
STATUS: ('s' | 'S')('t' | 'T')('a' | 'A')('t' |
 'T')('u' | 'U')('s' | 'S');
CHECK: ('c' | 'C')('h' | 'H')('e' | 'E')('c' | 'C')('k' | 'K');
RESULT: ('r' | 'R')('e' | 'E')('s' | 'S')('u' | 'U')('l' | 'L')('t' | 'T');
IF: ('i' | 'I')('f' | 'F');
ELSE: ('e' | 'E')('l' | 'L')('s' | 'S')('e' | 'E');
DEFERUNTIL: ('d' | 'D')('e' | 'E')('f' | 'F')('e' | 'E')('r' | 'R')('u' | 
'U')('n' | 'N')('t' | 'T')('i' | 'I')('l' | 'L');
CONCURRENT: ('c' | 'C')('o' | 'O')('n' | 'N')('c' | 'C')('u' | 'U')('r' | 
'R')('r' | 'R')('e' | 'E')('n' | 'N')('t' | 'T');
DISPATCHACTION: ('d' | 'D')('i' | 'I')('s' | 'S')('p' | 'P')('a' | 'A')('t' | 
'T')('c' | 'C')('h' | 'H') ACTION;
SITEDISPATCHACTION: ('s' | 'S')('i' | 'I')('t' | 'T')('e' | 'E') '.' 
DISPATCHACTION;
IN: ('i' | 'I')('n' | 'N');
DONE: ('d' | 'D')('o' | 'O')('n' | 'N')('e' | 'E');
ID: ('i' | 'I')('d' | 'D');
HOLD: ('h' | 'H')('o' | 'O')('l' | 'L')('d' | 'D');
INITIATE: ('i' | 'I')('n' | 'N')('i' | 'I')('t' | 'T')('i' | 'I')('a' |
 'A')('t' | 'T')('e' | 'E');
INFO: ('i' | 'I')('n' | 'N')('f' | 'F')('o' | 'O');
SCRIPT: ('s' | 'S')('c' | 'C')('r' | 'R')('i' | 'I')('p' | 'P')('t' | 'T');
COLOR: ('c' | 'C')('o' | 'O')('l' | 'L')('o' | 'O')('r' | 'R');
WAIT: ('w' | 'W')('a' | 'A')('i' | 'I')('t' | 'T');
REEVALUATE: ('r' | 'R')('e' | 'E')('e' | 'E')('v' | 'V')('a' | 'A')('l' | 
'L')('u' | 'U')('a' | 'A')('t' | 'T')('e' | 'E');
DO: ('d' | 'D')('o' | 'O');
COMMAND: ('c' | 'C')('o' | 'O')('m' | 'M')('m' | 'M')('a' | 'A')('n' | 'N')('d' 
| 'D');
OBJECT: ('o' | 'O')('b' | 'B')('j' | 'J')('e' | 'E')('c' | 'C')('t' | 'T');
COUNTER: ('c' | 'C')('o' | 'O')('u' | 'U')('n' | 'N')('t' | 'T')('e' | 'E')('r' 
| 'R');
INCREMENT: ('i' | 'I')('n' | 'N')('c' | 'C')('r' | 'R')('e' | 'E')('m' | 
'M')('e' | 'E')('n' | 'N')('t' | 'T');
STATE: ('s' | 'S')('t' | 'T')('a' | 'A')('t' | 'T')('e' | 'E');
ACTIVATE: ('a' | 'A')('c' | 'C')('t' | 'T')('i' | 'I')('v' | 'V')('a' |
 'A')('t' | 'T')('e' | 'E');
THRESHOLD: ('t' | 'T')('h' | 'H')('r' | 'R')('e' | 'E')('s' | 'S')('h' | 
'H')('o' | 'O')('l' | 'L')('d' | 'D');
DEACTIVATE: ('d' | 'D')('e' | 'E') ACTIVATE;
DECREMENT: ('d' | 'D')('e' | 'E')('c' | 'C')('r' | 'R')('e' | 'E')('m' | 
'M')('e' | 'E')('n' | 'N')('t' | 'T');
WITHIN: ('w' | 'W')('i' | 'I')('t' | 'T')('h' | 'H')('i' | 'I')('n' | 'N');

ACTIONGROUP: ACTION GROUP;
ENDIF: END IF;
CHANGESTATUS: CHANGE STATUS;
CANCELSERVICE: CANCEL SERVICE;
INITIATESERVICE: INITIATE SERVICE;
CHECKSTATUS: CHECK STATUS;
CHECKSTATUSRESULT: CHECKSTATUS '.' RESULT;
COMMANDRESULT: COMMAND '.' RESULT;
OBJECTCOUNTER: OBJECT '.' COUNTER;
OBJECTSTATE: OBJECT '.' STATE;
OBJECTTHRESHOLD: OBJECT '.' THRESHOLD;
GENERATESTATUS: GENERATE STATUS;
ENDWHEN: END WHEN;
ENDTIMER: END TIMER;
ENDSERVICE: END SERVICE;
ENDCONTACT: END CONTACT;
BRANCHHOURS: BRANCH HOURSLITERAL;
AFTERHOURS: AFTER
 HOURSLITERAL;
OTHERHOURS: OTHER HOURSLITERAL;
PEAKHOURS: PEAK HOURSLITERAL;
OFFPEAKHOURS: OFFPEAK HOURSLITERAL;
TICKETCOLOR: TICKET '.' COLOR;
TIME: INTEGER ':' INTEGER;
INTEGERPIPETIME: (INTEGER '|')? TIME; 
TIMETICKS: (INTEGER '|')? TIME ('/' INTEGER)?;
ANDOR: (AND | OR)?;

INTEGER : '0'..'9'+ ;
DAYIDENT: 'n' | 'N' | 'm' | 'M' | 't' | 'T' | 'w' | 'W' | 'r' | 'R' | 'f' | 'F' 
| 's' | 'S';
NUMIDENT: (('0'..'9') | ('A'..'Z') | ('a'..'z') | '*' | '#')+;
WS : (' ' | '\t' | '\n' | '\r' | '\f')+ {$channel = HIDDEN;};
COMMENT : '\'' .* ('\n' | '\r') {$channel = HIDDEN;};


      

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to