[antlr-interest] ArrayIndexOutOfBoundsException while generating code in v3
John Goering
johnstephi at googlemail.com
Sun Sep 24 23:23:59 PDT 2006
Hi there,
Thanks, here's the grammar (as far as I got when I noticed I could generate
code with it). Please note that I'm still extremely wet behind the ears in
regards to the whole thing. ;)
Thanks in advance for any help...
John
--------------------------
grammar mygrammar;
formula : (statement (SEMI | EOF))*
;
statement
:
'if' parExpression 'then' statement
| 'for' forInit 'to' expression ('step' expression)? 'do' statement
| 'while' parExpression statement
| 'do' statement 'while' parExpression ';'
| ';'
| statementExpression ';'
;
block
: '(' (statement)* ')'
;
forInit
: variableDeclarator
;
variableDeclarator
: Identifier assignmentOperator expression
;
localVariableDeclaration
: variableDeclarator ';'
;
forUpdate
: expressionList
;
expression
: conditionalOrExpression (assignmentOperator
conditionalOrExpression)?
;
type
: primitiveType ('array' | 'range')*
;
primitiveType
: 'booleanvar'
| 'numbervar'
| 'stringvar'
| 'datevar'
| 'datetimevar'
;
assignmentOperator
: ':='
;
conditionalOrExpression
: conditionalAndExpression ( 'or' conditionalAndExpression )*
;
conditionalAndExpression
: relationalExpression ( 'and' relationalExpression )*
;
relationalExpression
: additiveExpression ( relationalOp additiveExpression )*
;
relationalOp
: ('<' '=' | '>' '=' | '<' | '>' | '=')
;
additiveExpression
: multiplicativeExpression ( ('+' | '-') multiplicativeExpression )*
;
multiplicativeExpression
: unaryExpression ( ( '*' | '/' ) unaryExpression )*
;
unaryExpression
: '+' unaryExpression
| '-' unaryExpression
| primary
;
primary
: Identifier (arguments)?
| primitiveType Identifier
| parExpression
| literal
| field
;
field : '{' (~'}')+ '}'
;
parExpression
: '(' expression ')'
;
literal
: DecimalLiteral
| FloatingPointLiteral
| CharacterLiteral
| StringLiteral
| booleanLiteral
| 'null'
;
booleanLiteral
: 'true'
| 'false'
;
stringliteral
: '"' (~'"')* '"'
;
expressionList
: expression (',' expression)*
;
statementExpression
: expression
;
constantExpression
: expression
;
arguments
: '(' expressionList? ')'
;
ID : ('a'..'z' | 'A'..'Z')+
;
CharacterLiteral
: '\'' ( EscapeSequence | ~('\''|'\\') ) '\''
;
DecimalLiteral : ('0' | '1'..'9' '0'..'9'*);
FloatingPointLiteral
: ('0'..'9')+ '.' ('0'..'9')*
| '.' ('0'..'9')+
;
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
: Letter (Letter|JavaIDDigit)*
;
fragment
HexDigit : ('0'..'9'|'a'..'f'|'A'..'F') ;
fragment
Letter
: 'A'..'Z'|'a'..'z'
;
fragment
JavaIDDigit
: '0'..'9'
;
SEMI : ';';
WS : ( ' '
| '\t'
| '\r'
| '\n'
)+
{ channel=99; }
;
On 9/24/06, Kay Roepke <kroepke at classdump.org> wrote:
>
> Hi John!
>
> On 22. Sep 2006, at 16:42 Uhr, John Goering wrote:
>
> > Should I send the grammar as well, am I doing something wrong, or
> > is this a
> > known problem?
>
> I don't think it is a known problem. Please send the grammar, there
> seems to be deeper issue somewhere.
>
> cheers,
> -k
>
>
>
>
>
--
"I love deadlines. I like the whooshing sound they make as they fly by." -
Douglas Adams
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060925/ce7107f5/attachment.html
More information about the antlr-interest
mailing list