[antlr-interest] AntLRWorks Rule Debugging Error

Rahul Mehta rah_mehta at yahoo.com
Tue Mar 9 14:11:40 PST 2010


I am trying to test "whenDescriptor" rule in following grammar 
in AntLRWorks. I keep getting following exception as soon as I start 
debugging. Input text for testing is "when order : OrderBll then"

[16:45:07] C:\Documents and Settings\RM\My Documents\My 
Tools\AntLRWorks\output\__Test__.java:14: cannot find symbol
[16:45:07] symbol  : method whenDescriptor()
[16:45:07] location: class 
RulesTranslatorParser
[16:45:07]             g.whenDescriptor();
[16:45:07]              ^
[16:45:07] 1 error

I am able to test "packageDescriptor" 
and "declareDescriptor" successfully. Does anyone knows resolution to 
the error message? I tried various combination of input string but rule debugging fails.

Here is my grammar.

grammar RulesTranslator;

options
{
    
backtrack=true;
    memoize=true;
    language=CSharp2;
}

tokens {
    AND='and';
    OR='or';
    NOT='not';
    
EXISTS='exists';
    EVAL='eval';
    FORALL='forall';
    
CONTAINS='contains';
    IS='is';
    INSTANCEOF='instanceof';
    STRSIM='strsim';
    SOUNDSLIKE='soundslike';
    IN='in';
    NEW='new';
    WITH='with';
    ASSERT='assert';
    
ISDEF='isdef';
}

packageDescriptor
    : 'package' 
qualifiedName
    ;
    
declareDescriptorList
    : (declareDescriptor)*
    ;
    
declareDescriptor
    : 'declare' qualifiedName 
(variableDef)+ 'end'
    ;
    
whenDescriptor
    : 
//'when' ( typeRef | NOT ) (parExpression)+ 'then'
     'when' 
typeRef  'then'
    ;
    
typeRef
    :  (Identifier | 
variableDef)
    ;

primitiveType
    :   'boolean'
    
|    'char'
    |    'byte'
    |    'short'
    |    'int'
    |    'long'
    |    'float'
    |    'double'
    ;

qualifiedNameList
    : qualifiedName 
(',' qualifiedName)*
    ;
        
qualifiedName
    : 
Identifier ('.' Identifier)*
    ;
    
literal    
    : 
integerLiteral
    | FloatingPointLiteral
    | CharacterLiteral
    | StringLiteral
    | booleanLiteral
    | 'null'
    ;

integerLiteral
    :   HexLiteral
    |   OctalLiteral
    |   DecimalLiteral
    ;

booleanLiteral
    :   'true'
    |   'false'
    ;
    
elementValuePairs
    : elementValuePair (',' elementValuePair)*
    ;
    
elementValuePair
    : (Identifier '=')? 
conditionalExpression
    ;
            
variableDef    
    : ( Identifier ':' Identifier | Identifier ':' qualifiedName ) 
    ;

// STATEMENTS / BLOCKS    
chunk : (statement (';')?)*
    ;

block : chunk EOF;
        
statement
    : 'while' parExpression 
statement
        | 'do' statement 'while' parExpression ';'
    
    | 'switch' parExpression '{' switchBlockStatementGroups '}'
    
    | 'return' expression? ';'
        | 'break' Identifier? ';'
        | 'continue' Identifier? ';'
        //| 'when' parExpression 'then' (statement)? 'end'
        |  
statementExpression
        |  Identifier ':' statement
    ;
        
switchBlockStatementGroups
    :   
(switchBlockStatementGroup)*
    ;
    
switchBlockStatementGroup
    :   switchLabel statement*
    ;
    
switchLabel
    :  
'case' constantExpression ':'
    |  'default' ':'
    ;
    
moreStatementExpressions
    :  (',' statementExpression)*
    ;
        
fieldseperator 
    : (',' | ';')
    ;
    
logicalOperator
     : ('&&' | '||' | '~=') 
    ;
    
parExpression
    :   '(' expression ')'
    ;
    
expressionList
        
:   expression (',' expression)*
        ;

statementExpression
    :   expression
    ;
    
constantExpression
    :   
expression
    ;
    
expression
    :   
conditionalExpression (assignmentOperator expression)?
    ;
    
assignmentOperator
    :   '='
    |   '+='
    |   '-='
    |   '*='
    |   '/='
    |   '&='
    |   '|='
    |   '^='
    |   '%='
    |   '<' '<' '='
    |   '>' 
'>' '='
    |   '>' '>' '>' '='
    ;
    
conditionalExpression
    :   conditionalOrExpression ( '?' expression ':' expression )?
    ;

conditionalOrExpression
    :   conditionalAndExpression ( ( '||' | OR ) conditionalAndExpression 
)*
    ;

conditionalAndExpression
    :   inclusiveOrExpression ( ( 
'&&' | AND ) inclusiveOrExpression )*
    ;

inclusiveOrExpression
    :   exclusiveOrExpression ( '|' exclusiveOrExpression )*
    ;

exclusiveOrExpression
    :   andExpression ( '^' andExpression )*
    ;

andExpression
    :   equalityExpression ( '&' equalityExpression )*
    ;

equalityExpression
    :   relationalExpression ( ('==' | '!=') relationalExpression )*
    ;

relationalExpression
    :   shiftExpression ( relationalOp shiftExpression )*
    ;
    
relationalOp
    :    ('<' '=' | '>' '=' | '<' | '>')
    ;

shiftExpression
    :   additiveExpression ( shiftOp additiveExpression )*
    ;

shiftOp
    :   
('<' '<' | '>' '>' '>' | '>' '>')
    ;

additiveExpression
        :   multiplicativeExpression ( ('+' | '-') multiplicativeExpression )*
    ;

multiplicativeExpression
        :   
unaryExpression ( ( '*' | '/' | '%' ) unaryExpression )*
    ;
    
unaryExpression
    :   '+' unaryExpression
    |    '-' 
unaryExpression
    |   '++' primary
    |   '--' primary
    
|   unaryExpressionNotPlusMinus
    ;

unaryExpressionNotPlusMinus
    :   '~' unaryExpression
    |     ( '!' | NOT ) unaryExpression
    |   castExpression
    ;

castExpression
    :  '(' 
primitiveType ')' unaryExpression
    |  '(' expression ')' 
unaryExpressionNotPlusMinus
    ;

primary
    :    
parExpression
    |   literal
    ;
        
// Lexar    
HexLiteral : '0' ('x'|'X') HexDigit+ IntegerTypeSuffix? ;

DecimalLiteral : 
('0' | '1'..'9' '0'..'9'*) IntegerTypeSuffix? ;

OctalLiteral : 
'0' ('0'..'7')+ IntegerTypeSuffix? ;

fragment
HexDigit : 
('0'..'9'|'a'..'f'|'A'..'F') ;

fragment
IntegerTypeSuffix : ('l'|'L') ;

FloatingPointLiteral
    : ('0'..'9')+ '.' ('0'..'9')* Exponent? FloatTypeSuffix?
    | '.' 
('0'..'9')+ Exponent? FloatTypeSuffix?
    ;

fragment
Exponent : ('e'|'E') ('+'|'-')? ('0'..'9')+ ;

fragment
FloatTypeSuffix : ('f'|'F'|'d'|'D') ;

CharacterLiteral
    :   '\'' ( 
EscapeSequence | ~('\''|'\\') ) '\''
    ;

StringLiteral
    :  '"' ( EscapeSequence | ~('\\'|'"') )* '"'
    ;

fragment
EscapeSequence
    :   '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
    |   UnicodeEscape
    |   OctalEscape
    ;
    
fragment
OctalEscape
    :   
'\\' ('0'..'3') ('0'..'7') ('0'..'7')
    |   '\\' ('0'..'7') ('0'..'7')
    |   '\\' 
('0'..'7')
    ;

fragment
UnicodeEscape
    :   '\\' 'u' HexDigit HexDigit HexDigit HexDigit
    ;

Identifier 
    
    :   IdentifierStart (IdentifierStart|IdentifierPart)*
        ;

fragment
IdentifierStart
    :  '\u0024' |
       '\u0041'..'\u005a' |
       '\u005f' |
       '\u0061'..'\u007a' |
       '\u00c0'..'\u00d6' |
       
'\u00d8'..'\u00f6' |
       '\u00f8'..'\u00ff' |
       
'\u0100'..'\u1fff' |
       '\u3040'..'\u318f' |
       '\u3300'..'\u337f' |
       '\u3400'..'\u3d2d' |
       '\u4e00'..'\u9fff' |
       
'\uf900'..'\ufaff'
    ;

fragment
IdentifierPart
    :  
'\u0030'..'\u0039' |
       '\u0660'..'\u0669' |
       
'\u06f0'..'\u06f9' |
       '\u0966'..'\u096f' |
       
'\u09e6'..'\u09ef' |
       '\u0a66'..'\u0a6f' |
       
'\u0ae6'..'\u0aef' |
       '\u0b66'..'\u0b6f' |
       
'\u0be7'..'\u0bef' |
       '\u0c66'..'\u0c6f' |
       '\u0ce6'..'\u0cef' |
       '\u0d66'..'\u0d6f' |
       '\u0e50'..'\u0e59' |
       '\u0ed0'..'\u0ed9' |
       
'\u1040'..'\u1049' 
    |   '\uff10'..'\uff19'
   ;

WS  :  
(' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;}
    ;

COMMENT
    :   '/*' ( options {greedy=false;} : . )* '*/' {$channel=HIDDEN;}
    ;

LINE_COMMENT
    : '//' ~('\n'|'\r')* '\r'? '\n' 
{$channel=HIDDEN;}
    ;

NEWLINE    : ('\r')? '\n' {skip();}
    ;

Thanks,

Rahul



      


More information about the antlr-interest mailing list