It looks like you are trying to produce a grammar from some kind of normative 
spec and have made the classic mistake of trying to include context in the 
expression of the grammar. The problem is that such specs are not written for 
writing parsers with but more of an explanation of how things go together in 
general.

 

So, you don't want rules like alphanumerical_expression and so on, you just 
want expression, and you must make your expression rule left factored and 
organized for LL() parsers, not just typed in like below. You can steal the 
expression rule tree from any of the sample grammars (choose one that might be 
close already), such as java or C.

 

Basically though, you are not going to get very far starting from the grammar 
below. What is it you are trying to parse?

 

Jim

 

 

From: [email protected] 
[mailto:[email protected]] On Behalf Of Thomas Dill
Sent: Wednesday, November 04, 2009 8:33 AM
To: [email protected]
Subject: [antlr-interest] Define "function" as numerical and alphanumerical 
expression

 

Hi!

 

I need help for the following problem:

 

I think the best way to describe it, is to show you what I tried. This produces 
a bunch of errors. 

 

expression                     :    conditional_expression | 
numerical_expression | alphanumerical_expression | function | data_field ;

conditional_expression         :    'IF' arguments 'THEN' value ('ELSE' 
(conditional_expression | value))? ;

arguments                      :    argument  (('OR' | 'AND') argument)* |

'(' arguments ')' ;

Argument                      :    value relational_operator value |

                                    (NOT? value IN) ('(' (SingleStringLiteral | 
NumericLiteral) (COMMA (SingleStringLiteral | NumericLiteral))* ')' | FILE 
OBJNAME)  ;

relational_operator            :    RelOp | alphanumerical_relational_op | 
numerical_relational_op ;

alphanumerical_relational_op   :    ARelOp ;

numerical_relational_op        :    NRelOp numerical_expression  'TO' ;

value                          :    numerical_expression  | 
alphanumerical_expression | function | data_field;

function                       :    FUNCTION function_argument ')';

function_argument              :    (numerical_expression  | 
alphanumerical_expression | function | data_field) (COLON numerical_expression  
| alphanumerical_expression | function | data_field)*;

alphanumerical_expression      :    (SingleStringLiteral) (chrOp 
(SingleStringLiteral))+;

numerical_expression           :    (numExprA) (NumOp (numExprA))+ |

'('numerical_expression  ')' ;

numExprA                       :    NumericLiteral; 

data_field                     :    PREOP? PREFIX? OBJNAME

 

PREOP                          :     
('AVE'|'MAX'|'MIN'|'FST'|'TOT'|'CNT'|'SUM'|'ALL'|'ST'|'CT'|'ASQ'|'PCT'|'RPCT'|'SEG'|'DST')'.';
     

PREFIX                         :    OBJNAME '.';    

FUNCTION                       :    OBJNAME '(';

OBJNAME                        :    ('A'..'Z') ('A'..'Z'|'0'..'9'|'_')*;

NumOp                          :    '**' | '*' | '+' | '-' | '/' | 'AND' | 
'OR';     

ChrOp                          :    '|' | '||' ;

RelOp                         :     
'EQ'|'IS'|'ISNOT'|'ISFROM'|'EXCEEDS'|'NE'|'GE'|'GT'|'LT'|'LE'|'IS 
MISSING'|'ISNOT MISSING'  ;

NRelOp                         :    'FROM'|'ISFROM'|'NOTFROM';

ARelOp                         :    
'CONTAINS'|'OMITS'|'INCLUDES'|'EXCLUDES'|'NOT LIKE'|'LIKE';

fragment StringLiteral         :    '"' ~('"')* '"' | SingleStringLiteral ;

SingleStringLiteral            :    '\'' ~('\'')* '\''   ;

NumericLiteral                 :    DecimalLiteral | IntegerLiteral ;

fragment IntegerLiteral        :    DecimalDigit+;

fragment DecimalLiteral        :    DecimalDigit+ '.' DecimalDigit* | '.' 
DecimalDigit+ ;

fragment DecimalDigit          :    ('0'..'9') ;

 

I really don't know how to describe the problem but I urgently need some help.

 

Best regards,

Tom




--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

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

Reply via email to