Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. rule returns [double value]
  2. : exp=multiplyExp { $value = $exp.value; }
  3. ;
  4.  
  5.  
  6. multiplyExp returns [double value]
  7. : a1=additionExp {$value = $a1.value;}
  8. ( '*' a2=additionExp {$value *= $a2.value;}
  9. | '/' a2=additionExp {$value /= $a2.value;}
  10. )*
  11. ;
  12.  
  13. additionExp returns [double value]
  14. : m1=involutExp {$value = $m1.value;}
  15. ( '+' m2=involutExp {$value += $m2.value;}
  16. | '-' m2=involutExp {$value -= $m2.value;}
  17. )*
  18. ;
  19.  
  20. involutExp returns [double value]
  21. : i1=radicalExp {$value = $i1.value;}
  22. ( '^' i2=radicalExp {$value = Math.pow($value, $i2.value);}
  23. )*
  24. ;
  25.  
  26. radicalExp returns [double value]
  27. : r1=logExp {$value = $r1.value;}
  28. ( 'N' r2=logExp{$value = Math.pow($value, 1.0/$r2.value);}
  29. )*
  30. ;
  31.  
  32. logExp returns [double value]
  33. : l1 = cosPars {$value = $l1.value;}
  34. ( 'log' l2=cosPars{$value=Math.log10($l2.value);}
  35. )*
  36. ;
  37.  
  38. cosPars returns [double value]
  39. :c1 = atomExp {$value = $c1.value;}
  40. ('cos' c2=atomExp {$value=Math.cos($c2.value);})*
  41. ;
  42.  
  43. atomExp returns [double value]
  44. : primaryExp {$value = $primaryExp.value;}
  45. | '(' exp=additionExp ')' {$value = $exp.value;}
  46. ;
  47.  
  48. primaryExp returns [double value]
  49. : Number {$value = Double.parseDouble($Number.text);}
  50. | 'pi' {$value = Math.PI;}
  51. | 'sin' {$value = Math.sin($value);}
  52. ;
  53.  
  54. Number
  55. : ('0'..'9')+ ('.' ('0'..'9')+)?
  56. ;
  57.  
  58. WS
  59. : (' ' | 't' | 'r'| 'n') {$channel=HIDDEN;}
  60. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement