// *******************************************************************
// This file has been automatically generated from the grammar in file
// OsfV0.grm by hlt.language.syntax.ParserGenerator on
// Thu Oct 03 15:42:13 CEST 2013 --- !!! PLEASE DO NO EDIT !!!
// *******************************************************************

package hlt.osf.v0;

import java.io.Reader;
import java.io.StringReader;
import java.io.IOException;
import hlt.language.syntax.*;
import hlt.language.tools.Misc;
import hlt.language.tools.Debug;
import hlt.language.util.Stack;
import hlt.language.util.ArrayList;
import hlt.language.util.IntIterator;
import hlt.language.util.Error;
import hlt.language.util.Span;
import hlt.language.util.Locatable;
import hlt.osf.io.*;
import hlt.osf.base.*;
import hlt.osf.util.*;
import hlt.osf.exec.*;
import hlt.language.io.CircularInclusionException;
import java.util.HashMap;
import java.util.HashSet;
import java.io.PrintStream;
import java.io.FileNotFoundException;


/* ************ */
/* PARSER CLASS */
/* ************ */

public class OsfV0Parser extends StaticParser
{
  /* ************************ */
  /* PARSER CLASS CONSTRUCTOR */
  /* ************************ */

  public OsfV0Parser (Tokenizer t)
    {
      input = t;
      xmlroot = "OsfV0Program";
    }

  /* ************************* */
  /* PARSER CLASS DECLARATIONS */
  /* ************************* */


/* ************************************************************************ */
/* *************************** GLOBAL VARIABLES *************************** */
/* ************************************************************************ */

/* ************************************************************************ */

/**
 * This is the OSF execution context.
 */
  static Context context = new Context(1000000,2,3);

/* ************************************************************************ */

/* ************************************************************************ */
/* ************************** TAXONOMY MANAGEMENT ************************* */
/* ************************************************************************ */

/* ************************************************************************ */

void declareIsa (String s1, String s2) throws LockedCodeArrayException
{
  try
    {
      context.declareIsa(s1,s2,location);
    }
  catch (RuntimeException e)
    {
      logError(new Error().setMsg(e.getMessage()));
    }
}

/* ************************************************************************ */

void processIsaDeclaration (ArrayList lhs, ArrayList rhs)
{
  int lsize = lhs.size();
  int rsize = rhs.size();

  for (int i=0; i<lsize; i++)
    for (int j=0; j<rsize; j++)
      declareIsa((String)lhs.get(i),(String)rhs.get(j));
}

/* ************************************************************************ */

/* ************************************************************************ */
/* ************************* EXPRESSION PROCESSING ************************ */
/* ************************************************************************ */

/* ************************************************************************ */

/**
 * This builds an uninterpreted &psi;-term structure out of the
 * syntactic parts given as arguments as explained in the <a
 * href="#pstconstruc">specification</a>, then interprets its sort
 * expressions in the current context and prints out its interpreted
 * normalized form.
 */
void processPsiTerm (String tag, SortExpression sort, Stack keys, Stack subterms)
{
  PsiTerm pst = buildPsiTerm(new HashSet(),Tag.getTag(tag),sort,keys,subterms);
  try
    {
      time = System.currentTimeMillis();
      displayLine("*** "+pst.displayForm());
      time = System.currentTimeMillis() - time;
      if (Context.isTiming())
	displayLine("*** Processing time = "+time+" ms");
    }
  catch (RuntimeException e)
    {
      logError(new Error().setMsg(e.getMessage()));
    }
}

/**
 * Using the given hash set of tags already associated to previously
 * constructed &psi;-terms, this builds an uninterpreted &psi;-term
 * structure out of the syntactic parts given as arguments as explained
 * in the <a href="#pstconstruc">specification</a>.
 */
PsiTerm buildPsiTerm (HashSet tags, Tag tag, SortExpression sort, Stack keys, Stack subterms)
{
  tag = tag.deref();	// dereference the tag to get to the correct one if needed
  
  PsiTerm pst = null;	// this is the new psiterm to build and return

  // if the tag is a reoccurring tag
  if (tags.contains(tag))	
    {
      // build this term with a new anonymous tag:
      pst = buildPsiTerm(tags,
			 Tag.getTag(null),
			 sort,
			 keys,
			 subterms);
      // // update the tag to its reference (due to possible mergings building pst)
      // tag = tag.deref();
      // retrieve the tag's term, marking the tag as shared (due to the reoccurrence):
      PsiTerm previous = tag.markAsShared().term();
      // merge the two terms and return:
      previous.merge(pst);
      return previous;
    }

  // the tag has not occurred before
  pst = new PsiTerm(tag).setSort(sort);	// construct a new psiterm with the given tag and sort
  tags.add(tag);			// and add the tag to the tag occurrences

  // if there are any subterms
  if (subterms != null) // then keys != null as well
    while (!subterms.empty())
      {
	// get the current raw subterm to build:
	RawPsiTerm sub = (RawPsiTerm)subterms.pop();
	// build the current subterm
	PsiTerm subterm = buildPsiTerm(tags,
				       Tag.getTag(sub.tag),
				       sub.sort,
				       sub.keys,
				       sub.subterms);

	// get the current subterm's key
	Object key = keys.pop();

	// the possibly existing subterm for this key
	PsiTerm existingSubterm = null;

	if (key == null)
	  // this is an implicitly contiguous position
	  {
	    // retrieve the dereferenced possibly existing subterm:
	    existingSubterm = pst.getNextContiguousPositionSubterm();
	    if (existingSubterm == null)
	      pst.addContiguousPositionSubterm(subterm);
	    else
	      subterm.merge(existingSubterm.deref());

	    continue;
	  }

	if (key instanceof Integer)
	  // this is an explicitly specified position
	  {
	    int position = ((Integer)key).intValue();
	    existingSubterm = pst.getSubterm(position);
	    if (existingSubterm == null)
	      pst.setSubterm(position,subterm);
	    else
	      subterm.merge(existingSubterm.deref());

	    continue;
	  }

	// this is a feature subterm
	Feature feature = Feature.getFeature((String)key);

	existingSubterm = pst.getSubterm(feature);
	if (existingSubterm == null)
	  pst.setSubterm(feature,subterm);
	else
	  subterm.merge(existingSubterm.deref());
      }
  
  return pst;    
}

/**
 * This processes a sort expression in the context of an encoded sort
 * taxonomy. Given the current sort context, it compiles it, evaluates
 * it, and prints out the resulting maximal (possibly disjunctive) sort
 * matching the resulting sort code.  If in timing mode, it also reports
 * the processing time in milliseconds.
 */
void processSortExpression (SortExpression expression)
{
  try
    {
      time = System.currentTimeMillis();
      displayLine(// "*** " +
		  (Context.isTracing()
		   ? (expression.displayForm() +
		      // " => "+expression.value().toBitString() +
		      " >= ")
		   : "") +
		  // expression.maxLowerBound());
		  expression.decoded());
      time = System.currentTimeMillis() - time;
      if (Context.isTiming())
	displayLine("*** Processing time = "+time+" ms");
    }
  catch (RuntimeException e)
    {
      logError(new Error().setMsg(e.getMessage()));
    }
}

/* ************************************************************************ */
/* **************************** PRAGMA PROCESSING ************************* */
/* ************************************************************************ */

static boolean isMute, showTree;

static long time;

// etc...

// public final void initialize ()
// {
//   Pragmas.AUTOMATIC = false;
//   // etc ...
// }

/* ************************************************************************ */

/**
 * This calls the method in charge of dispatching which action to take
 * depending of the pragma.  If in timing mode, also reports the
 * processing time in milliseconds.
 */
final void processPragma (String pragma, ArrayList args)
{
  time = System.currentTimeMillis();
  executePragma(pragma,args);
  time = System.currentTimeMillis() - time;
  if (Context.isTiming())
    displayLine("*** %"+pragma+" pragma processing time = "+time+" ms");
}

/**
 * This is the method in charge of dispatching which action to execute
 * for which pragma.
 */
final void executePragma (String pragma, ArrayList args)
{
  setLocation();

  if (pragma == "exit")
    OsfV0Main.exit();

  if (pragma == "include")
    { // This has a bug in that an extra dot at the console is needed to
      // get the prompt.  The origin of this comes from IncludeReader
      // that swallows the IO.EOI at the end of the file being included
      // and as a result the tokenizer's promptIsNeeded returns
      // false. There is no easy way to fix that besides a deep and
      // careful analysis of how the read() method in IncludeReader and
      // the nextToken() nextChar() methods in (Abstract)StreamTokenizer
      // work. For now, keep it as it is. However, when we enter:
      // '%include "foo.osf". %encode.' on the same line, this works as
      // expected and we get the prompt.
      includeFiles((Stack)args);
      return;
    }

  if (pragma == "encode")
    {
      displaySize();
      encodeSorts();
      return;
    }	

  if (pragma == "save")
    {
      saveTaxonomy((Stack)args);
      return;
    }	

  if (pragma == "load")
    {
      loadTaxonomy((Stack)args);
      return;
    }	

  if (pragma == "enumsize")
    {
      displayLine("*** Sort enumeration size set to "+Decoded.enumSize());
      return;
    }	

  if (pragma == "size")
    {
      displaySize();
      return;
    }	

  if (pragma == "sorts")
    {
      displaySorts();
      return;
    }	

  if (pragma == "last")
    {
      displayLastExpression();
      return;
    }	

  // if (pragma == "height")
  //   {
  //     computeHeight(arg1);
  //     return;
  //   }	

  if (pragma == "cleartags")
    {
      Tag.clearKnownTags();
      displayLine("*** Cleared all known tags");
      return;
    }	

  if (pragma == "clear")
    {
      Tag.clearKnownTags();
      context.reset();
      displayLine("*** The sort taxonomy has been cleared ("+
		  (context.taxonomy().size())+" sorts defined)");
      return;
    }	

  if (pragma == "parents")
    {
      displayParents((SortExpression)args.get(0));
      return;
    }

  if (pragma == "children")
    {
      displayChildren((SortExpression)args.get(0));
      return;
    }

  if (pragma == "descendants")
    {
      showDescendants((SortExpression)args.get(0));
      return;
    }	

  if (pragma == "ancestors")
    {
      showAncestors((SortExpression)args.get(0));
      return;
    }	

  if (pragma == "evaluate")
    {
      PsiTerm.toggleSortEvaluation();
      if (!isMute)
	display("Sort expression evaluation has been turned "
	       +(PsiTerm.evaluateSorts() ? "on" : "off")+"...\n");
      return;
    }

  if (pragma == "mute")
    {
      isMute = !isMute;
      display("Muted output has been turned "+(isMute ? "on" : "off")+"...\n");
      if (isMute) displayLine("*** ...");
      return;
    }

  if (pragma == "tree")
    {
      parseTreeType = (showTree = !showTree) ? COMPACT_TREE : NO_TREE;
      display("Parse tree display has been turned "+(showTree ? "on" : "off")+"...\n");
      return;
    }

  if (pragma == "time")
    {
      Context.toggleTiming();
      displayLine("*** Processing timing has been turned "+(Context.isTiming() ? "on" : "off")+"...");
      return;
    }

  if (pragma == "trace")
    {
      if (isMute)
	{
	  display("Cannot trace evaluation in mute mode; turn mute mode off with '%mute.'");
	  return;
	}
      
      Context.toggleTracing();
      display("Execution tracing has been turned "+(Context.isTracing() ? "on" : "off")+"...\n");
      return;
    }

  if (pragma == "gc")
    {
      display("\n");
      Misc.forceGC(!isMute,dm.getOutputStream());
      return;
    }

  if (pragma == "syntax")
    {
      toggleTrace();
      display("Parser trace has been turned "+(tracingIsOn() ? "on" : "off")+"...\n");
      return;
    }

  if (pragma == "help")
    {
      helpPragma();
      return;
    }

  displayLine("*** Unknown pragma: '%"+pragma+"' (ignored) - type '%help.' for known pragmas.");
}

/* ************************************************************************ */

/**
 * Given a sort expression, this will display its parents in the current
 * taxonomy. 
 */
final void displayParents (SortExpression exp)
{
  try
    {
      // if this is only a sort symbol, just display its parents:
      if (exp.isSymbol())
	{
	  displayParents(context.getSort(((SymbolSortExpression)exp).name()));
	  return;
	}

      // otherwise, evaluate the expression, decode the value, and
      // display its least upper bounds:
      displayLine("*** "+displayForm(context.decodedValue(exp.value()).lubs(),true));
    }
  catch (RuntimeException e)
    {
      logError(new Error().setMsg(e.getMessage()));
    }
}

/* ************************************************************************ */

final void displayParents (Sort sort)
{
  if (sort.isTop())
    displayLine("*** "+dfm.displayTopForm());
  else
    displayLine("*** "+displayForm(sort.parents(),true));
}

/* ************************************************************************ */

/**
 * Given a sort expression, this will display its children in the current
 * taxonomy. 
 */
final void displayChildren (SortExpression exp)
{
  try
    {
      // if this is only a sort symbol, just display its children:
      if (exp.isSymbol())
	{
	  displayChildren(context.getSort(((SymbolSortExpression)exp).name()));
	  return;
	}

      // otherwise, evaluate the expression, decode the value, and
      // display its maximal lower bounds:
      displayLine("*** "+displayForm(context.decodedValue(exp.value()).mlbs(),false));
    }
  catch (RuntimeException e)
    {
      logError(new Error().setMsg(e.getMessage()));
    }
}

/* ************************************************************************ */

final void displayChildren (Sort sort)
{
  if (sort.isBottom())
    displayLine("*** "+dfm.displayBottomForm());
  else
    displayLine("*** "+displayForm(sort.children(),false));
}

/* ************************************************************************ */

/**
 * This loads the stack of files whose names are in the specified
 * stack. Each file should contain OSF V0 declarations or expressions.
 */
final void includeFiles (Stack files)
{
  if (files == null || files.isEmpty())
    {
      logError(syntaxError("missing file arguments in %include pragma",location));
      return;
    }

  while (!files.isEmpty())
    {
      String fileName = (String)files.pop();

      try
	{
	  displayLine("*** Reading from file: "+fileName);
	  ((OsfV0Tokenizer)input).include(fileName);
	}
      catch (FileNotFoundException e)
	{
	  logError(syntaxError("file not found: "+fileName,location));
	}
      catch (CircularInclusionException e)
	{
	  logError(syntaxError("circular file inclusion of file: "+fileName,location));
	}
      catch (RuntimeException e)
	{
	  logError(new Error().setMsg(e.getMessage()));
	}
    }
}

/* ************************************************************************ */

/**
 * This saves the currently encoded taxonomy into the file whose name is
 * in the specified stack.
 */
final void saveTaxonomy (Stack files)
{
  if (files == null || files.isEmpty())
    {
      logError(syntaxError("missing file arguments in %save pragma",location));
      return;
    }

  if (!context.taxonomy().isLocked())
    {
      logError(syntaxError("cannot save a non-encoded taxonomy",location));
      return;
    }

  while (!files.isEmpty())
    {
      String fileName = (String)files.pop();
      displayLine("*** Saving encoded taxonomy into file: "+fileName);

      try
	{
	  context.taxonomy().save(fileName);
	}
      catch (FileNotFoundException e)
	{
	  logError(syntaxError("file not found: "+fileName,location));
	}

      displayLine("*** "+(context.taxonomy().size()-1)+" encoded sorts saved into file: "+fileName);
    }
}

/* ************************************************************************ */

/**
 * This loads an encoded taxonomy from the file whose name is in the
 * specified stack.
 */
final void loadTaxonomy (Stack files)
{
  if (files == null || files.isEmpty())
    {
      logError(syntaxError("missing file arguments in %load pragma",location));
      return;
    }

  if (context.taxonomy().isLocked())
    {
      logError(syntaxError("there is already an encoded taxonomy - use %clear if you wish to load a new taxonomy",location));
      return;
    }

  while (!files.isEmpty())
    {
      String fileName = (String)files.pop();
      displayLine("*** Loading encoded taxonomy from file: "+fileName);

      try
	{
	  context.taxonomy().load(fileName);
	}
      catch (FileNotFoundException e)
	{
	  logError(syntaxError("file not found: "+fileName,location));
	}
      catch (IOException e)
	{
	  logError(syntaxError("IO error while loading: "+fileName,location));
	}

      displayLine("*** "+(context.taxonomy().size()-1)+" encoded sorts loaded from file: "+fileName);
    }
}

/* ************************************************************************ */

void displayLastExpression ()
{
  try
    {
      SortExpression expression = context.lastExpression();
      displayLine("*** "+expression.displayForm()+"  ==>  "+expression.maxLowerBound());      
    }
  catch (RuntimeException e)
    {
      logError(new Error().setMsg(e.getMessage()));
    }
}

/* ************************************************************************ */

// void computeHeight (String sort)
// {
//   try
//     {
//       displayLine("*** The height of "+sort+" is "+context.getSort(sort).height());
//     }
//   catch (RuntimeException e)
//     {
//       logError(new Error().setMsg(e.getMessage()));
//     }
// }

/* ************************************************************************ */

void showAncestors (SortExpression exp)
{
  try
    {
      // if this is only a sort symbol, just display its ancestors:
      if (exp.isSymbol())
	{
	  Sort sort = context.getSort(((SymbolSortExpression)exp).name());
	  displayLine("*** "+displayForm(sort.ancestors(),true));
	  return;
	}

      // otherwise, evaluate and decode the expression, and get its ancestors:
      HashSet ancestors = context.decodedValue(exp.value()).ancestors(context.taxonomy());

      displayLine("*** "+displayForm(ancestors,true));
    }
  catch (RuntimeException e)
    {
      logError(new Error().setMsg(e.getMessage()));
    }
}

/* ************************************************************************ */

void showDescendants (SortExpression exp)
{
  try
    {
      // if this is only a sort symbol, just display its descendants:
      if (exp.isSymbol())
	{
	  Sort sort = context.getSort(((SymbolSortExpression)exp).name());
	  displayLine("*** "+displayForm(sort.descendants(),false));
	  return;
	}

      // otherwise, evaluate and decode the expression, and get its descendants:
      HashSet descendants = context.decodedValue(exp.value()).descendants(context.taxonomy());

      displayLine("*** "+displayForm(descendants,false));
    }
  catch (RuntimeException e)
    {
      logError(new Error().setMsg(e.getMessage()));
    }
}

/* ************************************************************************ */

/**
 * This encodes the sorts declared thus far and locks the sort taxonomy;
 * (<i>i.e.</i>, no new sorts may be declared until this taxononmy has
 * been cleared (see the '<tt>%clear</tt>' pragma).
 */
void encodeSorts ()
{
  try
    {
      context.encodeSorts();
      displayLine("*** The sort taxonomy has been encoded ("+
		  (context.taxonomy().size()-1)+" sorts defined)");
    }
  catch (CyclicSortOrderingException e)
    {
      logError(new Error().setSee("").setMsg(e.getMessage()));
      _criticalError = true;
    }
  catch (RuntimeException e)
    {
      logError(new Error().setMsg(e.getMessage()));
    }
}  

/* ************************************************************************ */

final void helpPragma ()
{
  displayLine("*** Known pragmas (all must be followed by a period - '.'):");
  displayLine("\t------------  ------");
  displayLine("\t      PRAGMA  EFFECT");
  displayLine("\t------------  ------");

  displayLine("\t       %exit  exit session");

  displayLine("\t    %include  read the unclassified ontology from the given file (name specified as a quoted string)");
  displayLine("\t     %encode  classify the current ontology");
  displayLine("\t       %save  save a classified ontology into the given file (name specified as a quoted string)");
  displayLine("\t       %load  read a saved classified ontology from the given file (name specified as a quoted string)");

  displayLine("\t       %size  print the number of symbols in the current sort taxonomy");
  displayLine("\t      %sorts  display the codes of all symbols in current sort taxonomy");
  displayLine("\t    %defined  list all the non-built-in sorts symbols in the current taxonomy");
  displayLine("\t   %builtins  list all the sorts symbols in the current taxonomy");
  displayLine("\t      %clear  erase the codes of all symbols in the current sort taxonomy");

  displayLine("\t   %evaluate  toggle on/off automatic sort evaluation");
  displayLine("\t       %time  toggle on/off execution time reporting");
  displayLine("\t  %automatic  toggle on/off automatic sort encoding");
  displayLine("\t       %mute  toggle on/off intermediate displays");

  displayLine("\t       %last  print the last evaluated sort expression and its maximal lower bound sort(s)");

  displayLine("\t     %height  print the height of the specified sort (size of longest is-a chain from it to {})");
  displayLine("\t      %width  print the size of the widest maximal antichain containing the specified sort");

  displayLine("\t   %children  print the set of maximal strict lower bounds of the specified sort");
  displayLine("\t%descendants  print the set of strict lower bounds of the specified sort");
  displayLine("\t    %parents  print the set of minimal strict upper bounds of the specified sort");
  displayLine("\t  %ancestors  print the set of strinct upper bounds of the specified sort");
  displayLine("\t   %enumsize  set number of symbols to display in sort enumerations");


  displayLine("\t        %isa  check whether the first specified sort is a subsort of the second one");

  displayLine("\t       %tree  toggle on/off graphical display of syntax tree");
  displayLine("\t         %gc  force immediate garbage collection");
  displayLine("\t     %syntax  toggle on/off parser tracing");
  displayLine("\t      %trace  toggle on/off evaluation tracing");
  displayLine("\t       %help  list this information");
  newLine();
}

/* ************************************************************************ */
/* ************************** DISPLAY MANAGEMENT ************************** */
/* ************************************************************************ */

/**
 * The display manager.
 */
static DisplayManager dm = context.displayManager();

/**
 * The display form manager.
 */
static DisplayFormManager dfm = dm.displayFormManager();

/* ************************************************************************ */

/**
 * Redirect the output to the specified PrintStream.
 */
public final void setOutputStream (PrintStream stream)
{
  dm.setOutputStream(stream);
}

/* ************************************************************************ */

/**
 * Returns the display form of the given sort.
 */
String displayForm (Sort sort)
{
  return dfm.displaySortForm(sort);
}

/* ************************************************************************ */

/**
 * Returns the display form of set of sorts represented by the specified BitCode.
 */
String displayForm (BitCode sorts)
{
  return dfm.displaySortsForm(sorts,context.taxonomy());
}
/* ************************************************************************ */

/**
 * Returns the display form of the given hash set of sorts.
 */
String displayForm (HashSet sorts, boolean upper)
{
  return dfm.displayForm(sorts,upper);
}


/* ************************************************************************ */

/**
 * Displays the number of declared sorts on the display manager's output stream.
 */
void displaySize ()
{
  try
    {
      displayLine("*** There are "+context.taxonomy().size()+" sorts defined");
    }
  catch (RuntimeException e)
    {
      logError(new Error().setMsg(e.getMessage()));
    }
}

/* ************************************************************************ */

/**
 * Displays the declared sorts on the display manager's output stream.
 */
void displaySorts ()
{
  try
    {
      displayLine("*** Declared sorts:");
      context.taxonomy().showSortCodes();
      displayLine("*** "+(context.taxonomy().size()-1)+" sorts defined");
    }
  catch (RuntimeException e)
    {
      logError(new Error().setMsg(e.getMessage()));
    }
}

/* ************************************************************************ */

/**
 * If not in mute mode, displays the specified string on the display manager's
 * output stream.
 */
final void display (String s)
{
  if (isMute)
    return;

  dm.print(s);
}

/* ************************************************************************ */

/**
 * If not in mute mode, displays the specified string on the display manager's
 * output stream, and ends it with a newline.
 */
static final void displayLine (String s)
{
  if (isMute)
    return;

  dm.println(s);
}

/* ************************************************************************ */

/**
 * Outputs a newline on the display manager's output stream.
 */
final void newLine ()
{
  dm.println();
}


/* ************************************************************************ */
/* *************************** ERROR MANAGEMENT *************************** */
/* ************************************************************************ */

/* ************************************************************************ */

/**
 * This parser's error log.
 */
ErrorLogger errorLogger = context.errorLogger();

/**
 * Records the specified Error in this parser's error log.
 */
final void logError (Error error)
{
  errorLogger.recordError(error);
}

/**
 * When this is true, a context reset is called for upon reporting errors.
 */
private boolean _criticalError = false;

/**
 * When at top level, displays all the errors recorded in the error log
 * and clears it.
 */
void reportErrors ()
{
  if (((OsfV0Tokenizer)input).reader.depth() > 0)
    return;

  int size = errorLogger.size();
  int errorNo = 0;
  int warningNo = 0;

  for (int i=0; i<size; i++)
    {
      Error error = errorLogger.getError(i);
      displayLine(error.toString());
      if (error.isWarning())
	warningNo++;
      else
	errorNo++;
    }

  if (warningNo > 0)
    displayLine("*** There "+(warningNo==1 ? "was " : "were ")+warningNo+" warning"+(warningNo>1 ? "s" : ""));
  if (errorNo > 0)
    displayLine("*** There "+(errorNo==1 ? "was " : "were ")+errorNo+" error"+(errorNo>1 ? "s" : ""));

  if (_criticalError)
    {
      displayLine("*** Resetting context...");
      context.reset();
      _criticalError = false;
    }

  errorLogger.clearErrors();
}

/* ************************************************************************ */

/* ************************************************************************ */

/**
 * This is used for recording the location of syntactic constructs in the
 * input stream in order to locate where potential errors occur.
 */
Locatable location;

/* ************************************************************************ */

/**
 * Returns a syntax error object with specified message.
 */
final Error syntacticError (String msg)
{
  return new Error().setLabel("Syntax Error: ").setMsg(msg);
}

/* ************************************************************************ */

/**
 * Returns a syntax error object with specified message, and situated
 * as the specifed <tt>Locatable</tt> extent.
 */
final Error syntacticError (String msg, Locatable extent)
{
  return syntacticError(msg).setExtent(extent);
}

/* ************************************************************************ */

/**
 * Returns an evaluation error object with specified message.
 */
final Error evaluationError (String msg)
{
  return new Error().setLabel("Evaluation Error: ").setMsg(msg);
}

/* ************************************************************************ */

/**
 * Returns an evaluation error object with specified message,
 * and situated as the specifed <tt>Locatable</tt> extent.
 */
final Error evaluationError (String msg, Locatable extent)
{
  return evaluationError(msg).setExtent(extent);
}

/* ************************************************************************ */

// /**
//  * This method is used to situate an expression's abstract syntax with respect
//  * to its concrete syntax origin (specified as the given <tt>Locatable</tt>).
//  */
// final Expression locate (Expression e, Locatable l)
// {
//   return e.setExtent(l);
// }

// /**
//  * This method is used to situate an expression's abstract syntax with the
//  * extent of the latest <tt>location</tt>.
//  */
// final Expression locate (Expression e)
// {
//   return e.setExtent(location);
// }

// final Expression locateSymbol (ParseNode node)
// {
//   return locate(symbol(node.svalue()),node);
// }

/* ************************************************************************ */

/**
 * Prints out a prompt if needed for interactive input.
 */
final void prompt ()
{
  ((OsfV0Tokenizer)input).prompt();
}

/**
 * Reports errors if any and, if interactive, prompts the user for more
 * input.
 */
final void commitParse ()
{
  reportErrors();
  prompt();
}

/* ************************************************************************ */

/**
 * Sets the location to that of the specified <tt>Locatable</tt>.
 */
final void setLocation (Locatable locatable)
{
  location = locatable;
}

/* ************************************************************************ */

/**
 * Sets the location to that of the current parse node (<i>i.e.</i>, the node
 * currently at the top of the parse stack).
 */
final void setLocation ()
{
  setLocation(currentNode());
}

/* ************************************************************************ */



  /* ********************** */
  /* STATIC INITIALIZATIONS */
  /* ********************** */

  static
    {
      initializeTerminals();
      initializeNonTerminals();
      initializeRules();
      initializeParserActions();
      initializeParserStates();
      initializeActionTables();
      initializeGotoTables();
      initializeStateTables();
    }

  /* ********************* */
  /* PARTIAL PARSE METHODS */
  /* ********************* */

  final static ParseNode $OSFV0PROGRAM_SWITCH$ = new ParseNode(terminals[3]);

  public final void parseOsfV0Program (String s) throws IOException
    {
      parseOsfV0Program(new StringReader(s));
    }

  public final void parseOsfV0Program (Reader r) throws IOException
    {
      input.setReader(r);
      errorManager().recoverFromErrors(false);
      setSwitchToken($OSFV0PROGRAM_SWITCH$);
      parse();
    }

  final static ParseNode $SORTEXPRESSION_SWITCH$ = new ParseNode(terminals[4]);

  public final void parseSortExpression (String s) throws IOException
    {
      parseSortExpression(new StringReader(s));
    }

  public final void parseSortExpression (Reader r) throws IOException
    {
      input.setReader(r);
      errorManager().recoverFromErrors(false);
      setSwitchToken($SORTEXPRESSION_SWITCH$);
      parse();
    }

  /* **************** */
  /* SEMANTIC ACTIONS */
  /* **************** */

  protected ParseNode semanticAction(ParserRule $rule$) throws IOException
    {
      ParseNode $head$ = new ParseNode($rule$.head);

      switch($rule$.index())
        {
          case 2:
            {
            $head$ = $head$.copy(node($rule$,2));
            break;
            }
          case 3:
            {
            $head$ = $head$.copy(node($rule$,2));
            break;
            }
          case 8:
            {
            commitParse();
            break;
            }
          case 11:
            {
            OsfV0PragmaArguments_opt $node2$;
                if (node($rule$,2) instanceof OsfV0PragmaArguments_opt)
                   $node2$ = (OsfV0PragmaArguments_opt)node($rule$,2);
                 else
                 {
                     $node2$ = new OsfV0PragmaArguments_opt(node($rule$,2));
                     replaceStackNode($rule$,2,$node2$);
                   }

        processPragma(node($rule$,1).svalue().intern(),$node2$.args);
            break;
            }
          case 15:
            {
            OsfV0IsaDeclarationStatement $node1$;
                if (node($rule$,1) instanceof OsfV0IsaDeclarationStatement)
                   $node1$ = (OsfV0IsaDeclarationStatement)node($rule$,1);
                 else
                 {
                     $node1$ = new OsfV0IsaDeclarationStatement(node($rule$,1));
                     replaceStackNode($rule$,1,$node1$);
                   }

        setLocation();
        processIsaDeclaration($node1$.lhs,$node1$.rhs);
            break;
            }
          case 16:
            {
            OsfV0IsaDeclarationStatement $node0$ = new OsfV0IsaDeclarationStatement($head$);
                 $head$ = (OsfV0IsaDeclarationStatement)$node0$;
    OsfV0SortSymbols $node1$;
                if (node($rule$,1) instanceof OsfV0SortSymbols)
                   $node1$ = (OsfV0SortSymbols)node($rule$,1);
                 else
                 {
                     $node1$ = new OsfV0SortSymbols(node($rule$,1));
                     replaceStackNode($rule$,1,$node1$);
                   }
    OsfV0SortSymbols $node3$;
                if (node($rule$,3) instanceof OsfV0SortSymbols)
                   $node3$ = (OsfV0SortSymbols)node($rule$,3);
                 else
                 {
                     $node3$ = new OsfV0SortSymbols(node($rule$,3));
                     replaceStackNode($rule$,3,$node3$);
                   }

        $node0$.lhs = $node1$.symbols;
        $node0$.rhs = $node3$.symbols;
            break;
            }
          case 18:
            {
            OsfV0SortSymbols $node0$ = new OsfV0SortSymbols($head$);
                 $head$ = (OsfV0SortSymbols)$node0$;

        $node0$.symbols = new Stack();
        $node0$.symbols.push(node($rule$,1).svalue());
            break;
            }
          case 19:
            {
            OsfV0SortSymbols $node0$ = new OsfV0SortSymbols($head$);
                 $head$ = (OsfV0SortSymbols)$node0$;
    OsfV0SortSymbols $node3$;
                if (node($rule$,3) instanceof OsfV0SortSymbols)
                   $node3$ = (OsfV0SortSymbols)node($rule$,3);
                 else
                 {
                     $node3$ = new OsfV0SortSymbols(node($rule$,3));
                     replaceStackNode($rule$,3,$node3$);
                   }

        ($node0$.symbols = $node3$.symbols).push(node($rule$,1).svalue());
            break;
            }
          case 20:
            {
            OsfV0SortExpression $node1$;
                if (node($rule$,1) instanceof OsfV0SortExpression)
                   $node1$ = (OsfV0SortExpression)node($rule$,1);
                 else
                 {
                     $node1$ = new OsfV0SortExpression(node($rule$,1));
                     replaceStackNode($rule$,1,$node1$);
                   }

        processSortExpression($node1$.expression);
            break;
            }
          case 21:
            {
            OsfV0SortExpression $node0$ = new OsfV0SortExpression($head$);
                 $head$ = (OsfV0SortExpression)$node0$;

        $node0$.expression = new SymbolSortExpression(node($rule$,1).svalue(),context);
            break;
            }
          case 22:
            {
            OsfV0SortExpression $node0$ = new OsfV0SortExpression($head$);
                 $head$ = (OsfV0SortExpression)$node0$;
    OsfV0SortList $node2$;
                if (node($rule$,2) instanceof OsfV0SortList)
                   $node2$ = (OsfV0SortList)node($rule$,2);
                 else
                 {
                     $node2$ = new OsfV0SortList(node($rule$,2));
                     replaceStackNode($rule$,2,$node2$);
                   }

        $node0$.expression = new DisjunctiveSortExpression($node2$.sortList,context);
            break;
            }
          case 23:
            {
            OsfV0SortExpression $node0$ = new OsfV0SortExpression($head$);
                 $head$ = (OsfV0SortExpression)$node0$;
    OsfV0SortExpression $node2$;
                if (node($rule$,2) instanceof OsfV0SortExpression)
                   $node2$ = (OsfV0SortExpression)node($rule$,2);
                 else
                 {
                     $node2$ = new OsfV0SortExpression(node($rule$,2));
                     replaceStackNode($rule$,2,$node2$);
                   }

        $node0$.expression = new NotSortExpression($node2$.expression);
            break;
            }
          case 24:
            {
            OsfV0SortExpression $node0$ = new OsfV0SortExpression($head$);
                 $head$ = (OsfV0SortExpression)$node0$;
    OsfV0SortExpression $node1$;
                if (node($rule$,1) instanceof OsfV0SortExpression)
                   $node1$ = (OsfV0SortExpression)node($rule$,1);
                 else
                 {
                     $node1$ = new OsfV0SortExpression(node($rule$,1));
                     replaceStackNode($rule$,1,$node1$);
                   }
    OsfV0SortExpression $node3$;
                if (node($rule$,3) instanceof OsfV0SortExpression)
                   $node3$ = (OsfV0SortExpression)node($rule$,3);
                 else
                 {
                     $node3$ = new OsfV0SortExpression(node($rule$,3));
                     replaceStackNode($rule$,3,$node3$);
                   }

        $node0$.expression = new AndSortExpression($node1$.expression,$node3$.expression);
            break;
            }
          case 25:
            {
            OsfV0SortExpression $node0$ = new OsfV0SortExpression($head$);
                 $head$ = (OsfV0SortExpression)$node0$;
    OsfV0SortExpression $node1$;
                if (node($rule$,1) instanceof OsfV0SortExpression)
                   $node1$ = (OsfV0SortExpression)node($rule$,1);
                 else
                 {
                     $node1$ = new OsfV0SortExpression(node($rule$,1));
                     replaceStackNode($rule$,1,$node1$);
                   }
    OsfV0SortExpression $node3$;
                if (node($rule$,3) instanceof OsfV0SortExpression)
                   $node3$ = (OsfV0SortExpression)node($rule$,3);
                 else
                 {
                     $node3$ = new OsfV0SortExpression(node($rule$,3));
                     replaceStackNode($rule$,3,$node3$);
                   }

        $node0$.expression = new OrSortExpression($node1$.expression,$node3$.expression);
            break;
            }
          case 26:
            {
            OsfV0SortExpression $node0$ = new OsfV0SortExpression($head$);
                 $head$ = (OsfV0SortExpression)$node0$;
    OsfV0SortExpression $node1$;
                if (node($rule$,1) instanceof OsfV0SortExpression)
                   $node1$ = (OsfV0SortExpression)node($rule$,1);
                 else
                 {
                     $node1$ = new OsfV0SortExpression(node($rule$,1));
                     replaceStackNode($rule$,1,$node1$);
                   }
    OsfV0SortExpression $node3$;
                if (node($rule$,3) instanceof OsfV0SortExpression)
                   $node3$ = (OsfV0SortExpression)node($rule$,3);
                 else
                 {
                     $node3$ = new OsfV0SortExpression(node($rule$,3));
                     replaceStackNode($rule$,3,$node3$);
                   }

        $node0$.expression = new ButnotSortExpression($node1$.expression,$node3$.expression);
            break;
            }
          case 27:
            {
            OsfV0SortExpression $node0$ = new OsfV0SortExpression($head$);
                 $head$ = (OsfV0SortExpression)$node0$;
    OsfV0SortExpression $node2$;
                if (node($rule$,2) instanceof OsfV0SortExpression)
                   $node2$ = (OsfV0SortExpression)node($rule$,2);
                 else
                 {
                     $node2$ = new OsfV0SortExpression(node($rule$,2));
                     replaceStackNode($rule$,2,$node2$);
                   }

        $node0$.expression = $node2$.expression.setParenthesized(true);
            break;
            }
          case 31:
            {
            OsfV0SortList $node0$ = new OsfV0SortList($head$);
                 $head$ = (OsfV0SortList)$node0$;

        $node0$.sortList = new Stack();
        $node0$.sortList.push(node($rule$,1).svalue());
            break;
            }
          case 32:
            {
            OsfV0SortList $node0$ = new OsfV0SortList($head$);
                 $head$ = (OsfV0SortList)$node0$;
    OsfV0SortList $node3$;
                if (node($rule$,3) instanceof OsfV0SortList)
                   $node3$ = (OsfV0SortList)node($rule$,3);
                 else
                 {
                     $node3$ = new OsfV0SortList(node($rule$,3));
                     replaceStackNode($rule$,3,$node3$);
                   }

        ($node0$.sortList = $node3$.sortList).push(node($rule$,1).svalue());
            break;
            }
          case 35:
            {
            Decoded.setEnumSize((int)node($rule$,1).nvalue());
            break;
            }
          case 36:
            {
            OsfV0PragmaArguments_opt $node0$ = new OsfV0PragmaArguments_opt($head$);
                 $head$ = (OsfV0PragmaArguments_opt)$node0$;
    OsfV0FileList $node1$;
                if (node($rule$,1) instanceof OsfV0FileList)
                   $node1$ = (OsfV0FileList)node($rule$,1);
                 else
                 {
                     $node1$ = new OsfV0FileList(node($rule$,1));
                     replaceStackNode($rule$,1,$node1$);
                   }

        $node0$.args = $node1$.files;
            break;
            }
          case 37:
            {
            OsfV0PragmaArguments_opt $node0$ = new OsfV0PragmaArguments_opt($head$);
                 $head$ = (OsfV0PragmaArguments_opt)$node0$;
    OsfV0SortExpression $node1$;
                if (node($rule$,1) instanceof OsfV0SortExpression)
                   $node1$ = (OsfV0SortExpression)node($rule$,1);
                 else
                 {
                     $node1$ = new OsfV0SortExpression(node($rule$,1));
                     replaceStackNode($rule$,1,$node1$);
                   }

        $node0$.args = new ArrayList(1);
        $node0$.args.add($node1$.expression);
            break;
            }
          case 38:
            {
            OsfV0PragmaArguments_opt $node0$ = new OsfV0PragmaArguments_opt($head$);
                 $head$ = (OsfV0PragmaArguments_opt)$node0$;
    OsfV0SortExpression $node1$;
                if (node($rule$,1) instanceof OsfV0SortExpression)
                   $node1$ = (OsfV0SortExpression)node($rule$,1);
                 else
                 {
                     $node1$ = new OsfV0SortExpression(node($rule$,1));
                     replaceStackNode($rule$,1,$node1$);
                   }
    OsfV0SortExpression $node2$;
                if (node($rule$,2) instanceof OsfV0SortExpression)
                   $node2$ = (OsfV0SortExpression)node($rule$,2);
                 else
                 {
                     $node2$ = new OsfV0SortExpression(node($rule$,2));
                     replaceStackNode($rule$,2,$node2$);
                   }

        $node0$.args = new ArrayList(2);
        $node0$.args.add($node1$.expression);
        $node0$.args.add($node2$.expression);
            break;
            }
          case 39:
            {
            OsfV0FileList $node0$ = new OsfV0FileList($head$);
                 $head$ = (OsfV0FileList)$node0$;

        $node0$.files = new Stack();
        $node0$.files.push(node($rule$,1).svalue());
            break;
            }
          case 40:
            {
            OsfV0FileList $node0$ = new OsfV0FileList($head$);
                 $head$ = (OsfV0FileList)$node0$;
    OsfV0FileList $node2$;
                if (node($rule$,2) instanceof OsfV0FileList)
                   $node2$ = (OsfV0FileList)node($rule$,2);
                 else
                 {
                     $node2$ = new OsfV0FileList(node($rule$,2));
                     replaceStackNode($rule$,2,$node2$);
                   }

        ($node0$.files = $node2$.files).push(node($rule$,1).svalue());
            break;
            }
          case 0: case 1: case 5: case 10: case 34: 
            break;
          default:
            $head$ = $head$.copy(node($rule$,1));
            break;
        }
      return $head$;
    }

  /* **************** */
  /* TERMINAL SYMBOLS */
  /* **************** */

  static void initializeTerminals ()
    {
      terminals = new ParserTerminal[23];

      newTerminal(0,"$EMPTY$",1,2);
      newTerminal(1,"$E_O_I$",1,2);
      newTerminal(2,"error",1,2);
      newTerminal(3,"$OsfV0Program_switch$",1,2);
      newTerminal(4,"$SortExpression_switch$",1,2);
      newTerminal(5,"EOS",1,2);
      newTerminal(6,"IDENTIFIER",11,2);
      newTerminal(7,"PRAGMA",11,2);
      newTerminal(8,"STRING",11,2);
      newTerminal(9,"TOP",11,2);
      newTerminal(10,"BOTTOM",11,2);
      newTerminal(11,"INTEGER",11,2);
      newTerminal(12,"ISA",21,2);
      newTerminal(13,"BUTNOT",31,1);
      newTerminal(14,"OR",41,0);
      newTerminal(15,"AND",51,0);
      newTerminal(16,"NOT",61,1);
      newTerminal(17,",",1,2);
      newTerminal(18,"{",1,2);
      newTerminal(19,"}",1,2);
      newTerminal(20,"(",1,2);
      newTerminal(21,")",1,2);
      newTerminal(22,";",1,2);
    }

  /* ******************** */
  /* NON-TERMINAL SYMBOLS */
  /* ******************** */

  static void initializeNonTerminals ()
    {
      nonterminals = new ParserNonTerminal[19];

      newNonTerminal(0,"$START$");
      newNonTerminal(1,"$ROOTS$");
      newNonTerminal(2,"OsfV0Program");
      newNonTerminal(3,"SortExpression");
      newNonTerminal(4,"IsaDeclarationStatement");
      newNonTerminal(5,"SortSymbols");
      newNonTerminal(6,"SortList");
      newNonTerminal(7,"PragmaArguments_opt");
      newNonTerminal(8,"FileList");
      newNonTerminal(9,"Statements_opt");
      newNonTerminal(10,"Statement");
      newNonTerminal(11,"StatementType");
      newNonTerminal(12,"EndOfStatement");
      newNonTerminal(13,"$ACTION0$");
      newNonTerminal(14,"Pragma");
      newNonTerminal(15,"SortDeclarationStatement");
      newNonTerminal(16,"OsfExpression");
      newNonTerminal(17,"SortSymbol");
      newNonTerminal(18,"Sort");
    }

  /* **************** */
  /* PRODUCTION RULES */
  /* **************** */

  static void initializeRules ()
    {
      rules = new ParserRule[41];

      rules[0] = new ParserRule(0,1,0,1,2);
      rules[1] = new ParserRule(1,1,1,1,2);
      rules[2] = new ParserRule(1,2,2,1,2);
      rules[3] = new ParserRule(1,2,3,1,2);
      rules[4] = new ParserRule(2,1,4,1,2);
      rules[5] = new ParserRule(9,0,5,1,2);
      rules[6] = new ParserRule(9,2,6,1,2);
      rules[7] = new ParserRule(10,2,7,1,2);
      rules[8] = new ParserRule(13,0,8,1,2);
      rules[9] = new ParserRule(12,2,9,1,2);
      rules[10] = new ParserRule(11,0,10,1,2);
      rules[11] = new ParserRule(11,2,11,1,2);
      rules[12] = new ParserRule(11,1,12,1,2);
      rules[13] = new ParserRule(11,1,13,1,2);
      rules[14] = new ParserRule(11,1,14,1,2);
      rules[15] = new ParserRule(15,1,15,1,2);
      rules[16] = new ParserRule(4,3,16,21,2);
      rules[17] = new ParserRule(17,1,17,11,2);
      rules[18] = new ParserRule(5,1,18,1,2);
      rules[19] = new ParserRule(5,3,19,1,2);
      rules[20] = new ParserRule(16,1,20,1,2);
      rules[21] = new ParserRule(3,1,21,1,2);
      rules[22] = new ParserRule(3,3,22,1,2);
      rules[23] = new ParserRule(3,2,23,61,1);
      rules[24] = new ParserRule(3,3,24,51,0);
      rules[25] = new ParserRule(3,3,25,41,0);
      rules[26] = new ParserRule(3,3,26,31,1);
      rules[27] = new ParserRule(3,3,27,1,2);
      rules[28] = new ParserRule(18,1,28,11,2);
      rules[29] = new ParserRule(18,1,29,11,2);
      rules[30] = new ParserRule(18,1,30,11,2);
      rules[31] = new ParserRule(6,1,31,1,2);
      rules[32] = new ParserRule(6,3,32,1,2);
      rules[33] = new ParserRule(14,1,33,11,2);
      rules[34] = new ParserRule(7,0,34,1,2);
      rules[35] = new ParserRule(7,1,35,11,2);
      rules[36] = new ParserRule(7,1,36,1,2);
      rules[37] = new ParserRule(7,1,37,1,2);
      rules[38] = new ParserRule(7,2,38,1,2);
      rules[39] = new ParserRule(8,1,39,11,2);
      rules[40] = new ParserRule(8,2,40,11,2);
    }

  /* ************** */
  /* PARSER ACTIONS */
  /* ************** */

  static void initializeParserActions ()
    {
      actions = new ParserAction[314];

      newAction(0,5,0);
      newAction(1,2,0);
      newAction(2,0,3);
      newAction(3,0,4);
      newAction(4,1,5);
      newAction(5,1,5);
      newAction(6,1,5);
      newAction(7,1,5);
      newAction(8,1,5);
      newAction(9,1,5);
      newAction(10,1,5);
      newAction(11,1,5);
      newAction(12,1,5);
      newAction(13,1,5);
      newAction(14,1,1);
      newAction(15,1,5);
      newAction(16,1,5);
      newAction(17,1,5);
      newAction(18,1,5);
      newAction(19,1,5);
      newAction(20,1,5);
      newAction(21,1,5);
      newAction(22,1,5);
      newAction(23,1,5);
      newAction(24,1,5);
      newAction(25,0,8);
      newAction(26,0,9);
      newAction(27,0,11);
      newAction(28,0,22);
      newAction(29,0,23);
      newAction(30,0,29);
      newAction(31,1,4);
      newAction(32,1,10);
      newAction(33,0,8);
      newAction(34,0,9);
      newAction(35,0,11);
      newAction(36,0,18);
      newAction(37,0,19);
      newAction(38,0,21);
      newAction(39,0,22);
      newAction(40,0,23);
      newAction(41,1,6);
      newAction(42,1,6);
      newAction(43,1,6);
      newAction(44,1,6);
      newAction(45,1,6);
      newAction(46,1,6);
      newAction(47,1,6);
      newAction(48,1,6);
      newAction(49,1,6);
      newAction(50,1,6);
      newAction(51,1,21);
      newAction(52,1,21);
      newAction(53,1,21);
      newAction(54,1,21);
      newAction(55,1,21);
      newAction(56,1,21);
      newAction(57,1,21);
      newAction(58,1,21);
      newAction(59,1,21);
      newAction(60,1,21);
      newAction(61,1,21);
      newAction(62,1,21);
      newAction(63,0,22);
      newAction(64,0,23);
      newAction(65,0,29);
      newAction(66,0,8);
      newAction(67,0,9);
      newAction(68,0,11);
      newAction(69,0,22);
      newAction(70,0,23);
      newAction(71,0,29);
      newAction(72,1,20);
      newAction(73,0,31);
      newAction(74,0,32);
      newAction(75,0,33);
      newAction(76,0,8);
      newAction(77,0,9);
      newAction(78,0,11);
      newAction(79,0,22);
      newAction(80,0,23);
      newAction(81,0,29);
      newAction(82,0,44);
      newAction(83,1,18);
      newAction(84,1,18);
      newAction(85,0,41);
      newAction(86,1,8);
      newAction(87,0,8);
      newAction(88,0,9);
      newAction(89,0,11);
      newAction(90,1,34);
      newAction(91,0,26);
      newAction(92,0,28);
      newAction(93,0,22);
      newAction(94,0,23);
      newAction(95,0,29);
      newAction(96,1,12);
      newAction(97,1,13);
      newAction(98,1,14);
      newAction(99,1,33);
      newAction(100,1,33);
      newAction(101,1,33);
      newAction(102,1,33);
      newAction(103,1,33);
      newAction(104,1,33);
      newAction(105,1,33);
      newAction(106,1,33);
      newAction(107,1,33);
      newAction(108,1,15);
      newAction(109,1,17);
      newAction(110,1,17);
      newAction(111,1,30);
      newAction(112,1,30);
      newAction(113,1,30);
      newAction(114,1,30);
      newAction(115,1,28);
      newAction(116,1,28);
      newAction(117,1,28);
      newAction(118,1,28);
      newAction(119,1,28);
      newAction(120,1,28);
      newAction(121,1,28);
      newAction(122,1,28);
      newAction(123,1,28);
      newAction(124,1,28);
      newAction(125,1,28);
      newAction(126,1,28);
      newAction(127,1,28);
      newAction(128,1,28);
      newAction(129,1,29);
      newAction(130,1,29);
      newAction(131,1,29);
      newAction(132,1,29);
      newAction(133,1,29);
      newAction(134,1,29);
      newAction(135,1,29);
      newAction(136,1,29);
      newAction(137,1,29);
      newAction(138,1,29);
      newAction(139,1,29);
      newAction(140,1,29);
      newAction(141,1,29);
      newAction(142,1,29);
      newAction(143,1,11);
      newAction(144,0,31);
      newAction(145,0,32);
      newAction(146,0,33);
      newAction(147,1,37);
      newAction(148,0,8);
      newAction(149,0,9);
      newAction(150,0,11);
      newAction(151,0,22);
      newAction(152,0,23);
      newAction(153,0,29);
      newAction(154,1,35);
      newAction(155,1,36);
      newAction(156,1,39);
      newAction(157,0,28);
      newAction(158,1,30);
      newAction(159,1,30);
      newAction(160,1,30);
      newAction(161,1,30);
      newAction(162,1,30);
      newAction(163,1,30);
      newAction(164,1,30);
      newAction(165,1,30);
      newAction(166,1,30);
      newAction(167,1,30);
      newAction(168,1,30);
      newAction(169,1,30);
      newAction(170,1,30);
      newAction(171,1,30);
      newAction(172,1,40);
      newAction(173,0,8);
      newAction(174,0,9);
      newAction(175,0,11);
      newAction(176,0,22);
      newAction(177,0,23);
      newAction(178,0,29);
      newAction(179,0,8);
      newAction(180,0,9);
      newAction(181,0,11);
      newAction(182,0,22);
      newAction(183,0,23);
      newAction(184,0,29);
      newAction(185,0,8);
      newAction(186,0,9);
      newAction(187,0,11);
      newAction(188,0,22);
      newAction(189,0,23);
      newAction(190,0,29);
      newAction(191,0,31);
      newAction(192,0,32);
      newAction(193,0,33);
      newAction(194,1,38);
      newAction(195,0,31);
      newAction(196,0,32);
      newAction(197,0,33);
      newAction(198,1,26);
      newAction(199,1,26);
      newAction(200,1,26);
      newAction(201,1,26);
      newAction(202,1,26);
      newAction(203,1,26);
      newAction(204,1,26);
      newAction(205,1,26);
      newAction(206,1,26);
      newAction(207,0,31);
      newAction(208,0,32);
      newAction(209,1,25);
      newAction(210,1,25);
      newAction(211,1,25);
      newAction(212,1,25);
      newAction(213,1,25);
      newAction(214,1,25);
      newAction(215,1,25);
      newAction(216,1,25);
      newAction(217,1,25);
      newAction(218,1,25);
      newAction(219,1,25);
      newAction(220,0,31);
      newAction(221,1,24);
      newAction(222,1,24);
      newAction(223,1,24);
      newAction(224,1,24);
      newAction(225,1,24);
      newAction(226,1,24);
      newAction(227,1,24);
      newAction(228,1,24);
      newAction(229,1,24);
      newAction(230,1,24);
      newAction(231,1,24);
      newAction(232,1,24);
      newAction(233,1,7);
      newAction(234,1,7);
      newAction(235,1,7);
      newAction(236,1,7);
      newAction(237,1,7);
      newAction(238,1,7);
      newAction(239,1,7);
      newAction(240,1,7);
      newAction(241,1,7);
      newAction(242,1,7);
      newAction(243,0,40);
      newAction(244,1,9);
      newAction(245,1,9);
      newAction(246,1,9);
      newAction(247,1,9);
      newAction(248,1,9);
      newAction(249,1,9);
      newAction(250,1,9);
      newAction(251,1,9);
      newAction(252,1,9);
      newAction(253,1,9);
      newAction(254,0,43);
      newAction(255,1,19);
      newAction(256,1,19);
      newAction(257,1,17);
      newAction(258,1,17);
      newAction(259,1,17);
      newAction(260,0,43);
      newAction(261,1,16);
      newAction(262,0,31);
      newAction(263,0,32);
      newAction(264,0,33);
      newAction(265,0,47);
      newAction(266,1,27);
      newAction(267,1,27);
      newAction(268,1,27);
      newAction(269,1,27);
      newAction(270,1,27);
      newAction(271,1,27);
      newAction(272,1,27);
      newAction(273,1,27);
      newAction(274,1,27);
      newAction(275,1,27);
      newAction(276,1,27);
      newAction(277,1,27);
      newAction(278,1,23);
      newAction(279,1,23);
      newAction(280,1,23);
      newAction(281,1,23);
      newAction(282,1,23);
      newAction(283,1,23);
      newAction(284,1,23);
      newAction(285,1,23);
      newAction(286,1,23);
      newAction(287,1,23);
      newAction(288,1,23);
      newAction(289,1,23);
      newAction(290,0,53);
      newAction(291,1,31);
      newAction(292,0,51);
      newAction(293,0,22);
      newAction(294,0,23);
      newAction(295,0,29);
      newAction(296,1,32);
      newAction(297,1,22);
      newAction(298,1,22);
      newAction(299,1,22);
      newAction(300,1,22);
      newAction(301,1,22);
      newAction(302,1,22);
      newAction(303,1,22);
      newAction(304,1,22);
      newAction(305,1,22);
      newAction(306,1,22);
      newAction(307,1,22);
      newAction(308,1,22);
      newAction(309,1,3);
      newAction(310,0,31);
      newAction(311,0,32);
      newAction(312,0,33);
      newAction(313,1,2);
    }

  /* ************* */
  /* PARSER STATES */
  /* ************* */

  static void initializeParserStates ()
    {
      states = new ParserState[56];

      for (int i=0; i<56; i++) newState(i);
    }

  /* ************* */
  /* ACTION TABLES */
  /* ************* */

  static void initializeActionTables ()
    {
      newActionTables(49);

      newActionTable(0,12);
	setAction(0,16,11);
	setAction(0,1,4);
	setAction(0,2,5);
	setAction(0,18,12);
	setAction(0,3,2);
	setAction(0,4,3);
	setAction(0,20,13);
	setAction(0,5,6);
	setAction(0,6,7);
	setAction(0,7,8);
	setAction(0,9,9);
	setAction(0,10,10);

      newActionTable(1,1);
	setAction(1,1,1);

      newActionTable(2,1);
	setAction(2,1,14);

      newActionTable(3,10);
	setAction(3,16,22);
	setAction(3,1,15);
	setAction(3,2,16);
	setAction(3,18,23);
	setAction(3,20,24);
	setAction(3,5,17);
	setAction(3,6,18);
	setAction(3,7,19);
	setAction(3,9,20);
	setAction(3,10,21);

      newActionTable(4,6);
	setAction(4,16,26);
	setAction(4,18,25);
	setAction(4,20,27);
	setAction(4,6,30);
	setAction(4,9,28);
	setAction(4,10,29);

      newActionTable(5,10);
	setAction(5,16,34);
	setAction(5,1,31);
	setAction(5,2,36);
	setAction(5,18,33);
	setAction(5,20,35);
	setAction(5,5,32);
	setAction(5,6,38);
	setAction(5,7,37);
	setAction(5,9,39);
	setAction(5,10,40);

      newActionTable(6,10);
	setAction(6,16,48);
	setAction(6,1,41);
	setAction(6,2,42);
	setAction(6,18,49);
	setAction(6,20,50);
	setAction(6,5,43);
	setAction(6,6,44);
	setAction(6,7,45);
	setAction(6,9,46);
	setAction(6,10,47);

      newActionTable(7,12);
	setAction(7,16,59);
	setAction(7,1,51);
	setAction(7,18,60);
	setAction(7,21,62);
	setAction(7,20,61);
	setAction(7,5,52);
	setAction(7,6,53);
	setAction(7,9,54);
	setAction(7,10,55);
	setAction(7,13,56);
	setAction(7,14,57);
	setAction(7,15,58);

      newActionTable(8,3);
	setAction(8,6,65);
	setAction(8,9,63);
	setAction(8,10,64);

      newActionTable(9,4);
	setAction(9,5,72);
	setAction(9,13,75);
	setAction(9,14,74);
	setAction(9,15,73);

      newActionTable(10,1);
	setAction(10,12,82);

      newActionTable(11,3);
	setAction(11,17,85);
	setAction(11,5,83);
	setAction(11,12,84);

      newActionTable(12,1);
	setAction(12,5,86);

      newActionTable(13,9);
	setAction(13,16,88);
	setAction(13,18,87);
	setAction(13,5,90);
	setAction(13,20,89);
	setAction(13,6,95);
	setAction(13,8,92);
	setAction(13,9,93);
	setAction(13,10,94);
	setAction(13,11,91);

      newActionTable(14,1);
	setAction(14,5,96);

      newActionTable(15,1);
	setAction(15,5,97);

      newActionTable(16,1);
	setAction(16,5,98);

      newActionTable(17,9);
	setAction(17,16,105);
	setAction(17,18,106);
	setAction(17,20,107);
	setAction(17,5,99);
	setAction(17,6,100);
	setAction(17,8,101);
	setAction(17,9,102);
	setAction(17,10,103);
	setAction(17,11,104);

      newActionTable(18,1);
	setAction(18,5,108);

      newActionTable(19,6);
	setAction(19,17,110);
	setAction(19,5,111);
	setAction(19,12,109);
	setAction(19,13,112);
	setAction(19,14,113);
	setAction(19,15,114);

      newActionTable(20,14);
	setAction(20,16,123);
	setAction(20,1,115);
	setAction(20,19,125);
	setAction(20,18,124);
	setAction(20,21,127);
	setAction(20,20,126);
	setAction(20,5,116);
	setAction(20,6,117);
	setAction(20,22,128);
	setAction(20,9,118);
	setAction(20,10,119);
	setAction(20,13,120);
	setAction(20,14,121);
	setAction(20,15,122);

      newActionTable(21,14);
	setAction(21,16,137);
	setAction(21,1,129);
	setAction(21,19,139);
	setAction(21,18,138);
	setAction(21,21,141);
	setAction(21,20,140);
	setAction(21,5,130);
	setAction(21,6,131);
	setAction(21,22,142);
	setAction(21,9,132);
	setAction(21,10,133);
	setAction(21,13,134);
	setAction(21,14,135);
	setAction(21,15,136);

      newActionTable(22,1);
	setAction(22,5,143);

      newActionTable(23,10);
	setAction(23,16,149);
	setAction(23,18,148);
	setAction(23,20,150);
	setAction(23,5,147);
	setAction(23,6,153);
	setAction(23,9,151);
	setAction(23,10,152);
	setAction(23,13,146);
	setAction(23,14,145);
	setAction(23,15,144);

      newActionTable(24,1);
	setAction(24,5,154);

      newActionTable(25,1);
	setAction(25,5,155);

      newActionTable(26,2);
	setAction(26,5,156);
	setAction(26,8,157);

      newActionTable(27,14);
	setAction(27,16,166);
	setAction(27,1,158);
	setAction(27,19,168);
	setAction(27,18,167);
	setAction(27,21,170);
	setAction(27,20,169);
	setAction(27,5,159);
	setAction(27,6,160);
	setAction(27,22,171);
	setAction(27,9,161);
	setAction(27,10,162);
	setAction(27,13,163);
	setAction(27,14,164);
	setAction(27,15,165);

      newActionTable(28,1);
	setAction(28,5,172);

      newActionTable(29,4);
	setAction(29,5,194);
	setAction(29,13,193);
	setAction(29,14,192);
	setAction(29,15,191);

      newActionTable(30,12);
	setAction(30,16,203);
	setAction(30,1,198);
	setAction(30,18,204);
	setAction(30,21,206);
	setAction(30,20,205);
	setAction(30,5,199);
	setAction(30,6,200);
	setAction(30,9,201);
	setAction(30,10,202);
	setAction(30,13,197);
	setAction(30,14,196);
	setAction(30,15,195);

      newActionTable(31,12);
	setAction(31,16,216);
	setAction(31,1,209);
	setAction(31,18,217);
	setAction(31,21,219);
	setAction(31,20,218);
	setAction(31,5,210);
	setAction(31,6,211);
	setAction(31,9,212);
	setAction(31,10,213);
	setAction(31,13,214);
	setAction(31,14,215);
	setAction(31,15,207);

      newActionTable(32,12);
	setAction(32,16,229);
	setAction(32,1,221);
	setAction(32,18,230);
	setAction(32,21,232);
	setAction(32,20,231);
	setAction(32,5,222);
	setAction(32,6,223);
	setAction(32,9,224);
	setAction(32,10,225);
	setAction(32,13,226);
	setAction(32,14,227);
	setAction(32,15,228);

      newActionTable(33,10);
	setAction(33,16,240);
	setAction(33,1,233);
	setAction(33,2,234);
	setAction(33,18,241);
	setAction(33,20,242);
	setAction(33,5,235);
	setAction(33,6,236);
	setAction(33,7,237);
	setAction(33,9,238);
	setAction(33,10,239);

      newActionTable(34,1);
	setAction(34,5,243);

      newActionTable(35,10);
	setAction(35,16,251);
	setAction(35,1,244);
	setAction(35,2,245);
	setAction(35,18,252);
	setAction(35,20,253);
	setAction(35,5,246);
	setAction(35,6,247);
	setAction(35,7,248);
	setAction(35,9,249);
	setAction(35,10,250);

      newActionTable(36,1);
	setAction(36,6,254);

      newActionTable(37,2);
	setAction(37,5,255);
	setAction(37,12,256);

      newActionTable(38,3);
	setAction(38,17,259);
	setAction(38,5,257);
	setAction(38,12,258);

      newActionTable(39,1);
	setAction(39,5,261);

      newActionTable(40,4);
	setAction(40,21,265);
	setAction(40,13,264);
	setAction(40,14,263);
	setAction(40,15,262);

      newActionTable(41,12);
	setAction(41,16,274);
	setAction(41,1,266);
	setAction(41,18,275);
	setAction(41,21,277);
	setAction(41,20,276);
	setAction(41,5,267);
	setAction(41,6,268);
	setAction(41,9,269);
	setAction(41,10,270);
	setAction(41,13,271);
	setAction(41,14,272);
	setAction(41,15,273);

      newActionTable(42,12);
	setAction(42,16,286);
	setAction(42,1,278);
	setAction(42,18,287);
	setAction(42,21,289);
	setAction(42,20,288);
	setAction(42,5,279);
	setAction(42,6,280);
	setAction(42,9,281);
	setAction(42,10,282);
	setAction(42,13,283);
	setAction(42,14,284);
	setAction(42,15,285);

      newActionTable(43,1);
	setAction(43,19,290);

      newActionTable(44,2);
	setAction(44,19,291);
	setAction(44,22,292);

      newActionTable(45,1);
	setAction(45,19,296);

      newActionTable(46,12);
	setAction(46,16,305);
	setAction(46,1,297);
	setAction(46,18,306);
	setAction(46,21,308);
	setAction(46,20,307);
	setAction(46,5,298);
	setAction(46,6,299);
	setAction(46,9,300);
	setAction(46,10,301);
	setAction(46,13,302);
	setAction(46,14,303);
	setAction(46,15,304);

      newActionTable(47,4);
	setAction(47,1,309);
	setAction(47,13,312);
	setAction(47,14,311);
	setAction(47,15,310);

      newActionTable(48,1);
	setAction(48,1,313);

    }

  /* *********** */
  /* GOTO TABLES */
  /* *********** */

  static void initializeGotoTables ()
    {
      newGotoTables(18);

      newGotoTable(0,3);
	setGoto(0,1,1);
	setGoto(0,2,2);
	setGoto(0,9,5);

      newGotoTable(1,0);

      newGotoTable(2,2);
	setGoto(2,2,55);
	setGoto(2,9,5);

      newGotoTable(3,2);
	setGoto(3,18,7);
	setGoto(3,3,54);

      newGotoTable(4,10);
	setGoto(4,17,13);
	setGoto(4,16,17);
	setGoto(4,3,10);
	setGoto(4,18,7);
	setGoto(4,4,20);
	setGoto(4,5,12);
	setGoto(4,10,6);
	setGoto(4,11,14);
	setGoto(4,14,15);
	setGoto(4,15,16);

      newGotoTable(5,2);
	setGoto(5,18,50);
	setGoto(5,6,49);

      newGotoTable(6,2);
	setGoto(6,18,7);
	setGoto(6,3,48);

      newGotoTable(7,2);
	setGoto(7,18,7);
	setGoto(7,3,46);

      newGotoTable(8,2);
	setGoto(8,12,38);
	setGoto(8,13,39);

      newGotoTable(9,4);
	setGoto(9,3,25);
	setGoto(9,18,7);
	setGoto(9,7,24);
	setGoto(9,8,27);

      newGotoTable(10,2);
	setGoto(10,18,7);
	setGoto(10,3,34);

      newGotoTable(11,1);
	setGoto(11,8,30);

      newGotoTable(12,2);
	setGoto(12,18,7);
	setGoto(12,3,37);

      newGotoTable(13,2);
	setGoto(13,18,7);
	setGoto(13,3,36);

      newGotoTable(14,2);
	setGoto(14,18,7);
	setGoto(14,3,35);

      newGotoTable(15,2);
	setGoto(15,17,13);
	setGoto(15,5,42);

      newGotoTable(16,2);
	setGoto(16,17,13);
	setGoto(16,5,45);

      newGotoTable(17,2);
	setGoto(17,18,50);
	setGoto(17,6,52);

    }

  /* ************ */
  /* STATE TABLES */
  /* ************ */

  static void initializeStateTables ()
    {
      setTables(0,0,0);
      setTables(1,1,1);
      setTables(2,2,1);
      setTables(3,3,2);
      setTables(4,4,3);
      setTables(5,5,4);
      setTables(6,6,1);
      setTables(7,7,1);
      setTables(8,8,5);
      setTables(9,4,6);
      setTables(10,9,1);
      setTables(11,4,7);
      setTables(12,10,1);
      setTables(13,11,1);
      setTables(14,12,8);
      setTables(15,13,9);
      setTables(16,14,1);
      setTables(17,15,1);
      setTables(18,16,1);
      setTables(19,17,1);
      setTables(20,18,1);
      setTables(21,19,1);
      setTables(22,20,1);
      setTables(23,21,1);
      setTables(24,22,1);
      setTables(25,23,10);
      setTables(26,24,1);
      setTables(27,25,1);
      setTables(28,26,11);
      setTables(29,27,1);
      setTables(30,28,1);
      setTables(31,4,12);
      setTables(32,4,13);
      setTables(33,4,14);
      setTables(34,29,1);
      setTables(35,30,1);
      setTables(36,31,1);
      setTables(37,32,1);
      setTables(38,33,1);
      setTables(39,34,1);
      setTables(40,35,1);
      setTables(41,36,15);
      setTables(42,37,1);
      setTables(43,38,1);
      setTables(44,36,16);
      setTables(45,39,1);
      setTables(46,40,1);
      setTables(47,41,1);
      setTables(48,42,1);
      setTables(49,43,1);
      setTables(50,44,1);
      setTables(51,8,17);
      setTables(52,45,1);
      setTables(53,46,1);
      setTables(54,47,1);
      setTables(55,48,1);
    }
}

/* ***************** */
/* ANCILLARY CLASSES */
/* ***************** */

class OsfV0IsaDeclarationStatement extends ParseNode 
{
  OsfV0IsaDeclarationStatement (ParseNode node)
    {
      super(node);
    }

  Stack lhs;
  Stack rhs;
}

class OsfV0SortSymbols extends ParseNode 
{
  OsfV0SortSymbols (ParseNode node)
    {
      super(node);
    }

  Stack symbols;
}

class OsfV0SortList extends ParseNode 
{
  OsfV0SortList (ParseNode node)
    {
      super(node);
    }

  Stack sortList;
}

class OsfV0PragmaArguments_opt extends ParseNode 
{
  OsfV0PragmaArguments_opt (ParseNode node)
    {
      super(node);
    }

  ArrayList args;
}

class OsfV0FileList extends ParseNode 
{
  OsfV0FileList (ParseNode node)
    {
      super(node);
    }

  Stack files;
}



/* ************************************************************************ */
/* ************************* END OF GRAMMAR RULES ************************* */
/* ************************************************************************ */

/* ************************************************************************ */
/* ******************************* UTILITIES ****************************** */
/* ************************************************************************ */

class RawPsiTerm
  {
    String tag;
    SortExpression sort;
    Stack keys;
    Stack subterms;

    RawPsiTerm (String tag, SortExpression sort, Stack keys, Stack subterms)
      {
	this.tag = tag;
	this.sort = sort;
	this.keys = keys;
	this.subterms = subterms;
      }
  }

/* ************************************************************************ */
/* ***************************** END  OF  GRAMMAR ************************* */
/* ************************************************************************ */

/* ************************************************************************ */

