//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// PLEASE DO NOT EDIT WITHOUT THE EXPLICIT CONSENT OF THE AUTHOR! \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\

package hlt.language.syntax;

import java.io.IOException;

/**
 * This is the generic parser that is inherited by all parser classes
 * generated by ParserGenerator for a grammar which does not use any
 * dynamic operator.
 *
 * @see         ParserGenerator
 * @see         GenericParser
 * @see         DynamicParser
 *
 * @version     Last modified on Mon Sep 16 08:16:47 2013 by hak
 * @author      <a href="mailto:hak@acm.org">Hassan A&iuml;t-Kaci</a>
 * @copyright   &copy; <a href="http://www.hassan-ait-kaci.net/">by the author</a>
 */
public abstract class StaticParser extends GenericParser
{
  /**
   * The following are methods used for parsing.
   */
  //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
  //                       PARSING         METHODS                      \\
  //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\

  /**
   * Reads the next token into <tt>tokenNode</tt>.
   */
  final void readToken () throws IOException
    {
      tokenNode = nextToken();
      readTokenFlag = false;
    }

  /**
   * Sets the appropriate parser action for the current token in the current
   * state. If none exists, the parser action is set to the canonical error
   * action.
   */
  final void getParseAction () throws IOException
    {
      parseAction = parseState.getAction((ParserTerminal)tokenNode().symbol());
      if (parseAction == null)
	parseAction = errorAction();
    }

  final void trace (ParserAction a) throws IOException
    {
      traceAction(a);
      step();
    }

  /**
   * Performs the parse action and returns false iff it is an <tt>ACCEPT</tt>
   * action.
   */
  final boolean performParseAction () throws IOException
    {
      switch (parseAction.type)
        {
        case Action.ACCEPT:
          return false;
        case Action.SHIFT:
	  shift();
          break;
        case Action.REDUCE:
	  reduce();
          if (parseState != null)
	    break;
        case Action.ERROR:
	  // System.err.println(">>> A parsing error has occurred ...");
	  recoverFromError();
        }

      return true;
    }
}
