123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345 |
- // $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[] {
- "<invalid>", "<EOR>", "<DOWN>", "<UP>", "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<String, Double> varValue = new HashMap<String, Double>();
-
- 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});
- }
|