dcsimg
Conditional parsing
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   xiehao74
Posted On:   Thursday, March 21, 2013 01:49 PM

I have a sum function as follows: sumFunction returns [double value] : 'sum' '(i=' startIndex=Integer ';' endIndex=Integer ';' step=Integer ')' e=expression {value=Evaluation.sumExpression($startIndex.value, $endIndex.value, $step.value, $e.value);} ; My problem is: when startIndex>endIndex and step>0, this sum function should return 0.0. However, Antlr parser continue parse the "e=expression" portion. The result is that sometimes the parsing of "e=expression" return error because startIndex is outside the range. Do you think I can check the condition of startIndex, endIndex, and step first? If condition is true, parse the "e=expression". Otherwise skip "e=e   More>>

I have a sum function as follows:

sumFunction returns [double value] :
'sum' '(i=' startIndex=Integer ';' endIndex=Integer ';' step=Integer ')' e=expression
{value=Evaluation.sumExpression($startIndex.value, $endIndex.value, $step.value, $e.value);}
;


My problem is: when startIndex>endIndex and step>0, this sum function should return 0.0. However, Antlr parser continue parse the "e=expression" portion. The result is that sometimes the parsing of "e=expression" return error because startIndex is outside the range.

Do you think I can check the condition of startIndex, endIndex, and step first? If condition is true, parse the "e=expression". Otherwise skip "e=expression".

   <<Less
About | Sitemap | Contact