// *******************************************************************
// This file has been automatically generated from the grammar in file
// OsfV1.grm by hlt.language.syntax.ParserGenerator on
// Mon Sep 16 21:14:56 CEST 2013 --- !!! PLEASE DO NO EDIT !!!
// *******************************************************************

package hlt.osf.v1;

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 OsfV1Parser extends StaticParser
{
  /* ************************ */
  /* PARSER CLASS CONSTRUCTOR */
  /* ************************ */

  public OsfV1Parser (Tokenizer t)
    {
      input = t;
      xmlroot = "OsfV1Program";
    }

  /* ************************* */
  /* 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 (Stack lhs, Stack 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(4)); // margin is 4 to account for "*** "
      // Tag.tallyTags();	// show known tags
      Tag.clearKnownTags();	// clear the tags
      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.
 */
PsiTerm buildPsiTerm (HashSet tags, Tag tag, SortExpression sort, Stack keys, Stack subterms)
{
  // dereference the tag to get to the correct one if needed:
  tag = tag.deref();

  // this is the psiterm to build:
  PsiTerm pst = null;

  // check if this tag has been seen before:
  if (tags.contains(tag))
    // this tag is a reoccurring tag: 
    {
      // mark the tag as shared and retrieve its term:
      pst = tag.markAsShared().term();
      // merge the existing term's sort with the given sort:
      pst.mergeSortWith(sort);
    }
  else
    // this tag has not occurred before:
    {
      // add the tag to the tag occurrences:
      tags.add(tag);
      // create a new psiterm with the given sort and tag:
      pst = new PsiTerm(sort).setTag(tag);
    }

  // build the subterms if there are any:
  if (subterms != null) // (then must have keys != null as well)
    {
      // this is to count implicit positions of subterms if any:
      int implicitPosition = 0;

      // this is to hold a subterm to build if any:
      PsiTerm subterm = null;

      // this is to hold an already existing subterm if any:
      PsiTerm existingSubterm = null;

      // build each subterm one at a time:
      while (!subterms.empty())
	{
	  // get the current raw subterm to build:
	  RawPsiTerm rawsub = (RawPsiTerm)subterms.pop();
	  // build the current subterm
	  subterm = buildPsiTerm(tags,
				 Tag.getTag(rawsub.tag),
				 rawsub.sort,
				 rawsub.keys,
				 rawsub.subterms).deref();

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

	  if (key == null)
	    // this is an implicitly contiguous position
	    {
	      implicitPosition++;

	      // retrieve the possibly existing subterm:
	      existingSubterm = pst.getSubterm(implicitPosition);
	      if (existingSubterm == null)
		pst.setSubterm(implicitPosition,subterm.deref());
	      else
		existingSubterm.deref().merge(subterm.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.deref());
	      else
		existingSubterm.deref().merge(subterm.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
	    existingSubterm.merge(subterm.deref());
	}
    }

  // return dereferenced pst in case its tag was bound by merging subterms
  return pst = pst.deref();
}

/**
 * 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 on the pragma.  If in timing mode, also reports the
 * processing time in milliseconds.
 */
final void processPragma (String pragma, Stack 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, Stack args)
{
  setLocation();

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

  if (pragma == "eval")
    {
      PsiTerm.evaluateSorts(true);
      displayLine("*** Sort expression evaluation has been turned on...");
      return;
    }

  if (pragma == "no-eval")
    {
      PsiTerm.evaluateSorts(false);
      displayLine("*** Sort expression evaluation has been turned off...");
      return;
    }

  if (pragma == "toggle-eval")
    {
      PsiTerm.toggleSortEvaluation();
      displayLine("*** Sort expression evaluation has been turned "
		  +(PsiTerm.evalSorts() ? "on" : "off")+"...");
      return;
    }

  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(args);
      return;
    }

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

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

  if (pragma == "load")
    {
      loadTaxonomy(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 == "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 V1 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);
	  ((OsfV1Tokenizer)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%       eval  turn on sort evaluation");
  displayLine("\t%    no-eval  turn off sort evaluation");
  displayLine("\t%toggle-eval  toggle on/off 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.displayForm(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 (((OsfV1Tokenizer)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 ()
{
  ((OsfV1Tokenizer)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 $OSFV1PROGRAM_SWITCH$ = new ParseNode(terminals[3]);

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

  public final void parseOsfV1Program (Reader r) throws IOException
    {
      input.setReader(r);
      errorManager().recoverFromErrors(false);
      setSwitchToken($OSFV1PROGRAM_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:
            {
            OsfV1PragmaArguments_opt $node2$;
                if (node($rule$,2) instanceof OsfV1PragmaArguments_opt)
                   $node2$ = (OsfV1PragmaArguments_opt)node($rule$,2);
                 else
                 {
                     $node2$ = new OsfV1PragmaArguments_opt(node($rule$,2));
                     replaceStackNode($rule$,2,$node2$);
                   }

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

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

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

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

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

        processPsiTerm($node1$.tag,$node1$.sort,$node1$.keys,$node1$.subterms);
            break;
            }
          case 21:
            {
            OsfV1PsiTerm $node0$ = new OsfV1PsiTerm($head$);
                 $head$ = (OsfV1PsiTerm)$node0$;

        $node0$.tag = node($rule$,1).svalue();
        $node0$.sort = new SymbolSortExpression("@",context);
            break;
            }
          case 22:
            {
            OsfV1PsiTerm $node0$ = new OsfV1PsiTerm($head$);
                 $head$ = (OsfV1PsiTerm)$node0$;
    OsfV1UntaggedPsiTerm $node1$;
                if (node($rule$,1) instanceof OsfV1UntaggedPsiTerm)
                   $node1$ = (OsfV1UntaggedPsiTerm)node($rule$,1);
                 else
                 {
                     $node1$ = new OsfV1UntaggedPsiTerm(node($rule$,1));
                     replaceStackNode($rule$,1,$node1$);
                   }

        $node0$.sort = $node1$.sort;
        $node0$.keys = $node1$.keys;
        $node0$.subterms = $node1$.subterms;
            break;
            }
          case 23:
            {
            OsfV1PsiTerm $node0$ = new OsfV1PsiTerm($head$);
                 $head$ = (OsfV1PsiTerm)$node0$;
    OsfV1UntaggedPsiTerm $node3$;
                if (node($rule$,3) instanceof OsfV1UntaggedPsiTerm)
                   $node3$ = (OsfV1UntaggedPsiTerm)node($rule$,3);
                 else
                 {
                     $node3$ = new OsfV1UntaggedPsiTerm(node($rule$,3));
                     replaceStackNode($rule$,3,$node3$);
                   }

        $node0$.tag = node($rule$,1).svalue();
        $node0$.sort = $node3$.sort;
        $node0$.keys = $node3$.keys;
        $node0$.subterms = $node3$.subterms;
            break;
            }
          case 24:
            {
            OsfV1UntaggedPsiTerm $node0$ = new OsfV1UntaggedPsiTerm($head$);
                 $head$ = (OsfV1UntaggedPsiTerm)$node0$;
    OsfV1SortExpression $node1$;
                if (node($rule$,1) instanceof OsfV1SortExpression)
                   $node1$ = (OsfV1SortExpression)node($rule$,1);
                 else
                 {
                     $node1$ = new OsfV1SortExpression(node($rule$,1));
                     replaceStackNode($rule$,1,$node1$);
                   }
    OsfV1Body_opt $node2$;
                if (node($rule$,2) instanceof OsfV1Body_opt)
                   $node2$ = (OsfV1Body_opt)node($rule$,2);
                 else
                 {
                     $node2$ = new OsfV1Body_opt(node($rule$,2));
                     replaceStackNode($rule$,2,$node2$);
                   }

        $node0$.sort = $node1$.expression;
        $node0$.keys = $node2$.keys;
        $node0$.subterms = $node2$.subterms;
            break;
            }
          case 26:
            {
            OsfV1Body_opt $node0$ = new OsfV1Body_opt($head$);
                 $head$ = (OsfV1Body_opt)$node0$;
    OsfV1SubTerms $node2$;
                if (node($rule$,2) instanceof OsfV1SubTerms)
                   $node2$ = (OsfV1SubTerms)node($rule$,2);
                 else
                 {
                     $node2$ = new OsfV1SubTerms(node($rule$,2));
                     replaceStackNode($rule$,2,$node2$);
                   }

        $node0$.keys = $node2$.keys;
        $node0$.subterms = $node2$.subterms;
            break;
            }
          case 27:
            {
            OsfV1SubTerms $node0$ = new OsfV1SubTerms($head$);
                 $head$ = (OsfV1SubTerms)$node0$;
    OsfV1SubTerm $node1$;
                if (node($rule$,1) instanceof OsfV1SubTerm)
                   $node1$ = (OsfV1SubTerm)node($rule$,1);
                 else
                 {
                     $node1$ = new OsfV1SubTerm(node($rule$,1));
                     replaceStackNode($rule$,1,$node1$);
                   }

        $node0$.keys = new Stack();
        $node0$.keys.push($node1$.key);
        $node0$.subterms = new Stack();
        $node0$.subterms.push($node1$.psiterm);
            break;
            }
          case 28:
            {
            OsfV1SubTerms $node0$ = new OsfV1SubTerms($head$);
                 $head$ = (OsfV1SubTerms)$node0$;
    OsfV1SubTerms $node3$;
                if (node($rule$,3) instanceof OsfV1SubTerms)
                   $node3$ = (OsfV1SubTerms)node($rule$,3);
                 else
                 {
                     $node3$ = new OsfV1SubTerms(node($rule$,3));
                     replaceStackNode($rule$,3,$node3$);
                   }
    OsfV1SubTerm $node1$;
                if (node($rule$,1) instanceof OsfV1SubTerm)
                   $node1$ = (OsfV1SubTerm)node($rule$,1);
                 else
                 {
                     $node1$ = new OsfV1SubTerm(node($rule$,1));
                     replaceStackNode($rule$,1,$node1$);
                   }

        ($node0$.keys = $node3$.keys).push($node1$.key);
        ($node0$.subterms = $node3$.subterms).push($node1$.psiterm);
            break;
            }
          case 29:
            {
            OsfV1SubTerm $node0$ = new OsfV1SubTerm($head$);
                 $head$ = (OsfV1SubTerm)$node0$;
    OsfV1PsiTerm $node1$;
                if (node($rule$,1) instanceof OsfV1PsiTerm)
                   $node1$ = (OsfV1PsiTerm)node($rule$,1);
                 else
                 {
                     $node1$ = new OsfV1PsiTerm(node($rule$,1));
                     replaceStackNode($rule$,1,$node1$);
                   }

        $node0$.key = null;
        $node0$.psiterm = new RawPsiTerm($node1$.tag,$node1$.sort,$node1$.keys,$node1$.subterms);
            break;
            }
          case 30:
            {
            OsfV1SubTerm $node0$ = new OsfV1SubTerm($head$);
                 $head$ = (OsfV1SubTerm)$node0$;
    OsfV1Feature $node1$;
                if (node($rule$,1) instanceof OsfV1Feature)
                   $node1$ = (OsfV1Feature)node($rule$,1);
                 else
                 {
                     $node1$ = new OsfV1Feature(node($rule$,1));
                     replaceStackNode($rule$,1,$node1$);
                   }
    OsfV1PsiTerm $node3$;
                if (node($rule$,3) instanceof OsfV1PsiTerm)
                   $node3$ = (OsfV1PsiTerm)node($rule$,3);
                 else
                 {
                     $node3$ = new OsfV1PsiTerm(node($rule$,3));
                     replaceStackNode($rule$,3,$node3$);
                   }

        $node0$.key = $node1$.feature;
        $node0$.psiterm = new RawPsiTerm($node3$.tag,$node3$.sort,$node3$.keys,$node3$.subterms);
            break;
            }
          case 31:
            {
            OsfV1Feature $node0$ = new OsfV1Feature($head$);
                 $head$ = (OsfV1Feature)$node0$;

        $node0$.feature = new Integer((int)node($rule$,1).nvalue());
            break;
            }
          case 32:
            {
            OsfV1Feature $node0$ = new OsfV1Feature($head$);
                 $head$ = (OsfV1Feature)$node0$;

        $node0$.feature = node($rule$,1).svalue();
            break;
            }
          case 33:
            {
            OsfV1SortExpression $node0$ = new OsfV1SortExpression($head$);
                 $head$ = (OsfV1SortExpression)$node0$;
    OsfV1Constant $node1$;
                if (node($rule$,1) instanceof OsfV1Constant)
                   $node1$ = (OsfV1Constant)node($rule$,1);
                 else
                 {
                     $node1$ = new OsfV1Constant(node($rule$,1));
                     replaceStackNode($rule$,1,$node1$);
                   }

        $node0$.expression = new ConstantSortExpression($node1$.constant);
            break;
            }
          case 34:
            {
            OsfV1SortExpression $node0$ = new OsfV1SortExpression($head$);
                 $head$ = (OsfV1SortExpression)$node0$;

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

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

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

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

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

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

        $node0$.expression = $node2$.expression.setParenthesized(true);
            break;
            }
          case 41:
            {
            OsfV1Constant $node0$ = new OsfV1Constant($head$);
                 $head$ = (OsfV1Constant)$node0$;
 $node0$.constant = new IntegerConstant((int)node($rule$,1).nvalue());
            break;
            }
          case 42:
            {
            OsfV1Constant $node0$ = new OsfV1Constant($head$);
                 $head$ = (OsfV1Constant)$node0$;
 $node0$.constant = new CharConstant(node($rule$,1).svalue().charAt(0));
            break;
            }
          case 43:
            {
            OsfV1Constant $node0$ = new OsfV1Constant($head$);
                 $head$ = (OsfV1Constant)$node0$;
 $node0$.constant = new FloatConstant(node($rule$,1).nvalue());
            break;
            }
          case 44:
            {
            OsfV1Constant $node0$ = new OsfV1Constant($head$);
                 $head$ = (OsfV1Constant)$node0$;
 $node0$.constant = new StringConstant(node($rule$,1).svalue());
            break;
            }
          case 45:
            {
            OsfV1Constant $node0$ = new OsfV1Constant($head$);
                 $head$ = (OsfV1Constant)$node0$;
 $node0$.constant = new BooleanConstant(node($rule$,1).svalue() == "true" ? true : false);
            break;
            }
          case 49:
            {
            OsfV1SortList $node0$ = new OsfV1SortList($head$);
                 $head$ = (OsfV1SortList)$node0$;

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

        ($node0$.sortList = $node3$.sortList).push(node($rule$,1).svalue());
            break;
            }
          case 53:
            {
            Decoded.setEnumSize((int)node($rule$,1).nvalue());
            break;
            }
          case 54:
            {
            OsfV1PragmaArguments_opt $node0$ = new OsfV1PragmaArguments_opt($head$);
                 $head$ = (OsfV1PragmaArguments_opt)$node0$;
    OsfV1FileList $node1$;
                if (node($rule$,1) instanceof OsfV1FileList)
                   $node1$ = (OsfV1FileList)node($rule$,1);
                 else
                 {
                     $node1$ = new OsfV1FileList(node($rule$,1));
                     replaceStackNode($rule$,1,$node1$);
                   }

        $node0$.args = $node1$.files;
            break;
            }
          case 55:
            {
            OsfV1FileList $node0$ = new OsfV1FileList($head$);
                 $head$ = (OsfV1FileList)$node0$;

        $node0$.files = new Stack();
        $node0$.files.push(node($rule$,1).svalue());
            break;
            }
          case 56:
            {
            OsfV1FileList $node0$ = new OsfV1FileList($head$);
                 $head$ = (OsfV1FileList)$node0$;
    OsfV1FileList $node2$;
                if (node($rule$,2) instanceof OsfV1FileList)
                   $node2$ = (OsfV1FileList)node($rule$,2);
                 else
                 {
                     $node2$ = new OsfV1FileList(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 25: case 52: 
            break;
          default:
            $head$ = $head$.copy(node($rule$,1));
            break;
        }
      return $head$;
    }

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

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

      newTerminal(0,"$EMPTY$",1,2);
      newTerminal(1,"$E_O_I$",1,2);
      newTerminal(2,"error",1,2);
      newTerminal(3,"$OsfV1Program_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,"TAG",11,2);
      newTerminal(12,"INTEGER",11,2);
      newTerminal(13,"CHAR",11,2);
      newTerminal(14,"FLOAT",11,2);
      newTerminal(15,"BOOLEAN",11,2);
      newTerminal(16,"ARROW",21,2);
      newTerminal(17,"ISA",31,2);
      newTerminal(18,"BUTNOT",41,1);
      newTerminal(19,"OR",51,0);
      newTerminal(20,"AND",61,0);
      newTerminal(21,"NOT",71,1);
      newTerminal(22,",",1,2);
      newTerminal(23,":",1,2);
      newTerminal(24,"(",1,2);
      newTerminal(25,")",1,2);
      newTerminal(26,"{",1,2);
      newTerminal(27,"}",1,2);
      newTerminal(28,";",1,2);
    }

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

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

      newNonTerminal(0,"$START$");
      newNonTerminal(1,"$ROOTS$");
      newNonTerminal(2,"OsfV1Program");
      newNonTerminal(3,"SortExpression");
      newNonTerminal(4,"IsaDeclarationStatement");
      newNonTerminal(5,"SortSymbols");
      newNonTerminal(6,"Constant");
      newNonTerminal(7,"SortList");
      newNonTerminal(8,"UntaggedPsiTerm");
      newNonTerminal(9,"Body_opt");
      newNonTerminal(10,"PsiTerm");
      newNonTerminal(11,"SubTerms");
      newNonTerminal(12,"SubTerm");
      newNonTerminal(13,"Feature");
      newNonTerminal(14,"PragmaArguments_opt");
      newNonTerminal(15,"FileList");
      newNonTerminal(16,"Statements_opt");
      newNonTerminal(17,"Statement");
      newNonTerminal(18,"StatementType");
      newNonTerminal(19,"EndOfStatement");
      newNonTerminal(20,"$ACTION0$");
      newNonTerminal(21,"Pragma");
      newNonTerminal(22,"SortDeclarationStatement");
      newNonTerminal(23,"OsfExpression");
      newNonTerminal(24,"SortSymbol");
      newNonTerminal(25,"Sort");
    }

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

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

      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(16,0,5,1,2);
      rules[6] = new ParserRule(16,2,6,1,2);
      rules[7] = new ParserRule(17,2,7,1,2);
      rules[8] = new ParserRule(20,0,8,1,2);
      rules[9] = new ParserRule(19,2,9,1,2);
      rules[10] = new ParserRule(18,0,10,1,2);
      rules[11] = new ParserRule(18,2,11,1,2);
      rules[12] = new ParserRule(18,1,12,1,2);
      rules[13] = new ParserRule(18,1,13,1,2);
      rules[14] = new ParserRule(18,1,14,1,2);
      rules[15] = new ParserRule(22,1,15,1,2);
      rules[16] = new ParserRule(4,3,16,31,2);
      rules[17] = new ParserRule(24,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(23,1,20,1,2);
      rules[21] = new ParserRule(10,1,21,11,2);
      rules[22] = new ParserRule(10,1,22,1,2);
      rules[23] = new ParserRule(10,3,23,1,2);
      rules[24] = new ParserRule(8,2,24,1,2);
      rules[25] = new ParserRule(9,0,25,1,2);
      rules[26] = new ParserRule(9,3,26,1,2);
      rules[27] = new ParserRule(11,1,27,1,2);
      rules[28] = new ParserRule(11,3,28,1,2);
      rules[29] = new ParserRule(12,1,29,1,2);
      rules[30] = new ParserRule(12,3,30,21,2);
      rules[31] = new ParserRule(13,1,31,11,2);
      rules[32] = new ParserRule(13,1,32,11,2);
      rules[33] = new ParserRule(3,1,33,1,2);
      rules[34] = new ParserRule(3,1,34,1,2);
      rules[35] = new ParserRule(3,3,35,1,2);
      rules[36] = new ParserRule(3,2,36,71,1);
      rules[37] = new ParserRule(3,3,37,61,0);
      rules[38] = new ParserRule(3,3,38,51,0);
      rules[39] = new ParserRule(3,3,39,41,1);
      rules[40] = new ParserRule(3,3,40,1,2);
      rules[41] = new ParserRule(6,1,41,11,2);
      rules[42] = new ParserRule(6,1,42,11,2);
      rules[43] = new ParserRule(6,1,43,11,2);
      rules[44] = new ParserRule(6,1,44,11,2);
      rules[45] = new ParserRule(6,1,45,11,2);
      rules[46] = new ParserRule(25,1,46,11,2);
      rules[47] = new ParserRule(25,1,47,11,2);
      rules[48] = new ParserRule(25,1,48,11,2);
      rules[49] = new ParserRule(7,1,49,1,2);
      rules[50] = new ParserRule(7,3,50,1,2);
      rules[51] = new ParserRule(21,1,51,11,2);
      rules[52] = new ParserRule(14,0,52,1,2);
      rules[53] = new ParserRule(14,1,53,11,2);
      rules[54] = new ParserRule(14,1,54,1,2);
      rules[55] = new ParserRule(15,1,55,11,2);
      rules[56] = new ParserRule(15,2,56,11,2);
    }

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

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

      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,5);
      newAction(15,1,5);
      newAction(16,1,5);
      newAction(17,1,5);
      newAction(18,1,5);
      newAction(19,1,5);
      newAction(20,1,1);
      newAction(21,1,5);
      newAction(22,1,5);
      newAction(23,1,5);
      newAction(24,1,5);
      newAction(25,1,5);
      newAction(26,1,5);
      newAction(27,1,5);
      newAction(28,1,5);
      newAction(29,1,5);
      newAction(30,1,5);
      newAction(31,1,5);
      newAction(32,1,5);
      newAction(33,1,5);
      newAction(34,1,5);
      newAction(35,1,5);
      newAction(36,1,5);
      newAction(37,0,9);
      newAction(38,0,10);
      newAction(39,0,12);
      newAction(40,0,15);
      newAction(41,0,16);
      newAction(42,0,17);
      newAction(43,0,18);
      newAction(44,0,19);
      newAction(45,0,31);
      newAction(46,0,32);
      newAction(47,0,43);
      newAction(48,1,4);
      newAction(49,1,10);
      newAction(50,0,9);
      newAction(51,0,10);
      newAction(52,0,12);
      newAction(53,0,15);
      newAction(54,0,16);
      newAction(55,0,17);
      newAction(56,0,18);
      newAction(57,0,19);
      newAction(58,0,20);
      newAction(59,0,26);
      newAction(60,0,27);
      newAction(61,0,30);
      newAction(62,0,31);
      newAction(63,0,32);
      newAction(64,1,6);
      newAction(65,1,6);
      newAction(66,1,6);
      newAction(67,1,6);
      newAction(68,1,6);
      newAction(69,1,6);
      newAction(70,1,6);
      newAction(71,1,6);
      newAction(72,1,6);
      newAction(73,1,6);
      newAction(74,1,6);
      newAction(75,1,6);
      newAction(76,1,6);
      newAction(77,1,6);
      newAction(78,1,6);
      newAction(79,1,6);
      newAction(80,1,33);
      newAction(81,1,33);
      newAction(82,1,33);
      newAction(83,1,33);
      newAction(84,1,33);
      newAction(85,1,33);
      newAction(86,1,33);
      newAction(87,1,33);
      newAction(88,1,34);
      newAction(89,1,34);
      newAction(90,1,34);
      newAction(91,1,34);
      newAction(92,1,34);
      newAction(93,1,34);
      newAction(94,1,34);
      newAction(95,1,34);
      newAction(96,0,31);
      newAction(97,0,32);
      newAction(98,0,43);
      newAction(99,0,9);
      newAction(100,0,10);
      newAction(101,0,12);
      newAction(102,0,15);
      newAction(103,0,16);
      newAction(104,0,17);
      newAction(105,0,18);
      newAction(106,0,19);
      newAction(107,0,31);
      newAction(108,0,32);
      newAction(109,0,43);
      newAction(110,0,50);
      newAction(111,0,51);
      newAction(112,0,52);
      newAction(113,1,25);
      newAction(114,1,25);
      newAction(115,1,25);
      newAction(116,0,58);
      newAction(117,0,9);
      newAction(118,0,10);
      newAction(119,0,12);
      newAction(120,0,15);
      newAction(121,0,16);
      newAction(122,0,17);
      newAction(123,0,18);
      newAction(124,0,19);
      newAction(125,0,31);
      newAction(126,0,32);
      newAction(127,0,43);
      newAction(128,0,47);
      newAction(129,1,18);
      newAction(130,1,18);
      newAction(131,0,44);
      newAction(132,1,41);
      newAction(133,1,41);
      newAction(134,1,41);
      newAction(135,1,41);
      newAction(136,1,41);
      newAction(137,1,41);
      newAction(138,1,41);
      newAction(139,1,41);
      newAction(140,1,42);
      newAction(141,1,42);
      newAction(142,1,42);
      newAction(143,1,42);
      newAction(144,1,42);
      newAction(145,1,42);
      newAction(146,1,42);
      newAction(147,1,42);
      newAction(148,1,43);
      newAction(149,1,43);
      newAction(150,1,43);
      newAction(151,1,43);
      newAction(152,1,43);
      newAction(153,1,43);
      newAction(154,1,43);
      newAction(155,1,43);
      newAction(156,1,44);
      newAction(157,1,44);
      newAction(158,1,44);
      newAction(159,1,44);
      newAction(160,1,44);
      newAction(161,1,44);
      newAction(162,1,44);
      newAction(163,1,44);
      newAction(164,1,45);
      newAction(165,1,45);
      newAction(166,1,45);
      newAction(167,1,45);
      newAction(168,1,45);
      newAction(169,1,45);
      newAction(170,1,45);
      newAction(171,1,45);
      newAction(172,1,21);
      newAction(173,1,21);
      newAction(174,1,21);
      newAction(175,0,41);
      newAction(176,1,22);
      newAction(177,1,22);
      newAction(178,1,22);
      newAction(179,1,8);
      newAction(180,1,52);
      newAction(181,0,34);
      newAction(182,0,36);
      newAction(183,1,12);
      newAction(184,1,13);
      newAction(185,1,14);
      newAction(186,1,51);
      newAction(187,1,51);
      newAction(188,1,51);
      newAction(189,1,15);
      newAction(190,1,20);
      newAction(191,1,17);
      newAction(192,1,17);
      newAction(193,1,48);
      newAction(194,1,48);
      newAction(195,1,48);
      newAction(196,1,48);
      newAction(197,1,48);
      newAction(198,1,46);
      newAction(199,1,46);
      newAction(200,1,46);
      newAction(201,1,46);
      newAction(202,1,46);
      newAction(203,1,46);
      newAction(204,1,46);
      newAction(205,1,46);
      newAction(206,1,46);
      newAction(207,1,46);
      newAction(208,1,47);
      newAction(209,1,47);
      newAction(210,1,47);
      newAction(211,1,47);
      newAction(212,1,47);
      newAction(213,1,47);
      newAction(214,1,47);
      newAction(215,1,47);
      newAction(216,1,47);
      newAction(217,1,47);
      newAction(218,1,11);
      newAction(219,1,53);
      newAction(220,1,54);
      newAction(221,1,55);
      newAction(222,0,36);
      newAction(223,1,56);
      newAction(224,1,7);
      newAction(225,1,7);
      newAction(226,1,7);
      newAction(227,1,7);
      newAction(228,1,7);
      newAction(229,1,7);
      newAction(230,1,7);
      newAction(231,1,7);
      newAction(232,1,7);
      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,0,40);
      newAction(241,1,9);
      newAction(242,1,9);
      newAction(243,1,9);
      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,1,9);
      newAction(255,1,9);
      newAction(256,1,9);
      newAction(257,0,9);
      newAction(258,0,10);
      newAction(259,0,12);
      newAction(260,0,15);
      newAction(261,0,16);
      newAction(262,0,17);
      newAction(263,0,18);
      newAction(264,0,19);
      newAction(265,0,31);
      newAction(266,0,32);
      newAction(267,0,43);
      newAction(268,1,23);
      newAction(269,1,23);
      newAction(270,1,23);
      newAction(271,1,48);
      newAction(272,1,48);
      newAction(273,1,48);
      newAction(274,1,48);
      newAction(275,1,48);
      newAction(276,1,48);
      newAction(277,1,48);
      newAction(278,1,48);
      newAction(279,1,48);
      newAction(280,1,48);
      newAction(281,0,46);
      newAction(282,1,19);
      newAction(283,1,19);
      newAction(284,1,17);
      newAction(285,1,17);
      newAction(286,1,17);
      newAction(287,0,46);
      newAction(288,1,16);
      newAction(289,0,50);
      newAction(290,0,51);
      newAction(291,0,52);
      newAction(292,0,53);
      newAction(293,0,9);
      newAction(294,0,10);
      newAction(295,0,12);
      newAction(296,0,15);
      newAction(297,0,16);
      newAction(298,0,17);
      newAction(299,0,18);
      newAction(300,0,19);
      newAction(301,0,31);
      newAction(302,0,32);
      newAction(303,0,43);
      newAction(304,0,9);
      newAction(305,0,10);
      newAction(306,0,12);
      newAction(307,0,15);
      newAction(308,0,16);
      newAction(309,0,17);
      newAction(310,0,18);
      newAction(311,0,19);
      newAction(312,0,31);
      newAction(313,0,32);
      newAction(314,0,43);
      newAction(315,0,9);
      newAction(316,0,10);
      newAction(317,0,12);
      newAction(318,0,15);
      newAction(319,0,16);
      newAction(320,0,17);
      newAction(321,0,18);
      newAction(322,0,19);
      newAction(323,0,31);
      newAction(324,0,32);
      newAction(325,0,43);
      newAction(326,1,40);
      newAction(327,1,40);
      newAction(328,1,40);
      newAction(329,1,40);
      newAction(330,1,40);
      newAction(331,1,40);
      newAction(332,1,40);
      newAction(333,1,40);
      newAction(334,0,50);
      newAction(335,0,51);
      newAction(336,0,52);
      newAction(337,1,39);
      newAction(338,1,39);
      newAction(339,1,39);
      newAction(340,1,39);
      newAction(341,1,39);
      newAction(342,0,50);
      newAction(343,0,51);
      newAction(344,1,38);
      newAction(345,1,38);
      newAction(346,1,38);
      newAction(347,1,38);
      newAction(348,1,38);
      newAction(349,1,38);
      newAction(350,1,38);
      newAction(351,0,50);
      newAction(352,1,37);
      newAction(353,1,37);
      newAction(354,1,37);
      newAction(355,1,37);
      newAction(356,1,37);
      newAction(357,1,37);
      newAction(358,1,37);
      newAction(359,1,37);
      newAction(360,1,24);
      newAction(361,1,24);
      newAction(362,1,24);
      newAction(363,0,9);
      newAction(364,0,10);
      newAction(365,0,12);
      newAction(366,0,60);
      newAction(367,0,16);
      newAction(368,0,17);
      newAction(369,0,18);
      newAction(370,0,19);
      newAction(371,0,20);
      newAction(372,0,64);
      newAction(373,0,31);
      newAction(374,0,32);
      newAction(375,0,69);
      newAction(376,1,31);
      newAction(377,1,41);
      newAction(378,1,41);
      newAction(379,1,41);
      newAction(380,1,41);
      newAction(381,1,41);
      newAction(382,1,41);
      newAction(383,1,27);
      newAction(384,0,67);
      newAction(385,1,29);
      newAction(386,1,29);
      newAction(387,0,65);
      newAction(388,1,32);
      newAction(389,1,48);
      newAction(390,1,48);
      newAction(391,1,48);
      newAction(392,1,48);
      newAction(393,1,48);
      newAction(394,1,48);
      newAction(395,0,9);
      newAction(396,0,10);
      newAction(397,0,12);
      newAction(398,0,15);
      newAction(399,0,16);
      newAction(400,0,17);
      newAction(401,0,18);
      newAction(402,0,19);
      newAction(403,0,20);
      newAction(404,0,31);
      newAction(405,0,32);
      newAction(406,0,43);
      newAction(407,1,30);
      newAction(408,1,30);
      newAction(409,0,9);
      newAction(410,0,10);
      newAction(411,0,12);
      newAction(412,0,60);
      newAction(413,0,16);
      newAction(414,0,17);
      newAction(415,0,18);
      newAction(416,0,19);
      newAction(417,0,20);
      newAction(418,0,64);
      newAction(419,0,31);
      newAction(420,0,32);
      newAction(421,1,28);
      newAction(422,1,26);
      newAction(423,1,26);
      newAction(424,1,26);
      newAction(425,1,36);
      newAction(426,1,36);
      newAction(427,1,36);
      newAction(428,1,36);
      newAction(429,1,36);
      newAction(430,1,36);
      newAction(431,1,36);
      newAction(432,1,36);
      newAction(433,0,75);
      newAction(434,1,49);
      newAction(435,0,73);
      newAction(436,0,31);
      newAction(437,0,32);
      newAction(438,0,43);
      newAction(439,1,50);
      newAction(440,1,35);
      newAction(441,1,35);
      newAction(442,1,35);
      newAction(443,1,35);
      newAction(444,1,35);
      newAction(445,1,35);
      newAction(446,1,35);
      newAction(447,1,35);
      newAction(448,1,3);
      newAction(449,0,50);
      newAction(450,0,51);
      newAction(451,0,52);
      newAction(452,1,2);
    }

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

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

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

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

  static void initializeActionTables ()
    {
      newActionTables(69);

      newActionTable(0,18);
	setAction(0,1,4);
	setAction(0,2,5);
	setAction(0,3,2);
	setAction(0,4,3);
	setAction(0,5,6);
	setAction(0,6,7);
	setAction(0,7,8);
	setAction(0,8,9);
	setAction(0,9,10);
	setAction(0,10,11);
	setAction(0,11,12);
	setAction(0,12,13);
	setAction(0,13,14);
	setAction(0,14,15);
	setAction(0,15,16);
	setAction(0,21,17);
	setAction(0,24,18);
	setAction(0,26,19);

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

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

      newActionTable(3,16);
	setAction(3,1,21);
	setAction(3,2,22);
	setAction(3,5,23);
	setAction(3,6,24);
	setAction(3,7,25);
	setAction(3,8,26);
	setAction(3,9,27);
	setAction(3,10,28);
	setAction(3,11,29);
	setAction(3,12,30);
	setAction(3,13,31);
	setAction(3,14,32);
	setAction(3,15,33);
	setAction(3,21,34);
	setAction(3,24,35);
	setAction(3,26,36);

      newActionTable(4,11);
	setAction(4,21,38);
	setAction(4,6,47);
	setAction(4,8,43);
	setAction(4,9,45);
	setAction(4,24,39);
	setAction(4,10,46);
	setAction(4,26,37);
	setAction(4,12,40);
	setAction(4,13,41);
	setAction(4,14,42);
	setAction(4,15,44);

      newActionTable(5,16);
	setAction(5,1,48);
	setAction(5,2,59);
	setAction(5,5,49);
	setAction(5,6,61);
	setAction(5,7,60);
	setAction(5,8,56);
	setAction(5,9,62);
	setAction(5,10,63);
	setAction(5,11,58);
	setAction(5,12,53);
	setAction(5,13,54);
	setAction(5,14,55);
	setAction(5,15,57);
	setAction(5,21,51);
	setAction(5,24,52);
	setAction(5,26,50);

      newActionTable(6,16);
	setAction(6,1,64);
	setAction(6,2,65);
	setAction(6,5,66);
	setAction(6,6,67);
	setAction(6,7,68);
	setAction(6,8,69);
	setAction(6,9,70);
	setAction(6,10,71);
	setAction(6,11,72);
	setAction(6,12,73);
	setAction(6,13,74);
	setAction(6,14,75);
	setAction(6,15,76);
	setAction(6,21,77);
	setAction(6,24,78);
	setAction(6,26,79);

      newActionTable(7,8);
	setAction(7,1,80);
	setAction(7,19,83);
	setAction(7,18,82);
	setAction(7,20,84);
	setAction(7,5,81);
	setAction(7,22,85);
	setAction(7,25,87);
	setAction(7,24,86);

      newActionTable(8,8);
	setAction(8,1,88);
	setAction(8,19,91);
	setAction(8,18,90);
	setAction(8,20,92);
	setAction(8,5,89);
	setAction(8,22,93);
	setAction(8,25,95);
	setAction(8,24,94);

      newActionTable(9,3);
	setAction(9,6,98);
	setAction(9,9,96);
	setAction(9,10,97);

      newActionTable(10,7);
	setAction(10,19,111);
	setAction(10,18,112);
	setAction(10,5,113);
	setAction(10,20,110);
	setAction(10,22,114);
	setAction(10,25,115);
	setAction(10,24,116);

      newActionTable(11,1);
	setAction(11,17,128);

      newActionTable(12,3);
	setAction(12,17,130);
	setAction(12,5,129);
	setAction(12,22,131);

      newActionTable(13,8);
	setAction(13,1,132);
	setAction(13,19,135);
	setAction(13,18,134);
	setAction(13,20,136);
	setAction(13,5,133);
	setAction(13,22,137);
	setAction(13,25,139);
	setAction(13,24,138);

      newActionTable(14,8);
	setAction(14,1,140);
	setAction(14,19,143);
	setAction(14,18,142);
	setAction(14,20,144);
	setAction(14,5,141);
	setAction(14,22,145);
	setAction(14,25,147);
	setAction(14,24,146);

      newActionTable(15,8);
	setAction(15,1,148);
	setAction(15,19,151);
	setAction(15,18,150);
	setAction(15,20,152);
	setAction(15,5,149);
	setAction(15,22,153);
	setAction(15,25,155);
	setAction(15,24,154);

      newActionTable(16,8);
	setAction(16,1,156);
	setAction(16,19,159);
	setAction(16,18,158);
	setAction(16,20,160);
	setAction(16,5,157);
	setAction(16,22,161);
	setAction(16,25,163);
	setAction(16,24,162);

      newActionTable(17,8);
	setAction(17,1,164);
	setAction(17,19,167);
	setAction(17,18,166);
	setAction(17,20,168);
	setAction(17,5,165);
	setAction(17,22,169);
	setAction(17,25,171);
	setAction(17,24,170);

      newActionTable(18,4);
	setAction(18,5,172);
	setAction(18,23,175);
	setAction(18,22,173);
	setAction(18,25,174);

      newActionTable(19,3);
	setAction(19,5,176);
	setAction(19,22,177);
	setAction(19,25,178);

      newActionTable(20,1);
	setAction(20,5,179);

      newActionTable(21,3);
	setAction(21,5,180);
	setAction(21,8,182);
	setAction(21,12,181);

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

      newActionTable(23,1);
	setAction(23,5,184);

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

      newActionTable(25,3);
	setAction(25,5,186);
	setAction(25,8,187);
	setAction(25,12,188);

      newActionTable(26,1);
	setAction(26,5,189);

      newActionTable(27,1);
	setAction(27,5,190);

      newActionTable(28,7);
	setAction(28,17,191);
	setAction(28,19,195);
	setAction(28,18,194);
	setAction(28,20,196);
	setAction(28,5,193);
	setAction(28,22,192);
	setAction(28,24,197);

      newActionTable(29,10);
	setAction(29,1,198);
	setAction(29,19,201);
	setAction(29,18,200);
	setAction(29,20,202);
	setAction(29,5,199);
	setAction(29,22,203);
	setAction(29,25,205);
	setAction(29,24,204);
	setAction(29,27,206);
	setAction(29,28,207);

      newActionTable(30,10);
	setAction(30,1,208);
	setAction(30,19,211);
	setAction(30,18,210);
	setAction(30,20,212);
	setAction(30,5,209);
	setAction(30,22,213);
	setAction(30,25,215);
	setAction(30,24,214);
	setAction(30,27,216);
	setAction(30,28,217);

      newActionTable(31,1);
	setAction(31,5,218);

      newActionTable(32,1);
	setAction(32,5,219);

      newActionTable(33,1);
	setAction(33,5,220);

      newActionTable(34,2);
	setAction(34,5,221);
	setAction(34,8,222);

      newActionTable(35,1);
	setAction(35,5,223);

      newActionTable(36,16);
	setAction(36,1,224);
	setAction(36,2,225);
	setAction(36,5,226);
	setAction(36,6,227);
	setAction(36,7,228);
	setAction(36,8,229);
	setAction(36,9,230);
	setAction(36,10,231);
	setAction(36,11,232);
	setAction(36,12,233);
	setAction(36,13,234);
	setAction(36,14,235);
	setAction(36,15,236);
	setAction(36,21,237);
	setAction(36,24,238);
	setAction(36,26,239);

      newActionTable(37,1);
	setAction(37,5,240);

      newActionTable(38,16);
	setAction(38,1,241);
	setAction(38,2,242);
	setAction(38,5,243);
	setAction(38,6,244);
	setAction(38,7,245);
	setAction(38,8,246);
	setAction(38,9,247);
	setAction(38,10,248);
	setAction(38,11,249);
	setAction(38,12,250);
	setAction(38,13,251);
	setAction(38,14,252);
	setAction(38,15,253);
	setAction(38,21,254);
	setAction(38,24,255);
	setAction(38,26,256);

      newActionTable(39,3);
	setAction(39,5,268);
	setAction(39,22,269);
	setAction(39,25,270);

      newActionTable(40,10);
	setAction(40,1,271);
	setAction(40,19,274);
	setAction(40,18,273);
	setAction(40,20,275);
	setAction(40,5,272);
	setAction(40,22,276);
	setAction(40,25,278);
	setAction(40,24,277);
	setAction(40,27,279);
	setAction(40,28,280);

      newActionTable(41,1);
	setAction(41,6,281);

      newActionTable(42,2);
	setAction(42,17,283);
	setAction(42,5,282);

      newActionTable(43,3);
	setAction(43,17,285);
	setAction(43,5,284);
	setAction(43,22,286);

      newActionTable(44,1);
	setAction(44,5,288);

      newActionTable(45,4);
	setAction(45,19,290);
	setAction(45,18,291);
	setAction(45,20,289);
	setAction(45,25,292);

      newActionTable(46,8);
	setAction(46,1,326);
	setAction(46,19,329);
	setAction(46,18,328);
	setAction(46,20,330);
	setAction(46,5,327);
	setAction(46,22,331);
	setAction(46,25,333);
	setAction(46,24,332);

      newActionTable(47,8);
	setAction(47,1,337);
	setAction(47,19,335);
	setAction(47,18,336);
	setAction(47,5,338);
	setAction(47,20,334);
	setAction(47,22,339);
	setAction(47,25,341);
	setAction(47,24,340);

      newActionTable(48,8);
	setAction(48,1,344);
	setAction(48,19,347);
	setAction(48,18,346);
	setAction(48,5,345);
	setAction(48,20,342);
	setAction(48,22,348);
	setAction(48,25,350);
	setAction(48,24,349);

      newActionTable(49,8);
	setAction(49,1,352);
	setAction(49,19,355);
	setAction(49,18,354);
	setAction(49,5,353);
	setAction(49,20,356);
	setAction(49,22,357);
	setAction(49,25,359);
	setAction(49,24,358);

      newActionTable(50,3);
	setAction(50,5,360);
	setAction(50,22,361);
	setAction(50,25,362);

      newActionTable(51,12);
	setAction(51,21,364);
	setAction(51,6,372);
	setAction(51,8,369);
	setAction(51,9,373);
	setAction(51,24,365);
	setAction(51,10,374);
	setAction(51,11,371);
	setAction(51,26,363);
	setAction(51,12,366);
	setAction(51,13,367);
	setAction(51,14,368);
	setAction(51,15,370);

      newActionTable(52,1);
	setAction(52,25,375);

      newActionTable(53,7);
	setAction(53,16,376);
	setAction(53,19,378);
	setAction(53,18,377);
	setAction(53,20,379);
	setAction(53,22,380);
	setAction(53,25,382);
	setAction(53,24,381);

      newActionTable(54,2);
	setAction(54,22,384);
	setAction(54,25,383);

      newActionTable(55,2);
	setAction(55,22,385);
	setAction(55,25,386);

      newActionTable(56,1);
	setAction(56,16,387);

      newActionTable(57,7);
	setAction(57,16,388);
	setAction(57,19,390);
	setAction(57,18,389);
	setAction(57,20,391);
	setAction(57,22,392);
	setAction(57,25,394);
	setAction(57,24,393);

      newActionTable(58,12);
	setAction(58,21,396);
	setAction(58,6,406);
	setAction(58,8,401);
	setAction(58,9,404);
	setAction(58,24,397);
	setAction(58,10,405);
	setAction(58,11,403);
	setAction(58,26,395);
	setAction(58,12,398);
	setAction(58,13,399);
	setAction(58,14,400);
	setAction(58,15,402);

      newActionTable(59,2);
	setAction(59,22,407);
	setAction(59,25,408);

      newActionTable(60,1);
	setAction(60,25,421);

      newActionTable(61,3);
	setAction(61,5,422);
	setAction(61,22,423);
	setAction(61,25,424);

      newActionTable(62,8);
	setAction(62,1,425);
	setAction(62,19,428);
	setAction(62,18,427);
	setAction(62,20,429);
	setAction(62,5,426);
	setAction(62,22,430);
	setAction(62,25,432);
	setAction(62,24,431);

      newActionTable(63,1);
	setAction(63,27,433);

      newActionTable(64,2);
	setAction(64,27,434);
	setAction(64,28,435);

      newActionTable(65,1);
	setAction(65,27,439);

      newActionTable(66,8);
	setAction(66,1,440);
	setAction(66,19,443);
	setAction(66,18,442);
	setAction(66,20,444);
	setAction(66,5,441);
	setAction(66,22,445);
	setAction(66,25,447);
	setAction(66,24,446);

      newActionTable(67,4);
	setAction(67,1,448);
	setAction(67,19,450);
	setAction(67,18,451);
	setAction(67,20,449);

      newActionTable(68,1);
	setAction(68,1,452);

    }

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

  static void initializeGotoTables ()
    {
      newGotoTables(22);

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

      newGotoTable(1,0);

      newGotoTable(2,2);
	setGoto(2,16,5);
	setGoto(2,2,77);

      newGotoTable(3,3);
	setGoto(3,3,76);
	setGoto(3,6,7);
	setGoto(3,25,8);

      newGotoTable(4,13);
	setGoto(4,17,6);
	setGoto(4,18,22);
	setGoto(4,3,11);
	setGoto(4,4,28);
	setGoto(4,21,23);
	setGoto(4,5,13);
	setGoto(4,23,25);
	setGoto(4,6,7);
	setGoto(4,22,24);
	setGoto(4,8,21);
	setGoto(4,25,8);
	setGoto(4,24,14);
	setGoto(4,10,29);

      newGotoTable(5,2);
	setGoto(5,7,71);
	setGoto(5,25,72);

      newGotoTable(6,3);
	setGoto(6,3,70);
	setGoto(6,6,7);
	setGoto(6,25,8);

      newGotoTable(7,1);
	setGoto(7,9,57);

      newGotoTable(8,3);
	setGoto(8,3,49);
	setGoto(8,6,7);
	setGoto(8,25,8);

      newGotoTable(9,2);
	setGoto(9,19,38);
	setGoto(9,20,39);

      newGotoTable(10,2);
	setGoto(10,14,33);
	setGoto(10,15,35);

      newGotoTable(11,1);
	setGoto(11,15,37);

      newGotoTable(12,4);
	setGoto(12,3,11);
	setGoto(12,6,7);
	setGoto(12,25,8);
	setGoto(12,8,42);

      newGotoTable(13,2);
	setGoto(13,5,45);
	setGoto(13,24,14);

      newGotoTable(14,2);
	setGoto(14,5,48);
	setGoto(14,24,14);

      newGotoTable(15,3);
	setGoto(15,3,56);
	setGoto(15,6,7);
	setGoto(15,25,8);

      newGotoTable(16,3);
	setGoto(16,3,55);
	setGoto(16,6,7);
	setGoto(16,25,8);

      newGotoTable(17,3);
	setGoto(17,3,54);
	setGoto(17,6,7);
	setGoto(17,25,8);

      newGotoTable(18,8);
	setGoto(18,3,11);
	setGoto(18,6,7);
	setGoto(18,8,21);
	setGoto(18,25,8);
	setGoto(18,10,62);
	setGoto(18,11,59);
	setGoto(18,12,61);
	setGoto(18,13,63);

      newGotoTable(19,5);
	setGoto(19,3,11);
	setGoto(19,6,7);
	setGoto(19,8,21);
	setGoto(19,25,8);
	setGoto(19,10,66);

      newGotoTable(20,8);
	setGoto(20,3,11);
	setGoto(20,6,7);
	setGoto(20,8,21);
	setGoto(20,25,8);
	setGoto(20,10,62);
	setGoto(20,11,68);
	setGoto(20,12,61);
	setGoto(20,13,63);

      newGotoTable(21,2);
	setGoto(21,7,74);
	setGoto(21,25,72);

    }

  /* ************ */
  /* 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,1);
      setTables(9,9,5);
      setTables(10,4,6);
      setTables(11,10,7);
      setTables(12,4,8);
      setTables(13,11,1);
      setTables(14,12,1);
      setTables(15,13,1);
      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,9);
      setTables(23,21,10);
      setTables(24,22,1);
      setTables(25,23,1);
      setTables(26,24,1);
      setTables(27,25,1);
      setTables(28,26,1);
      setTables(29,27,1);
      setTables(30,28,1);
      setTables(31,29,1);
      setTables(32,30,1);
      setTables(33,31,1);
      setTables(34,32,1);
      setTables(35,33,1);
      setTables(36,34,11);
      setTables(37,35,1);
      setTables(38,36,1);
      setTables(39,37,1);
      setTables(40,38,1);
      setTables(41,4,12);
      setTables(42,39,1);
      setTables(43,40,1);
      setTables(44,41,13);
      setTables(45,42,1);
      setTables(46,43,1);
      setTables(47,41,14);
      setTables(48,44,1);
      setTables(49,45,1);
      setTables(50,4,15);
      setTables(51,4,16);
      setTables(52,4,17);
      setTables(53,46,1);
      setTables(54,47,1);
      setTables(55,48,1);
      setTables(56,49,1);
      setTables(57,50,1);
      setTables(58,51,18);
      setTables(59,52,1);
      setTables(60,53,1);
      setTables(61,54,1);
      setTables(62,55,1);
      setTables(63,56,1);
      setTables(64,57,1);
      setTables(65,58,19);
      setTables(66,59,1);
      setTables(67,51,20);
      setTables(68,60,1);
      setTables(69,61,1);
      setTables(70,62,1);
      setTables(71,63,1);
      setTables(72,64,1);
      setTables(73,9,21);
      setTables(74,65,1);
      setTables(75,66,1);
      setTables(76,67,1);
      setTables(77,68,1);
    }
}

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

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

  Stack lhs;
  Stack rhs;
}

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

  Stack symbols;
}

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

  Stack sortList;
}

class OsfV1UntaggedPsiTerm extends OsfV1Body_opt 
{
  OsfV1UntaggedPsiTerm (ParseNode node)
    {
      super(node);
    }

  SortExpression sort;
}

class OsfV1PsiTerm extends OsfV1UntaggedPsiTerm 
{
  OsfV1PsiTerm (ParseNode node)
    {
      super(node);
    }

  String tag;
}

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

  Stack keys;
  Stack subterms;
}

class OsfV1SubTerms extends OsfV1Body_opt 
{
  OsfV1SubTerms (ParseNode node)
    {
      super(node);
    }

  
}

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

  Object key;
  Object psiterm;
}

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

  Object feature;
}

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

  Stack args;
}

class OsfV1FileList extends ParseNode 
{
  OsfV1FileList (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 ************************* */
/* ************************************************************************ */

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

