Example #1
0
 /**
  * Parse the input file
  *
  * @return true if the input is a part of the language, false if it is not
  */
 public boolean parse() {
   pTable = new ParseTable();
   boolean notFound = true;
   curState = stack.peek();
   Token next = null;
   int nextState;
   String name = "";
   try {
     while (notFound) {
       next = scanner.scan();
       nextState = pTable.getNextState(curState, next.getP());
       if (nextState == 9999) {
         System.err.println("Error in parsing on line " + scanner.getLine());
         return false;
       } // next state is negative, reduce
       else if (nextState < 0) {
         while (nextState < 0) {
           reduce(nextState);
           nextState = pTable.getNextState(curState, next.getP());
         }
         shift(nextState, next.getP());
         curState = nextState;
       } // next state is positive and not a goto, shift
       else if (nextState > 0) { // took out && nextState < 100
         shift(nextState, next.getP());
         curState = nextState;
       } // next state is accept (only happens in state 6)
       if (nextState == 6) {
         gen.reduce(0);
         return true;
       }
       if (curState == 9999) {
         System.err.println("Error state reached while parsing.");
         System.err.println("Error on line: " + scanner.getLine());
         return false;
       }
     }
   } catch (java.io.IOException ie) {
     ie.printStackTrace();
   } catch (SyntaxError ex) {
     System.err.println("Syntax Error on line " + scanner.getLine() + " while parsing.");
     return false;
   } catch (compiler.CScanner.MaxIDSizeError me) {
     System.err.println(me.getMessage());
     return false;
   }
   return false;
 }