[antlr-interest] Indirect recursive grammar(A->B; B->C; C->A)

Manas manas_482002 at yahoo.co.in
Sun Oct 7 04:58:01 PDT 2007


hi.
  I am developing a parser for OCL expressions. While generating java code, ANTLRWorks gave an error for indirect recursive grammar. Same grammar is supported by YACC. Is there any method by which this can be resolved. Here is the grammar I have written.
  Manas
   
   
  grammar ocl;
   
  expressionInOclCS : oclExpressionCS;
   
  
  oclExpressionCS 
  : propertyCallExpCS
  | variableExpCS
  | literalExpCS
  | letExpCS
  | oclMessageExpCS
  | ifExpCS
  ;
  
   
  variableExpCS
  : simpleNameCS
  ; 
   
  simpleNameCS
  : VARSTRING
  ;
  
   
  pathNameCS
  : simpleNameCS('::' pathNameCS)?
  ;
   
  literalExpCS 
  : enumLiteralExpCS
  | collectionLiteralExpCS
  | tupleLiteralExpCS
  | primitiveLiteralExpCS
  ;
  
   
  enumLiteralExpCS
  : pathNameCS '::' simpleNameCS
  ;
  
   
  collectionLiteralExpCS
  : collectionTypeIdentifierCS '{' collectionLiteralPartsCS? '}'
  ; 
  
  
  
   
  collectionTypeIdentifierCS
  : 'Set'
  | 'Bag'
  | 'Sequence'
  | 'Collection'
  | 'OrderedSet'
  ;
  
   
  collectionLiteralPartsCS
  : collectionLiteralPartsCS (',' collectionLiteralPartsCS )?
  ;
  
   
  primitiveLiteralExpCS
  : integerLiteralExpCS
  | realLiteralExpCS
  | stringLiteralExpCS
  | booleanLiteralExpCS
  ;
  
   
  tupleLiteralExpCS
  : 'Tuple' '{' variableDeclarationListCS '}'
  ;
  
   
  integerLiteralExpCS
  : INTEGER
  ;
  
   
  realLiteralExpCS
  : REAL
  ;
  
   
  stringLiteralExpCS
  : STRING
  ;
   
  booleanLiteralExpCS
  : BOOLEAN
  ;
   
  variableDeclarationCS
  : simpleNameCS(':' typeCS)?('=' oclExpressionCS)?
  ;
  
  
   
  propertyCallExpCS
  : modelPropertyCallExpCS
  | loopExpCS
  ;
  
   
  loopExpCS
  : iteratorExpCS
  | iterateExpCS
  ;
  
   
  iteratorExpCS
  : oclExpressionCS '->' simpleNameCS '(' (variableDeclarationCS (',' variableDeclarationCS)? '|')?
  oclExpressionCS ')'
  | oclExpressionCS '.' simpleNameCS '(' argumentsCS? ')'
  | oclExpressionCS '.' simpleNameCS
  | oclExpressionCS '.' simpleNameCS ('[' argumentsCS ']')?
  ;
   
  
  iterateExpCS
  : oclExpressionCS '-> ' 'iterate' '('(variableDeclarationCS ';')?
  variableDeclarationCS'|'
  oclExpressionCS')'
  ;
   
  typeCS : pathNameCS
  | collectionTypeCS
  | tupleTypeCS;
  collectionTypeCS
  : collectionTypeIdentifierCS '(' typeCS ')'
  ;
  
   
  tupleTypeCS
  : 'Tuple' '(' variableDeclarationListCS? ')';
  
  variableDeclarationListCS //*********
  : variableDeclarationCS (',' variableDeclarationListCS)?
  ;
   
  modelPropertyCallExpCS
  : operationCallExpCS
  | attributeCallExpCS
  | navigationCallExpCS
  ;
  
   
  operationCallExpCS
  : oclExpressionCS simpleNameCS oclExpressionCS
  | oclExpressionCS '->' simpleNameCS '('argumentsCS? ')'
  | oclExpressionCS '.' simpleNameCS '(' argumentsCS? ')'
  | simpleNameCS '(' argumentsCS? ')'
  | oclExpressionCS '.' simpleNameCS isMarkedPreCS '(' argumentsCS? ')'
  | isMarkedPreCS '(' argumentsCS? ')'
  | pathNameCS '(' argumentsCS? ')'
  | simpleNameCS oclExpressionCS
  ;
   
  attributeCallExpCS
  : oclExpressionCS ',' simpleNameCS isMarkedPreCS?
  | simpleNameCS isMarkedPreCS?
  | pathNameCS
  ;
  
   
  navigationCallExpCS
  : associationEndCallExpCS
  | associationClassCallExpCS
  ;
   
  associationEndCallExpCS
  : oclExpressionCS '.' simpleNameCS('['argumentsCS']')? isMarkedPreCS?
  | simpleNameCS('['argumentsCS']')? isMarkedPreCS?
  ;
  
   
  associationClassCallExpCS
  : oclExpressionCS'.'simpleNameCS('[' argumentsCS']')? isMarkedPreCS?
  | simpleNameCS ('[' argumentsCS']')?isMarkedPreCS?
  ;
  
   
  isMarkedPreCS
  : '@' 'pre'
  ;
  
   
  argumentsCS
  : oclExpressionCS (',' argumentsCS)?//**********
  ;
  
   
  letExpCS: 'let' variableDeclarationCS letExpSubCS
  ; 
  
   
  letExpSubCS
  : ',' variableDeclarationCS letExpSubCS//***********
  | 'in' oclExpressionCS
  ;
  
   
  oclMessageExpCS
  : oclExpressionCS '^^' simpleNameCS '(' oclMessageArgumentsCS? ')'
  | oclExpressionCS '^' simpleNameCS '(' oclMessageArgumentsCS? ')'
  ; 
  
   
  oclMessageArgumentsCS
  : oclMessageArgCS (',' oclMessageArgumentsCS)? //********************
  ;
  
   
  oclMessageArgCS
  : '?'(':'typeCS)?
  | oclExpressionCS
  ;
   
  ifExpCS : 'if' oclExpression
  'then' oclExpression
  'else' oclExpression
  'endif'
  ;
  
   
  oclExpression
  : //To be defined yet
  ;
  
   
  VARSTRING : ('a'..'z'|'A'..'Z') ('0'..'9'|'a'..'z'|'A'..'Z')*
  ;
  INTEGER : ('0'..'9')+
  ;
  REAL : ('0'..'9')*'.'('0'..'9')+
  ;
  STRING : ('a'..'z'|'A'..'Z')+
  ;
  BOOLEAN : 'true'|'false'
  ;
  NEWLINE : '\r'?'\n'
  ;
  WS : (' '|'\t'|'\n'|'\r')+ {skip();}
  ;

       
---------------------------------
 5, 50, 500, 5000 - Store N number of mails in your inbox. Click here.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071007/d938c182/attachment-0001.html 


More information about the antlr-interest mailing list