EMSWalker.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. // $ANTLR 3.1 ..\\antlrEMSIV\\src\\EMSWalker.g 2015-12-04 17:45:01
  2. package com.pbsage.parser.emsiv;
  3. import java.util.Map;
  4. import java.util.HashMap;
  5. import org.antlr.runtime.*;
  6. import org.antlr.runtime.tree.*;import java.util.Stack;
  7. import java.util.List;
  8. import java.util.ArrayList;
  9. public class EMSWalker extends TreeParser {
  10. public static final String[] tokenNames = new String[] {
  11. "<invalid>", "<EOR>", "<DOWN>", "<UP>", "NEWLINE", "NUMBER", "ID", "F1", "F2", "'+'", "'-'", "'*'", "'/'", "'('", "')'", "','"
  12. };
  13. public static final int T__15=15;
  14. public static final int NEWLINE=4;
  15. public static final int T__12=12;
  16. public static final int T__11=11;
  17. public static final int T__14=14;
  18. public static final int T__13=13;
  19. public static final int T__10=10;
  20. public static final int NUMBER=5;
  21. public static final int F1=7;
  22. public static final int F2=8;
  23. public static final int ID=6;
  24. public static final int EOF=-1;
  25. public static final int T__9=9;
  26. // delegates
  27. // delegators
  28. public EMSWalker(TreeNodeStream input) {
  29. this(input, new RecognizerSharedState());
  30. }
  31. public EMSWalker(TreeNodeStream input, RecognizerSharedState state) {
  32. super(input, state);
  33. }
  34. public String[] getTokenNames() { return EMSWalker.tokenNames; }
  35. public String getGrammarFileName() { return "..\\antlrEMSIV\\src\\EMSWalker.g"; }
  36. public Map<String, Double> varValue = new HashMap<String, Double>();
  37. private String GetRealVar(String var)
  38. {
  39. return var.substring(1, var.length()-1);
  40. }
  41. // $ANTLR start "prog"
  42. // ..\\antlrEMSIV\\src\\EMSWalker.g:27:1: prog returns [double value] : (a= expr ) ;
  43. public final double prog() throws RecognitionException {
  44. double value = 0.0;
  45. double a = 0.0;
  46. try {
  47. // ..\\antlrEMSIV\\src\\EMSWalker.g:28:2: ( (a= expr ) )
  48. // ..\\antlrEMSIV\\src\\EMSWalker.g:28:4: (a= expr )
  49. {
  50. // ..\\antlrEMSIV\\src\\EMSWalker.g:28:4: (a= expr )
  51. // ..\\antlrEMSIV\\src\\EMSWalker.g:28:5: a= expr
  52. {
  53. pushFollow(FOLLOW_expr_in_prog64);
  54. a=expr();
  55. state._fsp--;
  56. }
  57. value =a;
  58. }
  59. }
  60. catch (RecognitionException re) {
  61. reportError(re);
  62. recover(input,re);
  63. }
  64. finally {
  65. }
  66. return value;
  67. }
  68. // $ANTLR end "prog"
  69. // $ANTLR start "expr"
  70. // ..\\antlrEMSIV\\src\\EMSWalker.g:31:1: expr returns [double value] : ( ^( '+' a= expr b= expr ) | ^( '-' a= expr b= expr ) | ^( '*' a= expr b= expr ) | ^( '/' a= expr b= expr ) | ID | NUMBER | ^( F1 a= expr ) | ^( F2 a= expr b= expr ) );
  71. public final double expr() throws RecognitionException {
  72. double value = 0.0;
  73. CommonTree ID1=null;
  74. CommonTree NUMBER2=null;
  75. CommonTree F13=null;
  76. CommonTree F24=null;
  77. double a = 0.0;
  78. double b = 0.0;
  79. try {
  80. // ..\\antlrEMSIV\\src\\EMSWalker.g:32:2: ( ^( '+' a= expr b= expr ) | ^( '-' a= expr b= expr ) | ^( '*' a= expr b= expr ) | ^( '/' a= expr b= expr ) | ID | NUMBER | ^( F1 a= expr ) | ^( F2 a= expr b= expr ) )
  81. int alt1=8;
  82. switch ( input.LA(1) ) {
  83. case 9:
  84. {
  85. alt1=1;
  86. }
  87. break;
  88. case 10:
  89. {
  90. alt1=2;
  91. }
  92. break;
  93. case 11:
  94. {
  95. alt1=3;
  96. }
  97. break;
  98. case 12:
  99. {
  100. alt1=4;
  101. }
  102. break;
  103. case ID:
  104. {
  105. alt1=5;
  106. }
  107. break;
  108. case NUMBER:
  109. {
  110. alt1=6;
  111. }
  112. break;
  113. case F1:
  114. {
  115. alt1=7;
  116. }
  117. break;
  118. case F2:
  119. {
  120. alt1=8;
  121. }
  122. break;
  123. default:
  124. NoViableAltException nvae =
  125. new NoViableAltException("", 1, 0, input);
  126. throw nvae;
  127. }
  128. switch (alt1) {
  129. case 1 :
  130. // ..\\antlrEMSIV\\src\\EMSWalker.g:32:4: ^( '+' a= expr b= expr )
  131. {
  132. match(input,9,FOLLOW_9_in_expr83);
  133. match(input, Token.DOWN, null);
  134. pushFollow(FOLLOW_expr_in_expr87);
  135. a=expr();
  136. state._fsp--;
  137. pushFollow(FOLLOW_expr_in_expr91);
  138. b=expr();
  139. state._fsp--;
  140. match(input, Token.UP, null);
  141. value = a+b;
  142. }
  143. break;
  144. case 2 :
  145. // ..\\antlrEMSIV\\src\\EMSWalker.g:33:4: ^( '-' a= expr b= expr )
  146. {
  147. match(input,10,FOLLOW_10_in_expr100);
  148. match(input, Token.DOWN, null);
  149. pushFollow(FOLLOW_expr_in_expr104);
  150. a=expr();
  151. state._fsp--;
  152. pushFollow(FOLLOW_expr_in_expr108);
  153. b=expr();
  154. state._fsp--;
  155. match(input, Token.UP, null);
  156. value = a-b;
  157. }
  158. break;
  159. case 3 :
  160. // ..\\antlrEMSIV\\src\\EMSWalker.g:34:4: ^( '*' a= expr b= expr )
  161. {
  162. match(input,11,FOLLOW_11_in_expr120);
  163. match(input, Token.DOWN, null);
  164. pushFollow(FOLLOW_expr_in_expr124);
  165. a=expr();
  166. state._fsp--;
  167. pushFollow(FOLLOW_expr_in_expr128);
  168. b=expr();
  169. state._fsp--;
  170. match(input, Token.UP, null);
  171. value = a*b;
  172. }
  173. break;
  174. case 4 :
  175. // ..\\antlrEMSIV\\src\\EMSWalker.g:35:4: ^( '/' a= expr b= expr )
  176. {
  177. match(input,12,FOLLOW_12_in_expr137);
  178. match(input, Token.DOWN, null);
  179. pushFollow(FOLLOW_expr_in_expr141);
  180. a=expr();
  181. state._fsp--;
  182. pushFollow(FOLLOW_expr_in_expr145);
  183. b=expr();
  184. state._fsp--;
  185. match(input, Token.UP, null);
  186. value = a/b;
  187. }
  188. break;
  189. case 5 :
  190. // ..\\antlrEMSIV\\src\\EMSWalker.g:36:4: ID
  191. {
  192. ID1=(CommonTree)match(input,ID,FOLLOW_ID_in_expr153);
  193. value = this.varValue.get(this.GetRealVar((ID1!=null?ID1.getText():null)));
  194. }
  195. break;
  196. case 6 :
  197. // ..\\antlrEMSIV\\src\\EMSWalker.g:37:4: NUMBER
  198. {
  199. NUMBER2=(CommonTree)match(input,NUMBER,FOLLOW_NUMBER_in_expr160);
  200. value = Double.parseDouble((NUMBER2!=null?NUMBER2.getText():null));
  201. }
  202. break;
  203. case 7 :
  204. // ..\\antlrEMSIV\\src\\EMSWalker.g:38:4: ^( F1 a= expr )
  205. {
  206. F13=(CommonTree)match(input,F1,FOLLOW_F1_in_expr169);
  207. match(input, Token.DOWN, null);
  208. pushFollow(FOLLOW_expr_in_expr173);
  209. a=expr();
  210. state._fsp--;
  211. match(input, Token.UP, null);
  212. value = FunctionUtil.compute((F13!=null?F13.getText():null),a);
  213. }
  214. break;
  215. case 8 :
  216. // ..\\antlrEMSIV\\src\\EMSWalker.g:39:4: ^( F2 a= expr b= expr )
  217. {
  218. F24=(CommonTree)match(input,F2,FOLLOW_F2_in_expr182);
  219. match(input, Token.DOWN, null);
  220. pushFollow(FOLLOW_expr_in_expr186);
  221. a=expr();
  222. state._fsp--;
  223. pushFollow(FOLLOW_expr_in_expr190);
  224. b=expr();
  225. state._fsp--;
  226. match(input, Token.UP, null);
  227. value = FunctionUtil.compute((F24!=null?F24.getText():null),a,b);
  228. }
  229. break;
  230. }
  231. }
  232. catch (RecognitionException re) {
  233. reportError(re);
  234. recover(input,re);
  235. }
  236. finally {
  237. }
  238. return value;
  239. }
  240. // $ANTLR end "expr"
  241. // Delegated rules
  242. public static final BitSet FOLLOW_expr_in_prog64 = new BitSet(new long[]{0x0000000000000002L});
  243. public static final BitSet FOLLOW_9_in_expr83 = new BitSet(new long[]{0x0000000000000004L});
  244. public static final BitSet FOLLOW_expr_in_expr87 = new BitSet(new long[]{0x0000000000001FE0L});
  245. public static final BitSet FOLLOW_expr_in_expr91 = new BitSet(new long[]{0x0000000000000008L});
  246. public static final BitSet FOLLOW_10_in_expr100 = new BitSet(new long[]{0x0000000000000004L});
  247. public static final BitSet FOLLOW_expr_in_expr104 = new BitSet(new long[]{0x0000000000001FE0L});
  248. public static final BitSet FOLLOW_expr_in_expr108 = new BitSet(new long[]{0x0000000000000008L});
  249. public static final BitSet FOLLOW_11_in_expr120 = new BitSet(new long[]{0x0000000000000004L});
  250. public static final BitSet FOLLOW_expr_in_expr124 = new BitSet(new long[]{0x0000000000001FE0L});
  251. public static final BitSet FOLLOW_expr_in_expr128 = new BitSet(new long[]{0x0000000000000008L});
  252. public static final BitSet FOLLOW_12_in_expr137 = new BitSet(new long[]{0x0000000000000004L});
  253. public static final BitSet FOLLOW_expr_in_expr141 = new BitSet(new long[]{0x0000000000001FE0L});
  254. public static final BitSet FOLLOW_expr_in_expr145 = new BitSet(new long[]{0x0000000000000008L});
  255. public static final BitSet FOLLOW_ID_in_expr153 = new BitSet(new long[]{0x0000000000000002L});
  256. public static final BitSet FOLLOW_NUMBER_in_expr160 = new BitSet(new long[]{0x0000000000000002L});
  257. public static final BitSet FOLLOW_F1_in_expr169 = new BitSet(new long[]{0x0000000000000004L});
  258. public static final BitSet FOLLOW_expr_in_expr173 = new BitSet(new long[]{0x0000000000000008L});
  259. public static final BitSet FOLLOW_F2_in_expr182 = new BitSet(new long[]{0x0000000000000004L});
  260. public static final BitSet FOLLOW_expr_in_expr186 = new BitSet(new long[]{0x0000000000001FE0L});
  261. public static final BitSet FOLLOW_expr_in_expr190 = new BitSet(new long[]{0x0000000000000008L});
  262. }