Exp1Parser.java

Go to the documentation of this file.
00001 /* Generated By:JavaCC: Do not edit this line. Exp1Parser.java */
00002 package plp.expressions1.parser;
00003 
00004 import plp.expressions1.*;
00005 import plp.expressions1.expression.*;
00006 import plp.expressions1.util.*;
00007 
00008 public class Exp1Parser implements Exp1ParserConstants {
00009 
00010     public static void main(String args[]) {
00011             Exp1Parser parser;
00012             if (args.length == 0) {
00013                 System.out.println("Expressoes 1 PLP Parser Version 0.0.1:  Reading from standard input . . .");
00014                 parser = new Exp1Parser(System.in);
00015             } else if (args.length == 1) {
00016                 System.out.println("Expressoes 1 PLP Parser Version 0.0.1:  Reading from file " + args[0] + " . . .");
00017                 try {
00018                         parser = new Exp1Parser(new java.io.FileInputStream(args[0]));
00019                 } catch (java.io.FileNotFoundException e) {
00020                         System.out.println("Java Parser Version 1.0.2:  File " + args[0] + " not found.");
00021                         return;
00022                 }
00023             } else {
00024                 System.out.println("Expressoes 1 PLP Parser Version 0.0.1:  Usage is one of:");
00025                 System.out.println("         java Exp1Parser < inputfile");
00026                 System.out.println("OR");
00027                 System.out.println("         java Exp1Parser inputfile");
00028                 return;
00029             }
00030             try {
00031                 Programa programa = parser.Input();
00032                 System.out.println("Expressoes 1 PLP Parser Version 0.0.1:  Expressoes1 program parsed successfully.");
00033                         if (!programa.checaTipo()) {
00034                                 System.out.println("Erro de tipo");
00035                         } else {
00036                                 programa.executar();
00037                         }
00038             } catch (ParseException e) {
00039                 System.out.println("Expressoes 1 PLP Parser Version 0.0.1:  Encountered errors during parse.");
00040             }
00041         }
00042 
00043   static final public Programa Input() throws ParseException {
00044     Programa retorno;
00045     retorno = PPrograma();
00046     jj_consume_token(0);
00047         {if (true) return retorno;}
00048     throw new Error("Missing return statement in function");
00049   }
00050 
00051   static final public Valor PValorInteiro() throws ParseException {
00052         Token token;
00053     token = jj_consume_token(INTEGER_LITERAL);
00054                 {if (true) return new ValorInteiro(Integer.parseInt(token.toString()));}
00055     throw new Error("Missing return statement in function");
00056   }
00057 
00058   static final public Valor PValorBooleano() throws ParseException {
00059     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
00060     case FALSE:
00061       jj_consume_token(FALSE);
00062                     {if (true) return new ValorBooleano(false);}
00063       break;
00064     case TRUE:
00065       jj_consume_token(TRUE);
00066                     {if (true) return new ValorBooleano(true);}
00067       break;
00068     default:
00069       jj_la1[0] = jj_gen;
00070       jj_consume_token(-1);
00071       throw new ParseException();
00072     }
00073     throw new Error("Missing return statement in function");
00074   }
00075 
00076   static final public Valor PValorString() throws ParseException {
00077         Token token;
00078     token = jj_consume_token(STRING_LITERAL);
00079                 String tokenStr = token.toString();
00080                 tokenStr = tokenStr.substring(1,tokenStr.length()-1);
00081                 {if (true) return new ValorString(tokenStr);}
00082     throw new Error("Missing return statement in function");
00083   }
00084 
00085   static final public Valor PValor() throws ParseException {
00086         Valor retorno;
00087     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
00088     case INTEGER_LITERAL:
00089       retorno = PValorInteiro();
00090       break;
00091     case TRUE:
00092     case FALSE:
00093       retorno = PValorBooleano();
00094       break;
00095     case STRING_LITERAL:
00096       retorno = PValorString();
00097       break;
00098     default:
00099       jj_la1[1] = jj_gen;
00100       jj_consume_token(-1);
00101       throw new ParseException();
00102     }
00103                 {if (true) return retorno;}
00104     throw new Error("Missing return statement in function");
00105   }
00106 
00107   static final public Expressao PExpMenos() throws ParseException {
00108         Expressao retorno;
00109     jj_consume_token(MINUS);
00110     retorno = PExpPrimaria();
00111                 {if (true) return new ExpMenos(retorno);}
00112     throw new Error("Missing return statement in function");
00113   }
00114 
00115   static final public Expressao PExpNot() throws ParseException {
00116         Expressao retorno;
00117     jj_consume_token(NOT);
00118     retorno = PExpPrimaria();
00119                 {if (true) return new ExpNot(retorno);}
00120     throw new Error("Missing return statement in function");
00121   }
00122 
00123   static final public Expressao PExpLength() throws ParseException {
00124         Expressao retorno;
00125     jj_consume_token(LENGTH);
00126     retorno = PExpPrimaria();
00127                 if (retorno instanceof ValorString) {
00128                     ValorString val = (ValorString) retorno;
00129                 }
00130                 {if (true) return new ExpLength(retorno);}
00131     throw new Error("Missing return statement in function");
00132   }
00133 
00134   static final public Expressao PExpPrimaria() throws ParseException {
00135     Expressao retorno;
00136     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
00137     case TRUE:
00138     case FALSE:
00139     case INTEGER_LITERAL:
00140     case STRING_LITERAL:
00141       retorno = PValor();
00142       break;
00143     case LPAREN:
00144       jj_consume_token(LPAREN);
00145       retorno = PExpressao();
00146       jj_consume_token(RPAREN);
00147       break;
00148     default:
00149       jj_la1[2] = jj_gen;
00150       jj_consume_token(-1);
00151       throw new ParseException();
00152     }
00153                 {if (true) return retorno;}
00154     throw new Error("Missing return statement in function");
00155   }
00156 
00157   static final public Expressao PExpUnaria() throws ParseException {
00158         Expressao retorno;
00159     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
00160     case MINUS:
00161       retorno = PExpMenos();
00162       break;
00163     case NOT:
00164       retorno = PExpNot();
00165       break;
00166     case LENGTH:
00167       retorno = PExpLength();
00168       break;
00169     case TRUE:
00170     case FALSE:
00171     case INTEGER_LITERAL:
00172     case STRING_LITERAL:
00173     case LPAREN:
00174       retorno = PExpPrimaria();
00175       break;
00176     default:
00177       jj_la1[3] = jj_gen;
00178       jj_consume_token(-1);
00179       throw new ParseException();
00180     }
00181                 {if (true) return retorno;}
00182     throw new Error("Missing return statement in function");
00183   }
00184 
00185   static final public Expressao PExpBinaria() throws ParseException {
00186         Expressao retorno, param2;
00187     retorno = PExpUnaria();
00188     label_1:
00189     while (true) {
00190       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
00191       case AND:
00192       case OR:
00193       case EQ:
00194       case CONCAT:
00195       case PLUS:
00196       case MINUS:
00197         ;
00198         break;
00199       default:
00200         jj_la1[4] = jj_gen;
00201         break label_1;
00202       }
00203       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
00204       case CONCAT:
00205         jj_consume_token(CONCAT);
00206         param2 = PExpUnaria();
00207                 retorno = new ExpConcat(retorno, param2);
00208         break;
00209       case MINUS:
00210         jj_consume_token(MINUS);
00211         param2 = PExpUnaria();
00212                 retorno = new ExpSub(retorno, param2);
00213         break;
00214       case AND:
00215         jj_consume_token(AND);
00216         param2 = PExpUnaria();
00217                 retorno = new ExpAnd(retorno, param2);
00218         break;
00219       case OR:
00220         jj_consume_token(OR);
00221         param2 = PExpUnaria();
00222                 retorno = new ExpOr(retorno, param2);
00223         break;
00224       case EQ:
00225         jj_consume_token(EQ);
00226         param2 = PExpUnaria();
00227                 retorno = new ExpEquals(retorno, param2);
00228         break;
00229       case PLUS:
00230         jj_consume_token(PLUS);
00231         param2 = PExpUnaria();
00232                 retorno = new ExpSoma(retorno, param2);
00233         break;
00234       default:
00235         jj_la1[5] = jj_gen;
00236         jj_consume_token(-1);
00237         throw new ParseException();
00238       }
00239     }
00240                 {if (true) return retorno;}
00241     throw new Error("Missing return statement in function");
00242   }
00243 
00244   static final public Expressao PExpressao() throws ParseException {
00245         Expressao retorno;
00246     retorno = PExpBinaria();
00247                 {if (true) return retorno;}
00248     throw new Error("Missing return statement in function");
00249   }
00250 
00251   static final public Programa PPrograma() throws ParseException {
00252         Expressao retorno;
00253     retorno = PExpressao();
00254                 {if (true) return new Programa(retorno);}
00255     throw new Error("Missing return statement in function");
00256   }
00257 
00258   static private boolean jj_initialized_once = false;
00259   static public Exp1ParserTokenManager token_source;
00260   static JavaCharStream jj_input_stream;
00261   static public Token token, jj_nt;
00262   static private int jj_ntk;
00263   static private int jj_gen;
00264   static final private int[] jj_la1 = new int[6];
00265   static private int[] jj_la1_0;
00266   static private int[] jj_la1_1;
00267   static {
00268       jj_la1_0();
00269       jj_la1_1();
00270    }
00271    private static void jj_la1_0() {
00272       jj_la1_0 = new int[] {0x6000,0x8e000,0x88e000,0x88f800,0x600,0x600,};
00273    }
00274    private static void jj_la1_1() {
00275       jj_la1_1 = new int[] {0x0,0x0,0x0,0x8000,0xe080,0xe080,};
00276    }
00277 
00278   public Exp1Parser(java.io.InputStream stream) {
00279      this(stream, null);
00280   }
00281   public Exp1Parser(java.io.InputStream stream, String encoding) {
00282     if (jj_initialized_once) {
00283       System.out.println("ERROR: Second call to constructor of static parser.  You must");
00284       System.out.println("       either use ReInit() or set the JavaCC option STATIC to false");
00285       System.out.println("       during parser generation.");
00286       throw new Error();
00287     }
00288     jj_initialized_once = true;
00289     try { jj_input_stream = new JavaCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
00290     token_source = new Exp1ParserTokenManager(jj_input_stream);
00291     token = new Token();
00292     jj_ntk = -1;
00293     jj_gen = 0;
00294     for (int i = 0; i < 6; i++) jj_la1[i] = -1;
00295   }
00296 
00297   static public void ReInit(java.io.InputStream stream) {
00298      ReInit(stream, null);
00299   }
00300   static public void ReInit(java.io.InputStream stream, String encoding) {
00301     try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
00302     token_source.ReInit(jj_input_stream);
00303     token = new Token();
00304     jj_ntk = -1;
00305     jj_gen = 0;
00306     for (int i = 0; i < 6; i++) jj_la1[i] = -1;
00307   }
00308 
00309   public Exp1Parser(java.io.Reader stream) {
00310     if (jj_initialized_once) {
00311       System.out.println("ERROR: Second call to constructor of static parser.  You must");
00312       System.out.println("       either use ReInit() or set the JavaCC option STATIC to false");
00313       System.out.println("       during parser generation.");
00314       throw new Error();
00315     }
00316     jj_initialized_once = true;
00317     jj_input_stream = new JavaCharStream(stream, 1, 1);
00318     token_source = new Exp1ParserTokenManager(jj_input_stream);
00319     token = new Token();
00320     jj_ntk = -1;
00321     jj_gen = 0;
00322     for (int i = 0; i < 6; i++) jj_la1[i] = -1;
00323   }
00324 
00325   static public void ReInit(java.io.Reader stream) {
00326     jj_input_stream.ReInit(stream, 1, 1);
00327     token_source.ReInit(jj_input_stream);
00328     token = new Token();
00329     jj_ntk = -1;
00330     jj_gen = 0;
00331     for (int i = 0; i < 6; i++) jj_la1[i] = -1;
00332   }
00333 
00334   public Exp1Parser(Exp1ParserTokenManager tm) {
00335     if (jj_initialized_once) {
00336       System.out.println("ERROR: Second call to constructor of static parser.  You must");
00337       System.out.println("       either use ReInit() or set the JavaCC option STATIC to false");
00338       System.out.println("       during parser generation.");
00339       throw new Error();
00340     }
00341     jj_initialized_once = true;
00342     token_source = tm;
00343     token = new Token();
00344     jj_ntk = -1;
00345     jj_gen = 0;
00346     for (int i = 0; i < 6; i++) jj_la1[i] = -1;
00347   }
00348 
00349   public void ReInit(Exp1ParserTokenManager tm) {
00350     token_source = tm;
00351     token = new Token();
00352     jj_ntk = -1;
00353     jj_gen = 0;
00354     for (int i = 0; i < 6; i++) jj_la1[i] = -1;
00355   }
00356 
00357   static final private Token jj_consume_token(int kind) throws ParseException {
00358     Token oldToken;
00359     if ((oldToken = token).next != null) token = token.next;
00360     else token = token.next = token_source.getNextToken();
00361     jj_ntk = -1;
00362     if (token.kind == kind) {
00363       jj_gen++;
00364       return token;
00365     }
00366     token = oldToken;
00367     jj_kind = kind;
00368     throw generateParseException();
00369   }
00370 
00371   static final public Token getNextToken() {
00372     if (token.next != null) token = token.next;
00373     else token = token.next = token_source.getNextToken();
00374     jj_ntk = -1;
00375     jj_gen++;
00376     return token;
00377   }
00378 
00379   static final public Token getToken(int index) {
00380     Token t = token;
00381     for (int i = 0; i < index; i++) {
00382       if (t.next != null) t = t.next;
00383       else t = t.next = token_source.getNextToken();
00384     }
00385     return t;
00386   }
00387 
00388   static final private int jj_ntk() {
00389     if ((jj_nt=token.next) == null)
00390       return (jj_ntk = (token.next=token_source.getNextToken()).kind);
00391     else
00392       return (jj_ntk = jj_nt.kind);
00393   }
00394 
00395   static private java.util.Vector<int[]> jj_expentries = new java.util.Vector<int[]>();
00396   static private int[] jj_expentry;
00397   static private int jj_kind = -1;
00398 
00399   static public ParseException generateParseException() {
00400     jj_expentries.removeAllElements();
00401     boolean[] la1tokens = new boolean[54];
00402     for (int i = 0; i < 54; i++) {
00403       la1tokens[i] = false;
00404     }
00405     if (jj_kind >= 0) {
00406       la1tokens[jj_kind] = true;
00407       jj_kind = -1;
00408     }
00409     for (int i = 0; i < 6; i++) {
00410       if (jj_la1[i] == jj_gen) {
00411         for (int j = 0; j < 32; j++) {
00412           if ((jj_la1_0[i] & (1<<j)) != 0) {
00413             la1tokens[j] = true;
00414           }
00415           if ((jj_la1_1[i] & (1<<j)) != 0) {
00416             la1tokens[32+j] = true;
00417           }
00418         }
00419       }
00420     }
00421     for (int i = 0; i < 54; i++) {
00422       if (la1tokens[i]) {
00423         jj_expentry = new int[1];
00424         jj_expentry[0] = i;
00425         jj_expentries.addElement(jj_expentry);
00426       }
00427     }
00428     int[][] exptokseq = new int[jj_expentries.size()][];
00429     for (int i = 0; i < jj_expentries.size(); i++) {
00430       exptokseq[i] = (int[])jj_expentries.elementAt(i);
00431     }
00432     return new ParseException(token, exptokseq, tokenImage);
00433   }
00434 
00435   static final public void enable_tracing() {
00436   }
00437 
00438   static final public void disable_tracing() {
00439   }
00440 
00441 }

Generated on Tue Sep 12 21:51:58 2006 for PLP by  doxygen 1.4.7