00001
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 PValorChar() throws ParseException {
00086 Token token;
00087 token = jj_consume_token(CHAR_LITERAL);
00088 String tokenStr = token.toString();
00089 {if (true) return new ValorChar(tokenStr.toCharArray()[1]);}
00090 throw new Error("Missing return statement in function");
00091 }
00092
00093 static final public Valor PValorReal() throws ParseException {
00094 Token token;
00095 token = jj_consume_token(REAL_LITERAL);
00096 {if (true) return new ValorReal(Double.parseDouble(token.toString()));}
00097 throw new Error("Missing return statement in function");
00098 }
00099
00100 static final public Valor PValor() throws ParseException {
00101 Valor retorno;
00102 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
00103 case INTEGER_LITERAL:
00104 retorno = PValorInteiro();
00105 break;
00106 case TRUE:
00107 case FALSE:
00108 retorno = PValorBooleano();
00109 break;
00110 case STRING_LITERAL:
00111 retorno = PValorString();
00112 break;
00113 case CHAR_LITERAL:
00114 retorno = PValorChar();
00115 break;
00116 case REAL_LITERAL:
00117 retorno = PValorReal();
00118 break;
00119 default:
00120 jj_la1[1] = jj_gen;
00121 jj_consume_token(-1);
00122 throw new ParseException();
00123 }
00124 {if (true) return retorno;}
00125 throw new Error("Missing return statement in function");
00126 }
00127
00128 static final public Expressao PExpMenos() throws ParseException {
00129 Expressao retorno;
00130 jj_consume_token(MINUS);
00131 retorno = PExpPrimaria();
00132 {if (true) return new ExpMenos(retorno);}
00133 throw new Error("Missing return statement in function");
00134 }
00135
00136 static final public Expressao PExpNot() throws ParseException {
00137 Expressao retorno;
00138 jj_consume_token(NOT);
00139 retorno = PExpPrimaria();
00140 {if (true) return new ExpNot(retorno);}
00141 throw new Error("Missing return statement in function");
00142 }
00143
00144 static final public Expressao PExpLength() throws ParseException {
00145 Expressao retorno;
00146 jj_consume_token(LENGTH);
00147 retorno = PExpPrimaria();
00148 if (retorno instanceof ValorString) {
00149 ValorString val = (ValorString) retorno;
00150 }
00151 {if (true) return new ExpLength(retorno);}
00152 throw new Error("Missing return statement in function");
00153 }
00154
00155 static final public Expressao PExpOrder() throws ParseException {
00156 Expressao retorno;
00157 jj_consume_token(ORDER);
00158 retorno = PExpPrimaria();
00159 if (retorno instanceof ValorChar) {
00160 ValorChar val = (ValorChar) retorno;
00161 }
00162 {if (true) return new ExpOrder(retorno);}
00163 throw new Error("Missing return statement in function");
00164 }
00165
00166 static final public Expressao PExpPrimaria() throws ParseException {
00167 Expressao retorno;
00168 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
00169 case TRUE:
00170 case FALSE:
00171 case INTEGER_LITERAL:
00172 case STRING_LITERAL:
00173 case CHAR_LITERAL:
00174 case REAL_LITERAL:
00175 retorno = PValor();
00176 break;
00177 case LPAREN:
00178 jj_consume_token(LPAREN);
00179 retorno = PExpressao();
00180 jj_consume_token(RPAREN);
00181 break;
00182 default:
00183 jj_la1[2] = jj_gen;
00184 jj_consume_token(-1);
00185 throw new ParseException();
00186 }
00187 {if (true) return retorno;}
00188 throw new Error("Missing return statement in function");
00189 }
00190
00191 static final public Expressao PExpUnaria() throws ParseException {
00192 Expressao retorno;
00193 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
00194 case MINUS:
00195 retorno = PExpMenos();
00196 break;
00197 case NOT:
00198 retorno = PExpNot();
00199 break;
00200 case LENGTH:
00201 retorno = PExpLength();
00202 break;
00203 case ORDER:
00204 retorno = PExpOrder();
00205 break;
00206 case TRUE:
00207 case FALSE:
00208 case INTEGER_LITERAL:
00209 case STRING_LITERAL:
00210 case CHAR_LITERAL:
00211 case REAL_LITERAL:
00212 case LPAREN:
00213 retorno = PExpPrimaria();
00214 break;
00215 default:
00216 jj_la1[3] = jj_gen;
00217 jj_consume_token(-1);
00218 throw new ParseException();
00219 }
00220 {if (true) return retorno;}
00221 throw new Error("Missing return statement in function");
00222 }
00223
00224 static final public Expressao PExpBinaria() throws ParseException {
00225 Expressao retorno, param2;
00226 retorno = PExpUnaria();
00227 label_1:
00228 while (true) {
00229 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
00230 case AND:
00231 case OR:
00232 case EQ:
00233 case CONCAT:
00234 case PLUS:
00235 case MINUS:
00236 case STAR:
00237 ;
00238 break;
00239 default:
00240 jj_la1[4] = jj_gen;
00241 break label_1;
00242 }
00243 switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
00244 case CONCAT:
00245 jj_consume_token(CONCAT);
00246 param2 = PExpUnaria();
00247 retorno = new ExpConcat(retorno, param2);
00248 break;
00249 case MINUS:
00250 jj_consume_token(MINUS);
00251 param2 = PExpUnaria();
00252 retorno = new ExpSub(retorno, param2);
00253 break;
00254 case AND:
00255 jj_consume_token(AND);
00256 param2 = PExpUnaria();
00257 retorno = new ExpAnd(retorno, param2);
00258 break;
00259 case OR:
00260 jj_consume_token(OR);
00261 param2 = PExpUnaria();
00262 retorno = new ExpOr(retorno, param2);
00263 break;
00264 case EQ:
00265 jj_consume_token(EQ);
00266 param2 = PExpUnaria();
00267 retorno = new ExpEquals(retorno, param2);
00268 break;
00269 case PLUS:
00270 jj_consume_token(PLUS);
00271 param2 = PExpUnaria();
00272 retorno = new ExpSoma(retorno, param2);
00273 break;
00274 case STAR:
00275 jj_consume_token(STAR);
00276 param2 = PExpUnaria();
00277 retorno = new ExpMult(retorno, param2);
00278 break;
00279 default:
00280 jj_la1[5] = jj_gen;
00281 jj_consume_token(-1);
00282 throw new ParseException();
00283 }
00284 }
00285 {if (true) return retorno;}
00286 throw new Error("Missing return statement in function");
00287 }
00288
00289 static final public Expressao PExpressao() throws ParseException {
00290 Expressao retorno;
00291 retorno = PExpBinaria();
00292 {if (true) return retorno;}
00293 throw new Error("Missing return statement in function");
00294 }
00295
00296 static final public Programa PPrograma() throws ParseException {
00297 Expressao retorno;
00298 retorno = PExpressao();
00299 {if (true) return new Programa(retorno);}
00300 throw new Error("Missing return statement in function");
00301 }
00302
00303 static private boolean jj_initialized_once = false;
00305 static public Exp1ParserTokenManager token_source;
00306 static JavaCharStream jj_input_stream;
00308 static public Token token;
00310 static public Token jj_nt;
00311 static private int jj_ntk;
00312 static private int jj_gen;
00313 static final private int[] jj_la1 = new int[6];
00314 static private int[] jj_la1_0;
00315 static private int[] jj_la1_1;
00316 static {
00317 jj_la1_init_0();
00318 jj_la1_init_1();
00319 }
00320 private static void jj_la1_init_0() {
00321 jj_la1_0 = new int[] {0xc000,0x71c000,0x471c000,0x471f800,0x600,0x600,};
00322 }
00323 private static void jj_la1_init_1() {
00324 jj_la1_1 = new int[] {0x0,0x0,0x0,0x40000,0xf0400,0xf0400,};
00325 }
00326
00328 public Exp1Parser(java.io.InputStream stream) {
00329 this(stream, null);
00330 }
00332 public Exp1Parser(java.io.InputStream stream, String encoding) {
00333 if (jj_initialized_once) {
00334 System.out.println("ERROR: Second call to constructor of static parser. ");
00335 System.out.println(" You must either use ReInit() or set the JavaCC option STATIC to false");
00336 System.out.println(" during parser generation.");
00337 throw new Error();
00338 }
00339 jj_initialized_once = true;
00340 try { jj_input_stream = new JavaCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
00341 token_source = new Exp1ParserTokenManager(jj_input_stream);
00342 token = new Token();
00343 jj_ntk = -1;
00344 jj_gen = 0;
00345 for (int i = 0; i < 6; i++) jj_la1[i] = -1;
00346 }
00347
00349 static public void ReInit(java.io.InputStream stream) {
00350 ReInit(stream, null);
00351 }
00353 static public void ReInit(java.io.InputStream stream, String encoding) {
00354 try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
00355 token_source.ReInit(jj_input_stream);
00356 token = new Token();
00357 jj_ntk = -1;
00358 jj_gen = 0;
00359 for (int i = 0; i < 6; i++) jj_la1[i] = -1;
00360 }
00361
00363 public Exp1Parser(java.io.Reader stream) {
00364 if (jj_initialized_once) {
00365 System.out.println("ERROR: Second call to constructor of static parser. ");
00366 System.out.println(" You must either use ReInit() or set the JavaCC option STATIC to false");
00367 System.out.println(" during parser generation.");
00368 throw new Error();
00369 }
00370 jj_initialized_once = true;
00371 jj_input_stream = new JavaCharStream(stream, 1, 1);
00372 token_source = new Exp1ParserTokenManager(jj_input_stream);
00373 token = new Token();
00374 jj_ntk = -1;
00375 jj_gen = 0;
00376 for (int i = 0; i < 6; i++) jj_la1[i] = -1;
00377 }
00378
00380 static public void ReInit(java.io.Reader stream) {
00381 jj_input_stream.ReInit(stream, 1, 1);
00382 token_source.ReInit(jj_input_stream);
00383 token = new Token();
00384 jj_ntk = -1;
00385 jj_gen = 0;
00386 for (int i = 0; i < 6; i++) jj_la1[i] = -1;
00387 }
00388
00390 public Exp1Parser(Exp1ParserTokenManager tm) {
00391 if (jj_initialized_once) {
00392 System.out.println("ERROR: Second call to constructor of static parser. ");
00393 System.out.println(" You must either use ReInit() or set the JavaCC option STATIC to false");
00394 System.out.println(" during parser generation.");
00395 throw new Error();
00396 }
00397 jj_initialized_once = true;
00398 token_source = tm;
00399 token = new Token();
00400 jj_ntk = -1;
00401 jj_gen = 0;
00402 for (int i = 0; i < 6; i++) jj_la1[i] = -1;
00403 }
00404
00406 public void ReInit(Exp1ParserTokenManager tm) {
00407 token_source = tm;
00408 token = new Token();
00409 jj_ntk = -1;
00410 jj_gen = 0;
00411 for (int i = 0; i < 6; i++) jj_la1[i] = -1;
00412 }
00413
00414 static private Token jj_consume_token(int kind) throws ParseException {
00415 Token oldToken;
00416 if ((oldToken = token).next != null) token = token.next;
00417 else token = token.next = token_source.getNextToken();
00418 jj_ntk = -1;
00419 if (token.kind == kind) {
00420 jj_gen++;
00421 return token;
00422 }
00423 token = oldToken;
00424 jj_kind = kind;
00425 throw generateParseException();
00426 }
00427
00428
00430 static final public Token getNextToken() {
00431 if (token.next != null) token = token.next;
00432 else token = token.next = token_source.getNextToken();
00433 jj_ntk = -1;
00434 jj_gen++;
00435 return token;
00436 }
00437
00439 static final public Token getToken(int index) {
00440 Token t = token;
00441 for (int i = 0; i < index; i++) {
00442 if (t.next != null) t = t.next;
00443 else t = t.next = token_source.getNextToken();
00444 }
00445 return t;
00446 }
00447
00448 static private int jj_ntk() {
00449 if ((jj_nt=token.next) == null)
00450 return (jj_ntk = (token.next=token_source.getNextToken()).kind);
00451 else
00452 return (jj_ntk = jj_nt.kind);
00453 }
00454
00455 static private java.util.List jj_expentries = new java.util.ArrayList();
00456 static private int[] jj_expentry;
00457 static private int jj_kind = -1;
00458
00460 static public ParseException generateParseException() {
00461 jj_expentries.clear();
00462 boolean[] la1tokens = new boolean[58];
00463 if (jj_kind >= 0) {
00464 la1tokens[jj_kind] = true;
00465 jj_kind = -1;
00466 }
00467 for (int i = 0; i < 6; i++) {
00468 if (jj_la1[i] == jj_gen) {
00469 for (int j = 0; j < 32; j++) {
00470 if ((jj_la1_0[i] & (1<<j)) != 0) {
00471 la1tokens[j] = true;
00472 }
00473 if ((jj_la1_1[i] & (1<<j)) != 0) {
00474 la1tokens[32+j] = true;
00475 }
00476 }
00477 }
00478 }
00479 for (int i = 0; i < 58; i++) {
00480 if (la1tokens[i]) {
00481 jj_expentry = new int[1];
00482 jj_expentry[0] = i;
00483 jj_expentries.add(jj_expentry);
00484 }
00485 }
00486 int[][] exptokseq = new int[jj_expentries.size()][];
00487 for (int i = 0; i < jj_expentries.size(); i++) {
00488 exptokseq[i] = (int[])jj_expentries.get(i);
00489 }
00490 return new ParseException(token, exptokseq, tokenImage);
00491 }
00492
00494 static final public void enable_tracing() {
00495 }
00496
00498 static final public void disable_tracing() {
00499 }
00500
00501 }