// *******************************************************************
// This file has been automatically generated from the grammar in file
// OsfV0.grm by hlt.language.syntax.ParserGenerator on
// Mon Jan 21 09:41:41 CET 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 OSF execution context.
 */
Context context = new Context();

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

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

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

/**
 * This is where the "is-a" declarations are stored.
 */
ArrayList isaDeclarations = new ArrayList(50);

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


void declareIsa (String s1, String s2) throws LockedCodeArrayException
{
  context.declareIsa(s1,s2,location);
}

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

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
    {
      displayLine(pst.displayForm());
    }
  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());
      time = System.currentTimeMillis() - time;
      if (isTiming)
	displayLine("*** Processing time = "+time+" ms");
    }
  catch (RuntimeException e)
    {
      logError(new Error().setMsg(e.getMessage()));
    }
}

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

static boolean isTiming, 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 (isTiming)
    displayLine("*** 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 tokeniser'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. Note that '%include
      // "foo.osf". %encode.' on the same line works. But the supoosedly
      // equivalent pragma '%load "foo.osf.' as defined below gives an
      // even weirder bug!
      includeFiles((Stack)args);
      return;
    }

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

  if (pragma == "load")
    { // This gives a strange bug !!!
      includeFiles((Stack)args);
      encodeSorts();
      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")
    {
      computeDescendants((SortExpression)args.get(0));
      return;
    }	

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

  if (pragma == "maximals")
    {
      try
      	{
  	  displayLine("*** "+displayForm(context.top().getChildren()));
      	}
      catch (RuntimeException e)
      	{
      	  logError(new Error().setMsg(e.getMessage()));
      	}
      return;
    }	

  if (pragma == "minimals")
    {
      try
      	{
  	  displayLine("*** Minimal sorts:");
  	  displayLine("*** "+displayForm(context.bottom().getParents()));
      	}
      catch (RuntimeException e)
      	{
      	  logError(new Error().setMsg(e.getMessage()));
      	}
      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")
    {
      isTiming = !isTiming;
      displayLine("*** Processing timing has been turned "+(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:
      BitCode value = exp.value();

      // check the code cache in case this value is a defined sort symbol:
      Object sort = context.codeCache().get(value);

      // if so, just display its parents:
      if (sort instanceof Sort)
	{
	  displayParents((Sort)sort);
	  return;
	}

      // if not, compute its MUBs and display them:
      displayLine("*** "+displayForm(context.taxonomy().minUpperBounds(value)));

    }
  catch (RuntimeException e)
    {
      logError(new Error().setMsg(e.getMessage()));
    }
}

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

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

/**
 * 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:
      BitCode value = exp.value();

      // check the code cache in case this value is a defined sort symbol:
      Object sort = context.codeCache().get(value);

      // if so, just display its children:
      if (sort instanceof Sort)
	{
	  displayChildren((Sort)sort);
	  return;
	}

      // if not, compute its MLBs and display them:
      displayLine("*** "+displayForm(context.taxonomy().maxLowerBounds(value)));

    }
  catch (RuntimeException e)
    {
      logError(new Error().setMsg(e.getMessage()));
    }
}

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

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

/**
 * This loads the specified file names in the specified list. Each file
 * name 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();
      // displayLine("*** Including file: "+fileName);

      try
	{
	  ((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));
	}

      displayLine("*** Included 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 computeDescendants (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()));
	  return;
	}

      // otherwise, evaluate the expression:
      BitCode value = exp.value();

      // check the code cache in case this value is a defined sort symbol:
      Object sort = context.codeCache().get(value);

      // if so, just display its descendants:
      if (sort instanceof Sort)
	{
	  displayLine("*** "+displayForm(((Sort)sort).descendants()));
	  return;
	}

      // otherwise, display the value code as the set of all its descendants:
      displayLine("*** "+displayForm(value));

    }
  catch (RuntimeException e)
    {
      logError(new Error().setMsg(e.getMessage()));
    }
}

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

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

      // otherwise, evaluate the expression:
      BitCode value = exp.value();

      // check the code cache in case this value is a defined sort symbol:
      Object sort = context.codeCache().get(value);

      // if so, just display its ancestors:
      if (sort instanceof Sort)
	{
	  displayLine("*** "+displayForm(((Sort)sort).ancestors()));
	  return;
	}

      // otherwise, compute and display the value code's ancestors -
      // except top, unless there are no other ancestors:
      BitCode ancestors = new BitCode();
      Taxonomy taxonomy = context.taxonomy();
      for (int i=taxonomy.size()-1; i-->0;)
	{
	  Sort s = (Sort)taxonomy.get(i);
	  if (s.code.isContainedIn(value))
	    break;	// no need to go further
	  if (value.isContainedIn(s.code))
	    ancestors.add(s.index);
	}
      if (ancestors.isEmpty())
	displayLine("*** "+dfm.displayTopForm());
      else
	displayLine("*** "+displayForm(ancestors));
    }
  catch (RuntimeException e)
    {
      logError(new Error().setMsg(e.getMessage()));
    }
}

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

/**
 * This proceeds to encoding the sorts declared thus far and locks the
 * sort taxonomy (i.e., no new sorts may be declared until this
 * taxononmy is erased - see the '%clear' 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 and process the given file (name specified as a quoted string)");
  displayLine("\t     %encode  encode the current sort taxonomy");

  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 current sort taxonomy");

  displayLine("\t   %evaluate  toggle on/off automatic sort evaluation");
  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        %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     %timing  toggle on/off execution timing");
  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();
}

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

// final void processExpression (Expression expression)
// {
//   setLocation();

//   Expression exp = compile(expression);

//   if (!error)
//     {
//       try
// 	{
// 	  Type type = exp.checkedType();

// 	  time = System.currentTimeMillis();
// 	  runtime.run(compiler.code());
// 	  time = System.currentTimeMillis() - time;

// 	  Type.resetNames();
// 	  dm.clearTags();
// 	  String s = " : " + type.toQuantifiedString();

// 	  if (type.isVoid())
// 	    s = dm.displayVoid() + s;
// 	  else
// 	    switch (runtime.resultSort())
// 	      {
// 	      case Type.INT_SORT:
// 		s = dm.displayForm(runtime.intResult(),type) + s;
// 		break;
// 	      case Type.REAL_SORT:
// 		s = dm.displayForm(runtime.realResult()) + s;
// 		break;
// 	      default:
// 		s = dm.displayForm(runtime.objectResult(),type) + s;
// 		break;
// 	      }
// 	  displayLine("*** "+s);
// 	}
//       catch (ArrayIndexOutOfBoundsException e)
// 	{
// 	  logError(dynamicSemanticsError("(array bound violation)",exp));
// 	  //e.printStackTrace();
// 	}
//       catch (DynamicSemanticsErrorException e)
// 	{
// 	  logError(dynamicSemanticsError(e.msg(),exp));
// 	  //e.printStackTrace();
// 	}
//       catch (Exception e)
// 	{
// 	  logError(dynamicSemanticsError(e.toString(),exp));
// 	  e.printStackTrace();
// 	}
//     }
// }


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

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

/**
 * The display form manager.
 */
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());
}

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

/**
 * 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.
 */
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();
    }

  /* **************** */
  /* 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 7:
            {
            commitParse();
            break;
            }
          case 10:
            {
            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 14:
            {
            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 15:
            {
            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 17:
            {
            OsfV0SortSymbols $node0$ = new OsfV0SortSymbols($head$);
                 $head$ = (OsfV0SortSymbols)$node0$;

        $node0$.symbols = new Stack();
        $node0$.symbols.push(node($rule$,1).svalue());
            break;
            }
          case 18:
            {
            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 19:
            {
            OsfV0PsiTerm $node1$;
                if (node($rule$,1) instanceof OsfV0PsiTerm)
                   $node1$ = (OsfV0PsiTerm)node($rule$,1);
                 else
                 {
                     $node1$ = new OsfV0PsiTerm(node($rule$,1));
                     replaceStackNode($rule$,1,$node1$);
                   }

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

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

        $node0$.sort = $node1$.sort;
        $node0$.keys = $node1$.keys;
        $node0$.subterms = $node1$.subterms;
            break;
            }
          case 22:
            {
            OsfV0PsiTerm $node0$ = new OsfV0PsiTerm($head$);
                 $head$ = (OsfV0PsiTerm)$node0$;
    OsfV0UntaggedPsiTerm $node3$;
                if (node($rule$,3) instanceof OsfV0UntaggedPsiTerm)
                   $node3$ = (OsfV0UntaggedPsiTerm)node($rule$,3);
                 else
                 {
                     $node3$ = new OsfV0UntaggedPsiTerm(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 23:
            {
            OsfV0UntaggedPsiTerm $node0$ = new OsfV0UntaggedPsiTerm($head$);
                 $head$ = (OsfV0UntaggedPsiTerm)$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$);
                   }
    OsfV0Body_opt $node2$;
                if (node($rule$,2) instanceof OsfV0Body_opt)
                   $node2$ = (OsfV0Body_opt)node($rule$,2);
                 else
                 {
                     $node2$ = new OsfV0Body_opt(node($rule$,2));
                     replaceStackNode($rule$,2,$node2$);
                   }

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

        $node0$.keys = $node2$.keys;
        $node0$.subterms = $node2$.subterms;
            break;
            }
          case 26:
            {
            OsfV0SubTerms $node0$ = new OsfV0SubTerms($head$);
                 $head$ = (OsfV0SubTerms)$node0$;
    OsfV0SubTerm $node1$;
                if (node($rule$,1) instanceof OsfV0SubTerm)
                   $node1$ = (OsfV0SubTerm)node($rule$,1);
                 else
                 {
                     $node1$ = new OsfV0SubTerm(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 27:
            {
            OsfV0SubTerms $node0$ = new OsfV0SubTerms($head$);
                 $head$ = (OsfV0SubTerms)$node0$;
    OsfV0SubTerms $node3$;
                if (node($rule$,3) instanceof OsfV0SubTerms)
                   $node3$ = (OsfV0SubTerms)node($rule$,3);
                 else
                 {
                     $node3$ = new OsfV0SubTerms(node($rule$,3));
                     replaceStackNode($rule$,3,$node3$);
                   }
    OsfV0SubTerm $node1$;
                if (node($rule$,1) instanceof OsfV0SubTerm)
                   $node1$ = (OsfV0SubTerm)node($rule$,1);
                 else
                 {
                     $node1$ = new OsfV0SubTerm(node($rule$,1));
                     replaceStackNode($rule$,1,$node1$);
                   }

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

        $node0$.key = null;
        $node0$.psiterm = new RawPsiTerm($node1$.tag,$node1$.sort,$node1$.keys,$node1$.subterms);
            break;
            }
          case 29:
            {
            OsfV0SubTerm $node0$ = new OsfV0SubTerm($head$);
                 $head$ = (OsfV0SubTerm)$node0$;
    OsfV0Feature $node1$;
                if (node($rule$,1) instanceof OsfV0Feature)
                   $node1$ = (OsfV0Feature)node($rule$,1);
                 else
                 {
                     $node1$ = new OsfV0Feature(node($rule$,1));
                     replaceStackNode($rule$,1,$node1$);
                   }
    OsfV0PsiTerm $node3$;
                if (node($rule$,3) instanceof OsfV0PsiTerm)
                   $node3$ = (OsfV0PsiTerm)node($rule$,3);
                 else
                 {
                     $node3$ = new OsfV0PsiTerm(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 30:
            {
            OsfV0Feature $node0$ = new OsfV0Feature($head$);
                 $head$ = (OsfV0Feature)$node0$;

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

        $node0$.feature = node($rule$,1).svalue();
            break;
            }
          case 32:
            {
            OsfV0SortExpression $node0$ = new OsfV0SortExpression($head$);
                 $head$ = (OsfV0SortExpression)$node0$;

        $node0$.expression = new SymbolSortExpression(node($rule$,1).svalue(),context);
            break;
            }
          case 33:
            {
            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 34:
            {
            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 35:
            {
            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 36:
            {
            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 37:
            {
            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 38:
            {
            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 42:
            {
            OsfV0SortList $node0$ = new OsfV0SortList($head$);
                 $head$ = (OsfV0SortList)$node0$;

        $node0$.sortList = new Stack();
        $node0$.sortList.push(node($rule$,1).svalue());
            break;
            }
          case 43:
            {
            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 46:
            {
            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 47:
            {
            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 48:
            {
            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 49:
            {
            OsfV0FileList $node0$ = new OsfV0FileList($head$);
                 $head$ = (OsfV0FileList)$node0$;

        $node0$.files = new Stack();
        $node0$.files.push(node($rule$,1).svalue());
            break;
            }
          case 50:
            {
            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 4: case 9: case 24: case 45: 
            break;
          default:
            $head$ = $head$.copy(node($rule$,1));
            break;
        }
      return $head$;
    }

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

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

      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,"EOS",1,2);
      newTerminal(5,"IDENTIFIER",11,2);
      newTerminal(6,"PRAGMA",11,2);
      newTerminal(7,"STRING",11,2);
      newTerminal(8,"TOP",11,2);
      newTerminal(9,"BOTTOM",11,2);
      newTerminal(10,"TAG",11,2);
      newTerminal(11,"INTEGER",11,2);
      newTerminal(12,"ARROW",21,2);
      newTerminal(13,"ISA",31,2);
      newTerminal(14,"BUTNOT",41,1);
      newTerminal(15,"AND",51,0);
      newTerminal(16,"OR",61,0);
      newTerminal(17,"NOT",71,1);
      newTerminal(18,",",1,2);
      newTerminal(19,":",1,2);
      newTerminal(20,"(",1,2);
      newTerminal(21,")",1,2);
      newTerminal(22,"{",1,2);
      newTerminal(23,"}",1,2);
      newTerminal(24,";",1,2);
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

  static void initializeActionTables ()
    {
      newActionTables(63);

      newActionTable(0,12);
	setAction(0,17,11);
	setAction(0,1,3);
	setAction(0,2,4);
	setAction(0,3,2);
	setAction(0,4,5);
	setAction(0,20,12);
	setAction(0,5,6);
	setAction(0,6,7);
	setAction(0,22,13);
	setAction(0,8,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,11);
	setAction(3,17,23);
	setAction(3,1,15);
	setAction(3,2,16);
	setAction(3,4,17);
	setAction(3,20,24);
	setAction(3,5,18);
	setAction(3,6,19);
	setAction(3,22,25);
	setAction(3,8,20);
	setAction(3,9,21);
	setAction(3,10,22);

      newActionTable(4,11);
	setAction(4,17,29);
	setAction(4,1,26);
	setAction(4,2,32);
	setAction(4,4,27);
	setAction(4,5,34);
	setAction(4,20,30);
	setAction(4,6,33);
	setAction(4,22,28);
	setAction(4,8,35);
	setAction(4,9,36);
	setAction(4,10,31);

      newActionTable(5,11);
	setAction(5,17,45);
	setAction(5,1,37);
	setAction(5,2,38);
	setAction(5,4,39);
	setAction(5,20,46);
	setAction(5,5,40);
	setAction(5,6,41);
	setAction(5,22,47);
	setAction(5,8,42);
	setAction(5,9,43);
	setAction(5,10,44);

      newActionTable(6,1);
	setAction(6,13,48);

      newActionTable(7,3);
	setAction(7,18,51);
	setAction(7,4,49);
	setAction(7,13,50);

      newActionTable(8,12);
	setAction(8,17,59);
	setAction(8,16,58);
	setAction(8,18,60);
	setAction(8,21,62);
	setAction(8,4,52);
	setAction(8,20,61);
	setAction(8,5,53);
	setAction(8,22,63);
	setAction(8,8,54);
	setAction(8,9,55);
	setAction(8,14,56);
	setAction(8,15,57);

      newActionTable(9,3);
	setAction(9,5,66);
	setAction(9,8,64);
	setAction(9,9,65);

      newActionTable(10,6);
	setAction(10,17,68);
	setAction(10,5,72);
	setAction(10,20,69);
	setAction(10,22,67);
	setAction(10,8,70);
	setAction(10,9,71);

      newActionTable(11,7);
	setAction(11,16,74);
	setAction(11,18,77);
	setAction(11,21,78);
	setAction(11,4,76);
	setAction(11,20,79);
	setAction(11,14,75);
	setAction(11,15,73);

      newActionTable(12,4);
	setAction(12,19,89);
	setAction(12,18,87);
	setAction(12,21,88);
	setAction(12,4,86);

      newActionTable(13,3);
	setAction(13,18,91);
	setAction(13,21,92);
	setAction(13,4,90);

      newActionTable(14,1);
	setAction(14,4,93);

      newActionTable(15,8);
	setAction(15,17,95);
	setAction(15,4,97);
	setAction(15,5,101);
	setAction(15,20,96);
	setAction(15,7,98);
	setAction(15,22,94);
	setAction(15,8,99);
	setAction(15,9,100);

      newActionTable(16,1);
	setAction(16,4,102);

      newActionTable(17,1);
	setAction(17,4,103);

      newActionTable(18,1);
	setAction(18,4,104);

      newActionTable(19,8);
	setAction(19,17,110);
	setAction(19,4,105);
	setAction(19,20,111);
	setAction(19,5,106);
	setAction(19,22,112);
	setAction(19,7,107);
	setAction(19,8,108);
	setAction(19,9,109);

      newActionTable(20,1);
	setAction(20,4,113);

      newActionTable(21,1);
	setAction(21,4,114);

      newActionTable(22,7);
	setAction(22,16,120);
	setAction(22,18,116);
	setAction(22,4,117);
	setAction(22,20,121);
	setAction(22,13,115);
	setAction(22,14,118);
	setAction(22,15,119);

      newActionTable(23,14);
	setAction(23,4,122);
	setAction(23,5,123);
	setAction(23,8,124);
	setAction(23,9,125);
	setAction(23,14,126);
	setAction(23,15,127);
	setAction(23,17,129);
	setAction(23,16,128);
	setAction(23,18,130);
	setAction(23,21,132);
	setAction(23,20,131);
	setAction(23,23,134);
	setAction(23,22,133);
	setAction(23,24,135);

      newActionTable(24,14);
	setAction(24,4,136);
	setAction(24,5,137);
	setAction(24,8,138);
	setAction(24,9,139);
	setAction(24,14,140);
	setAction(24,15,141);
	setAction(24,17,143);
	setAction(24,16,142);
	setAction(24,18,144);
	setAction(24,21,146);
	setAction(24,20,145);
	setAction(24,23,148);
	setAction(24,22,147);
	setAction(24,24,149);

      newActionTable(25,1);
	setAction(25,4,150);

      newActionTable(26,10);
	setAction(26,17,156);
	setAction(26,16,152);
	setAction(26,4,154);
	setAction(26,5,160);
	setAction(26,20,157);
	setAction(26,22,155);
	setAction(26,8,158);
	setAction(26,9,159);
	setAction(26,14,153);
	setAction(26,15,151);

      newActionTable(27,1);
	setAction(27,4,161);

      newActionTable(28,2);
	setAction(28,4,162);
	setAction(28,7,163);

      newActionTable(29,14);
	setAction(29,4,164);
	setAction(29,5,165);
	setAction(29,8,166);
	setAction(29,9,167);
	setAction(29,14,168);
	setAction(29,15,169);
	setAction(29,17,171);
	setAction(29,16,170);
	setAction(29,18,172);
	setAction(29,21,174);
	setAction(29,20,173);
	setAction(29,23,176);
	setAction(29,22,175);
	setAction(29,24,177);

      newActionTable(30,1);
	setAction(30,4,178);

      newActionTable(31,4);
	setAction(31,16,198);
	setAction(31,4,200);
	setAction(31,14,199);
	setAction(31,15,197);

      newActionTable(32,12);
	setAction(32,17,208);
	setAction(32,16,202);
	setAction(32,18,209);
	setAction(32,21,211);
	setAction(32,4,204);
	setAction(32,20,210);
	setAction(32,5,205);
	setAction(32,22,212);
	setAction(32,8,206);
	setAction(32,9,207);
	setAction(32,14,203);
	setAction(32,15,201);

      newActionTable(33,12);
	setAction(33,17,222);
	setAction(33,16,221);
	setAction(33,18,223);
	setAction(33,21,225);
	setAction(33,4,215);
	setAction(33,20,224);
	setAction(33,5,216);
	setAction(33,22,226);
	setAction(33,8,217);
	setAction(33,9,218);
	setAction(33,14,219);
	setAction(33,15,220);

      newActionTable(34,12);
	setAction(34,17,235);
	setAction(34,16,240);
	setAction(34,18,236);
	setAction(34,21,238);
	setAction(34,4,228);
	setAction(34,20,237);
	setAction(34,5,229);
	setAction(34,22,239);
	setAction(34,8,230);
	setAction(34,9,231);
	setAction(34,14,232);
	setAction(34,15,233);

      newActionTable(35,11);
	setAction(35,17,249);
	setAction(35,1,241);
	setAction(35,2,242);
	setAction(35,4,243);
	setAction(35,20,250);
	setAction(35,5,244);
	setAction(35,6,245);
	setAction(35,22,251);
	setAction(35,8,246);
	setAction(35,9,247);
	setAction(35,10,248);

      newActionTable(36,1);
	setAction(36,4,252);

      newActionTable(37,11);
	setAction(37,17,261);
	setAction(37,1,253);
	setAction(37,2,254);
	setAction(37,4,255);
	setAction(37,20,262);
	setAction(37,5,256);
	setAction(37,6,257);
	setAction(37,22,263);
	setAction(37,8,258);
	setAction(37,9,259);
	setAction(37,10,260);

      newActionTable(38,3);
	setAction(38,18,271);
	setAction(38,21,272);
	setAction(38,4,270);

      newActionTable(39,4);
	setAction(39,16,274);
	setAction(39,21,276);
	setAction(39,14,275);
	setAction(39,15,273);

      newActionTable(40,12);
	setAction(40,17,284);
	setAction(40,16,283);
	setAction(40,18,285);
	setAction(40,21,287);
	setAction(40,4,277);
	setAction(40,20,286);
	setAction(40,5,278);
	setAction(40,22,288);
	setAction(40,8,279);
	setAction(40,9,280);
	setAction(40,14,281);
	setAction(40,15,282);

      newActionTable(41,3);
	setAction(41,18,290);
	setAction(41,21,291);
	setAction(41,4,289);

      newActionTable(42,8);
	setAction(42,17,293);
	setAction(42,5,297);
	setAction(42,20,294);
	setAction(42,22,292);
	setAction(42,8,298);
	setAction(42,9,299);
	setAction(42,10,295);
	setAction(42,11,296);

      newActionTable(43,1);
	setAction(43,21,300);

      newActionTable(44,2);
	setAction(44,18,302);
	setAction(44,21,301);

      newActionTable(45,2);
	setAction(45,18,303);
	setAction(45,21,304);

      newActionTable(46,1);
	setAction(46,12,305);

      newActionTable(47,1);
	setAction(47,12,306);

      newActionTable(48,7);
	setAction(48,16,310);
	setAction(48,18,311);
	setAction(48,21,313);
	setAction(48,20,312);
	setAction(48,12,307);
	setAction(48,14,308);
	setAction(48,15,309);

      newActionTable(49,7);
	setAction(49,17,315);
	setAction(49,5,320);
	setAction(49,20,316);
	setAction(49,22,314);
	setAction(49,8,318);
	setAction(49,9,319);
	setAction(49,10,317);

      newActionTable(50,2);
	setAction(50,18,321);
	setAction(50,21,322);

      newActionTable(51,1);
	setAction(51,21,331);

      newActionTable(52,3);
	setAction(52,18,333);
	setAction(52,21,334);
	setAction(52,4,332);

      newActionTable(53,12);
	setAction(53,17,342);
	setAction(53,16,341);
	setAction(53,18,343);
	setAction(53,21,345);
	setAction(53,4,335);
	setAction(53,20,344);
	setAction(53,5,336);
	setAction(53,22,346);
	setAction(53,8,337);
	setAction(53,9,338);
	setAction(53,14,339);
	setAction(53,15,340);

      newActionTable(54,1);
	setAction(54,23,347);

      newActionTable(55,2);
	setAction(55,23,348);
	setAction(55,24,349);

      newActionTable(56,1);
	setAction(56,23,353);

      newActionTable(57,12);
	setAction(57,17,361);
	setAction(57,16,360);
	setAction(57,18,362);
	setAction(57,21,364);
	setAction(57,4,354);
	setAction(57,20,363);
	setAction(57,5,355);
	setAction(57,22,365);
	setAction(57,8,356);
	setAction(57,9,357);
	setAction(57,14,358);
	setAction(57,15,359);

      newActionTable(58,1);
	setAction(58,5,366);

      newActionTable(59,2);
	setAction(59,4,367);
	setAction(59,13,368);

      newActionTable(60,3);
	setAction(60,18,371);
	setAction(60,4,369);
	setAction(60,13,370);

      newActionTable(61,1);
	setAction(61,4,373);

      newActionTable(62,1);
	setAction(62,1,374);

    }

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

  static void initializeGotoTables ()
    {
      newGotoTables(22);

      newGotoTable(0,3);
	setGoto(0,1,1);
	setGoto(0,2,2);
	setGoto(0,15,4);

      newGotoTable(1,0);

      newGotoTable(2,2);
	setGoto(2,2,70);
	setGoto(2,15,4);

      newGotoTable(3,12);
	setGoto(3,17,15);
	setGoto(3,16,5);
	setGoto(3,3,21);
	setGoto(3,21,17);
	setGoto(3,4,6);
	setGoto(3,20,16);
	setGoto(3,5,11);
	setGoto(3,23,7);
	setGoto(3,22,18);
	setGoto(3,7,14);
	setGoto(3,9,22);
	setGoto(3,24,8);

      newGotoTable(4,2);
	setGoto(4,6,60);
	setGoto(4,24,61);

      newGotoTable(5,2);
	setGoto(5,5,59);
	setGoto(5,24,8);

      newGotoTable(6,1);
	setGoto(6,8,46);

      newGotoTable(7,2);
	setGoto(7,5,44);
	setGoto(7,24,8);

      newGotoTable(8,2);
	setGoto(8,19,40);
	setGoto(8,18,39);

      newGotoTable(9,4);
	setGoto(9,5,27);
	setGoto(9,24,8);
	setGoto(9,13,26);
	setGoto(9,14,28);

      newGotoTable(10,2);
	setGoto(10,5,35);
	setGoto(10,24,8);

      newGotoTable(11,1);
	setGoto(11,14,31);

      newGotoTable(12,2);
	setGoto(12,5,38);
	setGoto(12,24,8);

      newGotoTable(13,2);
	setGoto(13,5,37);
	setGoto(13,24,8);

      newGotoTable(14,2);
	setGoto(14,5,36);
	setGoto(14,24,8);

      newGotoTable(15,3);
	setGoto(15,5,11);
	setGoto(15,7,43);
	setGoto(15,24,8);

      newGotoTable(16,7);
	setGoto(16,5,11);
	setGoto(16,7,14);
	setGoto(16,9,50);
	setGoto(16,24,8);
	setGoto(16,10,48);
	setGoto(16,11,49);
	setGoto(16,12,51);

      newGotoTable(17,4);
	setGoto(17,5,11);
	setGoto(17,7,14);
	setGoto(17,24,8);
	setGoto(17,9,55);

      newGotoTable(18,7);
	setGoto(18,5,11);
	setGoto(18,7,14);
	setGoto(18,9,50);
	setGoto(18,24,8);
	setGoto(18,10,57);
	setGoto(18,11,49);
	setGoto(18,12,51);

      newGotoTable(19,2);
	setGoto(19,6,63);
	setGoto(19,24,61);

      newGotoTable(20,2);
	setGoto(20,4,66);
	setGoto(20,23,7);

      newGotoTable(21,2);
	setGoto(21,4,69);
	setGoto(21,23,7);

    }

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

  SortExpression expression;
}

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

  Stack sortList;
}

class OsfV0UntaggedPsiTerm extends OsfV0Body_opt 
{
  OsfV0UntaggedPsiTerm (ParseNode node)
    {
      super(node);
    }

  SortExpression sort;
}

class OsfV0PsiTerm extends OsfV0UntaggedPsiTerm 
{
  OsfV0PsiTerm (ParseNode node)
    {
      super(node);
    }

  String tag;
}

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

  Stack keys;
  Stack subterms;
}

class OsfV0SubTerms extends OsfV0Body_opt 
{
  OsfV0SubTerms (ParseNode node)
    {
      super(node);
    }

  
}

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

  Object key;
  Object psiterm;
}

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

  Object feature;
}

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 ************************* */
/* ************************************************************************ */

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

