// $ANTLR 3.1 ..\\antlrEMSIV\\src\\EMSWalker.g 2015-12-04 17:45:01 package com.pbsage.parser.emsiv; import java.util.Map; import java.util.HashMap; import org.antlr.runtime.*; import org.antlr.runtime.tree.*;import java.util.Stack; import java.util.List; import java.util.ArrayList; public class EMSWalker extends TreeParser { public static final String[] tokenNames = new String[] { "", "", "", "", "NEWLINE", "NUMBER", "ID", "F1", "F2", "'+'", "'-'", "'*'", "'/'", "'('", "')'", "','" }; public static final int T__15=15; public static final int NEWLINE=4; public static final int T__12=12; public static final int T__11=11; public static final int T__14=14; public static final int T__13=13; public static final int T__10=10; public static final int NUMBER=5; public static final int F1=7; public static final int F2=8; public static final int ID=6; public static final int EOF=-1; public static final int T__9=9; // delegates // delegators public EMSWalker(TreeNodeStream input) { this(input, new RecognizerSharedState()); } public EMSWalker(TreeNodeStream input, RecognizerSharedState state) { super(input, state); } public String[] getTokenNames() { return EMSWalker.tokenNames; } public String getGrammarFileName() { return "..\\antlrEMSIV\\src\\EMSWalker.g"; } public Map varValue = new HashMap(); private String GetRealVar(String var) { return var.substring(1, var.length()-1); } // $ANTLR start "prog" // ..\\antlrEMSIV\\src\\EMSWalker.g:27:1: prog returns [double value] : (a= expr ) ; public final double prog() throws RecognitionException { double value = 0.0; double a = 0.0; try { // ..\\antlrEMSIV\\src\\EMSWalker.g:28:2: ( (a= expr ) ) // ..\\antlrEMSIV\\src\\EMSWalker.g:28:4: (a= expr ) { // ..\\antlrEMSIV\\src\\EMSWalker.g:28:4: (a= expr ) // ..\\antlrEMSIV\\src\\EMSWalker.g:28:5: a= expr { pushFollow(FOLLOW_expr_in_prog64); a=expr(); state._fsp--; } value =a; } } catch (RecognitionException re) { reportError(re); recover(input,re); } finally { } return value; } // $ANTLR end "prog" // $ANTLR start "expr" // ..\\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 ) ); public final double expr() throws RecognitionException { double value = 0.0; CommonTree ID1=null; CommonTree NUMBER2=null; CommonTree F13=null; CommonTree F24=null; double a = 0.0; double b = 0.0; try { // ..\\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 ) ) int alt1=8; switch ( input.LA(1) ) { case 9: { alt1=1; } break; case 10: { alt1=2; } break; case 11: { alt1=3; } break; case 12: { alt1=4; } break; case ID: { alt1=5; } break; case NUMBER: { alt1=6; } break; case F1: { alt1=7; } break; case F2: { alt1=8; } break; default: NoViableAltException nvae = new NoViableAltException("", 1, 0, input); throw nvae; } switch (alt1) { case 1 : // ..\\antlrEMSIV\\src\\EMSWalker.g:32:4: ^( '+' a= expr b= expr ) { match(input,9,FOLLOW_9_in_expr83); match(input, Token.DOWN, null); pushFollow(FOLLOW_expr_in_expr87); a=expr(); state._fsp--; pushFollow(FOLLOW_expr_in_expr91); b=expr(); state._fsp--; match(input, Token.UP, null); value = a+b; } break; case 2 : // ..\\antlrEMSIV\\src\\EMSWalker.g:33:4: ^( '-' a= expr b= expr ) { match(input,10,FOLLOW_10_in_expr100); match(input, Token.DOWN, null); pushFollow(FOLLOW_expr_in_expr104); a=expr(); state._fsp--; pushFollow(FOLLOW_expr_in_expr108); b=expr(); state._fsp--; match(input, Token.UP, null); value = a-b; } break; case 3 : // ..\\antlrEMSIV\\src\\EMSWalker.g:34:4: ^( '*' a= expr b= expr ) { match(input,11,FOLLOW_11_in_expr120); match(input, Token.DOWN, null); pushFollow(FOLLOW_expr_in_expr124); a=expr(); state._fsp--; pushFollow(FOLLOW_expr_in_expr128); b=expr(); state._fsp--; match(input, Token.UP, null); value = a*b; } break; case 4 : // ..\\antlrEMSIV\\src\\EMSWalker.g:35:4: ^( '/' a= expr b= expr ) { match(input,12,FOLLOW_12_in_expr137); match(input, Token.DOWN, null); pushFollow(FOLLOW_expr_in_expr141); a=expr(); state._fsp--; pushFollow(FOLLOW_expr_in_expr145); b=expr(); state._fsp--; match(input, Token.UP, null); value = a/b; } break; case 5 : // ..\\antlrEMSIV\\src\\EMSWalker.g:36:4: ID { ID1=(CommonTree)match(input,ID,FOLLOW_ID_in_expr153); value = this.varValue.get(this.GetRealVar((ID1!=null?ID1.getText():null))); } break; case 6 : // ..\\antlrEMSIV\\src\\EMSWalker.g:37:4: NUMBER { NUMBER2=(CommonTree)match(input,NUMBER,FOLLOW_NUMBER_in_expr160); value = Double.parseDouble((NUMBER2!=null?NUMBER2.getText():null)); } break; case 7 : // ..\\antlrEMSIV\\src\\EMSWalker.g:38:4: ^( F1 a= expr ) { F13=(CommonTree)match(input,F1,FOLLOW_F1_in_expr169); match(input, Token.DOWN, null); pushFollow(FOLLOW_expr_in_expr173); a=expr(); state._fsp--; match(input, Token.UP, null); value = FunctionUtil.compute((F13!=null?F13.getText():null),a); } break; case 8 : // ..\\antlrEMSIV\\src\\EMSWalker.g:39:4: ^( F2 a= expr b= expr ) { F24=(CommonTree)match(input,F2,FOLLOW_F2_in_expr182); match(input, Token.DOWN, null); pushFollow(FOLLOW_expr_in_expr186); a=expr(); state._fsp--; pushFollow(FOLLOW_expr_in_expr190); b=expr(); state._fsp--; match(input, Token.UP, null); value = FunctionUtil.compute((F24!=null?F24.getText():null),a,b); } break; } } catch (RecognitionException re) { reportError(re); recover(input,re); } finally { } return value; } // $ANTLR end "expr" // Delegated rules public static final BitSet FOLLOW_expr_in_prog64 = new BitSet(new long[]{0x0000000000000002L}); public static final BitSet FOLLOW_9_in_expr83 = new BitSet(new long[]{0x0000000000000004L}); public static final BitSet FOLLOW_expr_in_expr87 = new BitSet(new long[]{0x0000000000001FE0L}); public static final BitSet FOLLOW_expr_in_expr91 = new BitSet(new long[]{0x0000000000000008L}); public static final BitSet FOLLOW_10_in_expr100 = new BitSet(new long[]{0x0000000000000004L}); public static final BitSet FOLLOW_expr_in_expr104 = new BitSet(new long[]{0x0000000000001FE0L}); public static final BitSet FOLLOW_expr_in_expr108 = new BitSet(new long[]{0x0000000000000008L}); public static final BitSet FOLLOW_11_in_expr120 = new BitSet(new long[]{0x0000000000000004L}); public static final BitSet FOLLOW_expr_in_expr124 = new BitSet(new long[]{0x0000000000001FE0L}); public static final BitSet FOLLOW_expr_in_expr128 = new BitSet(new long[]{0x0000000000000008L}); public static final BitSet FOLLOW_12_in_expr137 = new BitSet(new long[]{0x0000000000000004L}); public static final BitSet FOLLOW_expr_in_expr141 = new BitSet(new long[]{0x0000000000001FE0L}); public static final BitSet FOLLOW_expr_in_expr145 = new BitSet(new long[]{0x0000000000000008L}); public static final BitSet FOLLOW_ID_in_expr153 = new BitSet(new long[]{0x0000000000000002L}); public static final BitSet FOLLOW_NUMBER_in_expr160 = new BitSet(new long[]{0x0000000000000002L}); public static final BitSet FOLLOW_F1_in_expr169 = new BitSet(new long[]{0x0000000000000004L}); public static final BitSet FOLLOW_expr_in_expr173 = new BitSet(new long[]{0x0000000000000008L}); public static final BitSet FOLLOW_F2_in_expr182 = new BitSet(new long[]{0x0000000000000004L}); public static final BitSet FOLLOW_expr_in_expr186 = new BitSet(new long[]{0x0000000000001FE0L}); public static final BitSet FOLLOW_expr_in_expr190 = new BitSet(new long[]{0x0000000000000008L}); }