// *******************************************************************
// This file has been automatically generated from the grammar in file
// OsfV2.grm by hlt.language.syntax.ParserGenerator on
// Tue Feb 18 10:24:44 CET 2014 --- !!! PLEASE DO NO EDIT !!!
// *******************************************************************

package hlt.osf.v2;

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

  public OsfV2Parser (Tokenizer t)
    {
      input = t;
      xmlroot = "OsfExpression";
      xmlRootNSPrefix = "osf";
      String[] ns = {"osf","http://cedar.liris.cnrs.fr/osf"};
      namespaces = ns;
    }

  /* ************************* */
  /* 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 flag is used to control secondary parsing and xml display of a
 * normalized osf term.
 */
static boolean showXml = true;
static OsfV2Tokenizer stringTokenizer;
static OsfV2Parser stringParser;
static
  { if (stringParser == null)
      {
	stringTokenizer = new OsfV2Tokenizer();
	stringParser = new OsfV2Parser(stringTokenizer);
      }
  }

/**
 * 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)
{
  // build and normalize the parsed psiterm:
  PsiTerm pst = buildPsiTerm(new HashSet(),Tag.getTag(tag),sort,keys,subterms);
  // generate a string display form for the normalized psiterm:
  String psiTermString = pst.displayForm(4); // margin is 4 to account for "*** "

  try
    {
      time = System.currentTimeMillis();
      // display the normalized psiterm:
      displayLine("*** "+psiTermString);
      // Tag.tallyTags();	// show known tags
      Tag.clearKnownTags();	// clear the tags
      time = System.currentTimeMillis() - time;
      if (Context.isTiming())
	displayLine("*** Processing time = "+time+" ms");

      // display the XML form of the psiterm as it was parsed:
      System.out.println("*** XML form of "+(showXml ? "original" : "normalized")+" psiterm:");
      writeXml(currentNode(),System.out);

      if (showXml)
	{
	  // reparse the normalized psiterm string to display its XML tree:
	  showXml = false;
	  stringParser.parseOsfExpression(psiTermString);
      	}

      showXml = true;
    }
  catch (RuntimeException e)
    {
      logError(new Error().setMsg(e.getMessage()));
      e.printStackTrace();
    }
  catch (Exception e)	// for writeXml ...
    {
      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")
    OsfV2Main.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 V2 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);
	  ((OsfV2Tokenizer)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 (((OsfV2Tokenizer)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 ()
{
  ((OsfV2Tokenizer)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 $OSFV2PROGRAM_SWITCH$ = new ParseNode(terminals[3]);

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

  public final void parseOsfV2Program (Reader r) throws IOException
    {
      input.setReader(r);
      errorManager().recoverFromErrors(false);
      setSwitchToken($OSFV2PROGRAM_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();
    }

  final static ParseNode $OSFEXPRESSION_SWITCH$ = new ParseNode(terminals[5]);

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

  public final void parseOsfExpression (Reader r) throws IOException
    {
      input.setReader(r);
      errorManager().recoverFromErrors(false);
      setSwitchToken($OSFEXPRESSION_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 4:
            {
            $head$ = $head$.copy(node($rule$,2));
            break;
            }
          case 9:
            {
            commitParse();
            break;
            }
          case 12:
            {
            OsfV2PragmaArguments_opt $node2$;
                if (node($rule$,2) instanceof OsfV2PragmaArguments_opt)
                   $node2$ = (OsfV2PragmaArguments_opt)node($rule$,2);
                 else
                 {
                     $node2$ = new OsfV2PragmaArguments_opt(node($rule$,2));
                     replaceStackNode($rule$,2,$node2$);
                   }

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

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

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

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

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

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

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

        $node0$.sort = $node1$.sort;
        $node0$.keys = $node1$.keys;
        $node0$.subterms = $node1$.subterms;
            break;
            }
          case 24:
            {
            OsfV2PsiTerm $node0$ = new OsfV2PsiTerm($head$);
                 $head$ = (OsfV2PsiTerm)$node0$;
    OsfV2UntaggedPsiTerm $node3$;
                if (node($rule$,3) instanceof OsfV2UntaggedPsiTerm)
                   $node3$ = (OsfV2UntaggedPsiTerm)node($rule$,3);
                 else
                 {
                     $node3$ = new OsfV2UntaggedPsiTerm(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 25:
            {
            OsfV2UntaggedPsiTerm $node0$ = new OsfV2UntaggedPsiTerm($head$);
                 $head$ = (OsfV2UntaggedPsiTerm)$node0$;
    OsfV2SortExpression $node1$;
                if (node($rule$,1) instanceof OsfV2SortExpression)
                   $node1$ = (OsfV2SortExpression)node($rule$,1);
                 else
                 {
                     $node1$ = new OsfV2SortExpression(node($rule$,1));
                     replaceStackNode($rule$,1,$node1$);
                   }
    OsfV2Body_opt $node2$;
                if (node($rule$,2) instanceof OsfV2Body_opt)
                   $node2$ = (OsfV2Body_opt)node($rule$,2);
                 else
                 {
                     $node2$ = new OsfV2Body_opt(node($rule$,2));
                     replaceStackNode($rule$,2,$node2$);
                   }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        ($node0$.files = $node2$.files).push(node($rule$,1).svalue());
            break;
            }
          case 0: case 1: case 6: case 11: case 26: case 53: 
            break;
          default:
            $head$ = $head$.copy(node($rule$,1));
            break;
        }
      return $head$;
    }

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

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

      newTerminal(0,"$EMPTY$",1,2);
      newTerminal(1,"$E_O_I$",1,2);
      newTerminal(2,"error",1,2);
      newTerminal(3,"$OsfV2Program_switch$",1,2);
      newTerminal(4,"$SortExpression_switch$",1,2);
      newTerminal(5,"$OsfExpression_switch$",1,2);
      newTerminal(6,"EOS",1,2);
      newTerminal(7,"IDENTIFIER",11,2);
      { // Code for XML serialization annotation:
        // [ nsprefix = "osf" localname = "identifier" attributes = { name = $VALUE } ]
        terminals[7].setXmlInfo(new XmlInfo("identifier","osf"));
        XmlAttributeInfo[] xmlAttributes = new XmlAttributeInfo[1];
        xmlAttributes[0] = new XmlAttributeInfo("name");
        terminals[7].addXmlInfo(xmlAttributes);
      }
      newTerminal(8,"PRAGMA",11,2);
      newTerminal(9,"STRING",11,2);
      newTerminal(10,"TOP",11,2);
      { // Code for XML serialization annotation:
        // [ nsprefix = "osf" localname = "sort" attributes = { name = "TOP" } ]
        terminals[10].setXmlInfo(new XmlInfo("sort","osf"));
        XmlAttributeInfo[] xmlAttributes = new XmlAttributeInfo[1];
        xmlAttributes[0] = XmlAttributeInfo.literalXmlAttributeInfo("name","TOP");
        terminals[10].addXmlInfo(xmlAttributes);
      }
      newTerminal(11,"BOTTOM",11,2);
      { // Code for XML serialization annotation:
        // [ nsprefix = "osf" localname = "sort" attributes = { name = "BOTTOM" } ]
        terminals[11].setXmlInfo(new XmlInfo("sort","osf"));
        XmlAttributeInfo[] xmlAttributes = new XmlAttributeInfo[1];
        xmlAttributes[0] = XmlAttributeInfo.literalXmlAttributeInfo("name","BOTTOM");
        terminals[11].addXmlInfo(xmlAttributes);
      }
      newTerminal(12,"TAG",11,2);
      { // Code for XML serialization annotation:
        // [ nsprefix = "osf" localname = "tag" attributes = { name = $VALUE } ]
        terminals[12].setXmlInfo(new XmlInfo("tag","osf"));
        XmlAttributeInfo[] xmlAttributes = new XmlAttributeInfo[1];
        xmlAttributes[0] = new XmlAttributeInfo("name");
        terminals[12].addXmlInfo(xmlAttributes);
      }
      newTerminal(13,"INTEGER",11,2);
      newTerminal(14,"CHAR",11,2);
      newTerminal(15,"FLOAT",11,2);
      newTerminal(16,"BOOLEAN",11,2);
      newTerminal(17,"ARROW",21,2);
      newTerminal(18,"ISA",31,2);
      newTerminal(19,"BUTNOT",41,1);
      newTerminal(20,"OR",51,0);
      newTerminal(21,"AND",61,0);
      newTerminal(22,"NOT",71,1);
      newTerminal(23,",",1,2);
      newTerminal(24,":",1,2);
      newTerminal(25,"(",1,2);
      newTerminal(26,")",1,2);
      newTerminal(27,"{",1,2);
      newTerminal(28,"}",1,2);
      newTerminal(29,";",1,2);
    }

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

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

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

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

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

      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(1,2,4,1,2);
      rules[5] = new ParserRule(2,1,5,1,2);
      rules[6] = new ParserRule(17,0,6,1,2);
      rules[7] = new ParserRule(17,2,7,1,2);
      rules[8] = new ParserRule(18,2,8,1,2);
      rules[9] = new ParserRule(21,0,9,1,2);
      rules[10] = new ParserRule(20,2,10,1,2);
      rules[11] = new ParserRule(19,0,11,1,2);
      rules[12] = new ParserRule(19,2,12,1,2);
      rules[13] = new ParserRule(19,1,13,1,2);
      rules[14] = new ParserRule(19,1,14,1,2);
      rules[15] = new ParserRule(19,1,15,1,2);
      rules[16] = new ParserRule(23,1,16,1,2);
      rules[17] = new ParserRule(5,3,17,31,2);
      rules[18] = new ParserRule(24,1,18,11,2);
      rules[19] = new ParserRule(6,1,19,1,2);
      rules[20] = new ParserRule(6,3,20,1,2);
      rules[21] = new ParserRule(4,1,21,1,2);
      rules[22] = new ParserRule(9,1,22,11,2);
      { // Code for XML serialization annotation:
        // [ nsprefix = "osf" localname = "term" attributes = { tag = 1/name } ]
        rules[22].setXmlInfo(new XmlInfo("term","osf"));
        XmlAttributeInfo[] xmlAttributes = new XmlAttributeInfo[1];
        xmlAttributes[0] = XmlAttributeInfo.refXmlAttributeInfo("tag","name");
        xmlAttributes[0].setChild(1);
        rules[22].addXmlInfo(xmlAttributes);
      }
      rules[23] = new ParserRule(9,1,23,1,2);
      rules[24] = new ParserRule(9,3,24,1,2);
      { // Code for XML serialization annotation:
        // [ nsprefix = "osf" localname = "term" attributes = { tag = 1/name sort = 3/sort } children = ( 3[0] ) ]
        rules[24].setXmlInfo(new XmlInfo("term","osf"));
        XmlAttributeInfo[] xmlAttributes = new XmlAttributeInfo[2];
        xmlAttributes[0] = XmlAttributeInfo.refXmlAttributeInfo("tag","name");
        xmlAttributes[0].setChild(1);
        xmlAttributes[1] = XmlAttributeInfo.refXmlAttributeInfo("sort","sort");
        xmlAttributes[1].setChild(3);
        rules[24].addXmlInfo(xmlAttributes);
        int[] xmlChildren = {3};
        rules[24].addXmlInfo(xmlChildren);
          {
             int[][] paths = new int[1][];
             int[] path;
             path = new int[1];
             path[0] = 0;
             paths[0] = path;
             rules[24].addXmlInfo(paths);
          }
      }
      rules[25] = new ParserRule(10,2,25,1,2);
      { // Code for XML serialization annotation:
        // [ nsprefix = "osf" localname = "term" attributes = { sort = 1/sort } children = ( 2 ) ]
        rules[25].setXmlInfo(new XmlInfo("term","osf"));
        XmlAttributeInfo[] xmlAttributes = new XmlAttributeInfo[1];
        xmlAttributes[0] = XmlAttributeInfo.refXmlAttributeInfo("sort","sort");
        xmlAttributes[0].setChild(1);
        rules[25].addXmlInfo(xmlAttributes);
        int[] xmlChildren = {2};
        rules[25].addXmlInfo(xmlChildren);
      }
      rules[26] = new ParserRule(11,0,26,1,2);
      rules[27] = new ParserRule(11,3,27,1,2);
      rules[28] = new ParserRule(12,1,28,1,2);
      rules[29] = new ParserRule(12,3,29,1,2);
      rules[30] = new ParserRule(13,1,30,1,2);
      rules[31] = new ParserRule(13,3,31,21,2);
      { // Code for XML serialization annotation:
        // [ nsprefix = "osf" localname = "feature" attributes = { name = 1/name } children = ( 3 ) ]
        rules[31].setXmlInfo(new XmlInfo("feature","osf"));
        XmlAttributeInfo[] xmlAttributes = new XmlAttributeInfo[1];
        xmlAttributes[0] = XmlAttributeInfo.refXmlAttributeInfo("name","name");
        xmlAttributes[0].setChild(1);
        rules[31].addXmlInfo(xmlAttributes);
        int[] xmlChildren = {3};
        rules[31].addXmlInfo(xmlChildren);
      }
      rules[32] = new ParserRule(14,1,32,11,2);
      rules[33] = new ParserRule(14,1,33,11,2);
      rules[34] = new ParserRule(3,1,34,1,2);
      rules[35] = new ParserRule(3,1,35,1,2);
      { // Code for XML serialization annotation:
        // [ nsprefix = "osf" localname = "sort" attributes = { sort = 1/name } ]
        rules[35].setXmlInfo(new XmlInfo("sort","osf"));
        XmlAttributeInfo[] xmlAttributes = new XmlAttributeInfo[1];
        xmlAttributes[0] = XmlAttributeInfo.refXmlAttributeInfo("sort","name");
        xmlAttributes[0].setChild(1);
        rules[35].addXmlInfo(xmlAttributes);
      }
      rules[36] = new ParserRule(3,3,36,1,2);
      rules[37] = new ParserRule(3,2,37,71,1);
      rules[38] = new ParserRule(3,3,38,61,0);
      rules[39] = new ParserRule(3,3,39,51,0);
      rules[40] = new ParserRule(3,3,40,41,1);
      rules[41] = new ParserRule(3,3,41,1,2);
      rules[42] = new ParserRule(7,1,42,11,2);
      rules[43] = new ParserRule(7,1,43,11,2);
      rules[44] = new ParserRule(7,1,44,11,2);
      rules[45] = new ParserRule(7,1,45,11,2);
      rules[46] = new ParserRule(7,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(25,1,49,11,2);
      rules[50] = new ParserRule(8,1,50,1,2);
      rules[51] = new ParserRule(8,3,51,1,2);
      rules[52] = new ParserRule(22,1,52,11,2);
      rules[53] = new ParserRule(15,0,53,1,2);
      rules[54] = new ParserRule(15,1,54,11,2);
      rules[55] = new ParserRule(15,1,55,1,2);
      rules[56] = new ParserRule(16,1,56,11,2);
      rules[57] = new ParserRule(16,2,57,11,2);
    }

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

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

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

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

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

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

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

  static void initializeActionTables ()
    {
      newActionTables(70);

      newActionTable(0,19);
	setAction(0,1,5);
	setAction(0,2,6);
	setAction(0,3,2);
	setAction(0,4,3);
	setAction(0,5,4);
	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,16,17);
	setAction(0,22,18);
	setAction(0,25,19);
	setAction(0,27,20);

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

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

      newActionTable(3,16);
	setAction(3,1,22);
	setAction(3,2,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,16,34);
	setAction(3,22,35);
	setAction(3,25,36);
	setAction(3,27,37);

      newActionTable(4,11);
	setAction(4,16,45);
	setAction(4,7,48);
	setAction(4,22,39);
	setAction(4,25,40);
	setAction(4,9,44);
	setAction(4,10,46);
	setAction(4,27,38);
	setAction(4,11,47);
	setAction(4,13,41);
	setAction(4,14,42);
	setAction(4,15,43);

      newActionTable(5,12);
	setAction(5,16,56);
	setAction(5,7,60);
	setAction(5,22,50);
	setAction(5,25,51);
	setAction(5,9,55);
	setAction(5,10,58);
	setAction(5,27,49);
	setAction(5,11,59);
	setAction(5,12,57);
	setAction(5,13,52);
	setAction(5,14,53);
	setAction(5,15,54);

      newActionTable(6,16);
	setAction(6,1,61);
	setAction(6,2,72);
	setAction(6,6,62);
	setAction(6,7,74);
	setAction(6,8,73);
	setAction(6,9,69);
	setAction(6,10,75);
	setAction(6,11,76);
	setAction(6,12,71);
	setAction(6,13,66);
	setAction(6,14,67);
	setAction(6,15,68);
	setAction(6,16,70);
	setAction(6,22,64);
	setAction(6,25,65);
	setAction(6,27,63);

      newActionTable(7,16);
	setAction(7,1,77);
	setAction(7,2,78);
	setAction(7,6,79);
	setAction(7,7,80);
	setAction(7,8,81);
	setAction(7,9,82);
	setAction(7,10,83);
	setAction(7,11,84);
	setAction(7,12,85);
	setAction(7,13,86);
	setAction(7,14,87);
	setAction(7,15,88);
	setAction(7,16,89);
	setAction(7,22,90);
	setAction(7,25,91);
	setAction(7,27,92);

      newActionTable(8,8);
	setAction(8,1,93);
	setAction(8,19,95);
	setAction(8,21,97);
	setAction(8,20,96);
	setAction(8,23,98);
	setAction(8,6,94);
	setAction(8,25,99);
	setAction(8,26,100);

      newActionTable(9,8);
	setAction(9,1,101);
	setAction(9,19,103);
	setAction(9,21,105);
	setAction(9,20,104);
	setAction(9,23,106);
	setAction(9,6,102);
	setAction(9,25,107);
	setAction(9,26,108);

      newActionTable(10,3);
	setAction(10,7,111);
	setAction(10,10,109);
	setAction(10,11,110);

      newActionTable(11,8);
	setAction(11,1,126);
	setAction(11,19,125);
	setAction(11,21,123);
	setAction(11,20,124);
	setAction(11,23,128);
	setAction(11,6,127);
	setAction(11,25,130);
	setAction(11,26,129);

      newActionTable(12,2);
	setAction(12,1,142);
	setAction(12,6,143);

      newActionTable(13,1);
	setAction(13,18,144);

      newActionTable(14,3);
	setAction(14,18,146);
	setAction(14,23,147);
	setAction(14,6,145);

      newActionTable(15,8);
	setAction(15,1,148);
	setAction(15,19,150);
	setAction(15,21,152);
	setAction(15,20,151);
	setAction(15,23,153);
	setAction(15,6,149);
	setAction(15,25,154);
	setAction(15,26,155);

      newActionTable(16,8);
	setAction(16,1,156);
	setAction(16,19,158);
	setAction(16,21,160);
	setAction(16,20,159);
	setAction(16,23,161);
	setAction(16,6,157);
	setAction(16,25,162);
	setAction(16,26,163);

      newActionTable(17,8);
	setAction(17,1,164);
	setAction(17,19,166);
	setAction(17,21,168);
	setAction(17,20,167);
	setAction(17,23,169);
	setAction(17,6,165);
	setAction(17,25,170);
	setAction(17,26,171);

      newActionTable(18,8);
	setAction(18,1,172);
	setAction(18,19,174);
	setAction(18,21,176);
	setAction(18,20,175);
	setAction(18,23,177);
	setAction(18,6,173);
	setAction(18,25,178);
	setAction(18,26,179);

      newActionTable(19,8);
	setAction(19,1,180);
	setAction(19,19,182);
	setAction(19,21,184);
	setAction(19,20,183);
	setAction(19,23,185);
	setAction(19,6,181);
	setAction(19,25,186);
	setAction(19,26,187);

      newActionTable(20,5);
	setAction(20,1,188);
	setAction(20,23,190);
	setAction(20,6,189);
	setAction(20,24,192);
	setAction(20,26,191);

      newActionTable(21,4);
	setAction(21,1,193);
	setAction(21,23,195);
	setAction(21,6,194);
	setAction(21,26,196);

      newActionTable(22,1);
	setAction(22,6,197);

      newActionTable(23,3);
	setAction(23,6,198);
	setAction(23,9,200);
	setAction(23,13,199);

      newActionTable(24,1);
	setAction(24,6,201);

      newActionTable(25,1);
	setAction(25,6,202);

      newActionTable(26,1);
	setAction(26,6,203);

      newActionTable(27,3);
	setAction(27,6,204);
	setAction(27,9,205);
	setAction(27,13,206);

      newActionTable(28,1);
	setAction(28,6,207);

      newActionTable(29,7);
	setAction(29,19,211);
	setAction(29,18,208);
	setAction(29,21,213);
	setAction(29,20,212);
	setAction(29,6,210);
	setAction(29,23,209);
	setAction(29,25,214);

      newActionTable(30,10);
	setAction(30,1,215);
	setAction(30,19,217);
	setAction(30,21,219);
	setAction(30,20,218);
	setAction(30,23,220);
	setAction(30,6,216);
	setAction(30,25,221);
	setAction(30,26,222);
	setAction(30,29,224);
	setAction(30,28,223);

      newActionTable(31,10);
	setAction(31,1,225);
	setAction(31,19,227);
	setAction(31,21,229);
	setAction(31,20,228);
	setAction(31,23,230);
	setAction(31,6,226);
	setAction(31,25,231);
	setAction(31,26,232);
	setAction(31,29,234);
	setAction(31,28,233);

      newActionTable(32,1);
	setAction(32,6,235);

      newActionTable(33,1);
	setAction(33,6,236);

      newActionTable(34,1);
	setAction(34,6,237);

      newActionTable(35,2);
	setAction(35,6,238);
	setAction(35,9,239);

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

      newActionTable(37,16);
	setAction(37,1,241);
	setAction(37,2,242);
	setAction(37,6,243);
	setAction(37,7,244);
	setAction(37,8,245);
	setAction(37,9,246);
	setAction(37,10,247);
	setAction(37,11,248);
	setAction(37,12,249);
	setAction(37,13,250);
	setAction(37,14,251);
	setAction(37,15,252);
	setAction(37,16,253);
	setAction(37,22,254);
	setAction(37,25,255);
	setAction(37,27,256);

      newActionTable(38,1);
	setAction(38,6,257);

      newActionTable(39,16);
	setAction(39,1,258);
	setAction(39,2,259);
	setAction(39,6,260);
	setAction(39,7,261);
	setAction(39,8,262);
	setAction(39,9,263);
	setAction(39,10,264);
	setAction(39,11,265);
	setAction(39,12,266);
	setAction(39,13,267);
	setAction(39,14,268);
	setAction(39,15,269);
	setAction(39,16,270);
	setAction(39,22,271);
	setAction(39,25,272);
	setAction(39,27,273);

      newActionTable(40,4);
	setAction(40,1,285);
	setAction(40,23,287);
	setAction(40,6,286);
	setAction(40,26,288);

      newActionTable(41,10);
	setAction(41,1,289);
	setAction(41,19,291);
	setAction(41,21,293);
	setAction(41,20,292);
	setAction(41,23,294);
	setAction(41,6,290);
	setAction(41,25,295);
	setAction(41,26,296);
	setAction(41,29,298);
	setAction(41,28,297);

      newActionTable(42,1);
	setAction(42,7,299);

      newActionTable(43,2);
	setAction(43,18,301);
	setAction(43,6,300);

      newActionTable(44,3);
	setAction(44,18,303);
	setAction(44,23,304);
	setAction(44,6,302);

      newActionTable(45,1);
	setAction(45,6,306);

      newActionTable(46,4);
	setAction(46,19,309);
	setAction(46,21,307);
	setAction(46,20,308);
	setAction(46,26,310);

      newActionTable(47,8);
	setAction(47,1,344);
	setAction(47,19,346);
	setAction(47,21,348);
	setAction(47,20,347);
	setAction(47,23,349);
	setAction(47,6,345);
	setAction(47,25,350);
	setAction(47,26,351);

      newActionTable(48,8);
	setAction(48,1,355);
	setAction(48,19,354);
	setAction(48,21,352);
	setAction(48,20,353);
	setAction(48,23,357);
	setAction(48,6,356);
	setAction(48,25,358);
	setAction(48,26,359);

      newActionTable(49,8);
	setAction(49,1,362);
	setAction(49,19,364);
	setAction(49,21,360);
	setAction(49,20,365);
	setAction(49,23,366);
	setAction(49,6,363);
	setAction(49,25,367);
	setAction(49,26,368);

      newActionTable(50,8);
	setAction(50,1,370);
	setAction(50,19,372);
	setAction(50,21,374);
	setAction(50,20,373);
	setAction(50,23,375);
	setAction(50,6,371);
	setAction(50,25,376);
	setAction(50,26,377);

      newActionTable(51,4);
	setAction(51,1,378);
	setAction(51,23,380);
	setAction(51,6,379);
	setAction(51,26,381);

      newActionTable(52,12);
	setAction(52,16,389);
	setAction(52,7,391);
	setAction(52,22,383);
	setAction(52,25,384);
	setAction(52,9,388);
	setAction(52,10,392);
	setAction(52,27,382);
	setAction(52,11,393);
	setAction(52,12,390);
	setAction(52,13,385);
	setAction(52,14,386);
	setAction(52,15,387);

      newActionTable(53,1);
	setAction(53,26,394);

      newActionTable(54,7);
	setAction(54,17,395);
	setAction(54,19,396);
	setAction(54,21,398);
	setAction(54,20,397);
	setAction(54,23,399);
	setAction(54,25,400);
	setAction(54,26,401);

      newActionTable(55,2);
	setAction(55,23,403);
	setAction(55,26,402);

      newActionTable(56,2);
	setAction(56,23,404);
	setAction(56,26,405);

      newActionTable(57,1);
	setAction(57,17,406);

      newActionTable(58,7);
	setAction(58,17,407);
	setAction(58,19,408);
	setAction(58,21,410);
	setAction(58,20,409);
	setAction(58,23,411);
	setAction(58,25,412);
	setAction(58,26,413);

      newActionTable(59,2);
	setAction(59,23,426);
	setAction(59,26,427);

      newActionTable(60,1);
	setAction(60,26,440);

      newActionTable(61,4);
	setAction(61,1,441);
	setAction(61,23,443);
	setAction(61,6,442);
	setAction(61,26,444);

      newActionTable(62,8);
	setAction(62,1,445);
	setAction(62,19,447);
	setAction(62,21,449);
	setAction(62,20,448);
	setAction(62,23,450);
	setAction(62,6,446);
	setAction(62,25,451);
	setAction(62,26,452);

      newActionTable(63,1);
	setAction(63,28,453);

      newActionTable(64,2);
	setAction(64,29,455);
	setAction(64,28,454);

      newActionTable(65,1);
	setAction(65,28,459);

      newActionTable(66,8);
	setAction(66,1,460);
	setAction(66,19,462);
	setAction(66,21,464);
	setAction(66,20,463);
	setAction(66,23,465);
	setAction(66,6,461);
	setAction(66,25,466);
	setAction(66,26,467);

      newActionTable(67,1);
	setAction(67,1,468);

      newActionTable(68,4);
	setAction(68,1,469);
	setAction(68,19,472);
	setAction(68,21,470);
	setAction(68,20,471);

      newActionTable(69,1);
	setAction(69,1,473);

    }

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

  static void initializeGotoTables ()
    {
      newGotoTables(23);

      newGotoTable(0,3);
	setGoto(0,17,6);
	setGoto(0,1,1);
	setGoto(0,2,2);

      newGotoTable(1,0);

      newGotoTable(2,2);
	setGoto(2,17,6);
	setGoto(2,2,79);

      newGotoTable(3,3);
	setGoto(3,3,78);
	setGoto(3,7,8);
	setGoto(3,25,9);

      newGotoTable(4,6);
	setGoto(4,3,12);
	setGoto(4,4,77);
	setGoto(4,7,8);
	setGoto(4,25,9);
	setGoto(4,9,14);
	setGoto(4,10,23);

      newGotoTable(5,13);
	setGoto(5,19,24);
	setGoto(5,3,12);
	setGoto(5,18,7);
	setGoto(5,4,27);
	setGoto(5,5,30);
	setGoto(5,23,26);
	setGoto(5,6,15);
	setGoto(5,22,25);
	setGoto(5,7,8);
	setGoto(5,25,9);
	setGoto(5,24,16);
	setGoto(5,9,14);
	setGoto(5,10,23);

      newGotoTable(6,2);
	setGoto(6,25,73);
	setGoto(6,8,72);

      newGotoTable(7,3);
	setGoto(7,3,71);
	setGoto(7,7,8);
	setGoto(7,25,9);

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

      newGotoTable(9,3);
	setGoto(9,3,50);
	setGoto(9,7,8);
	setGoto(9,25,9);

      newGotoTable(10,2);
	setGoto(10,21,40);
	setGoto(10,20,39);

      newGotoTable(11,2);
	setGoto(11,16,36);
	setGoto(11,15,34);

      newGotoTable(12,1);
	setGoto(12,16,38);

      newGotoTable(13,4);
	setGoto(13,3,12);
	setGoto(13,7,8);
	setGoto(13,25,9);
	setGoto(13,10,43);

      newGotoTable(14,2);
	setGoto(14,6,46);
	setGoto(14,24,16);

      newGotoTable(15,2);
	setGoto(15,6,49);
	setGoto(15,24,16);

      newGotoTable(16,3);
	setGoto(16,3,57);
	setGoto(16,7,8);
	setGoto(16,25,9);

      newGotoTable(17,3);
	setGoto(17,3,56);
	setGoto(17,7,8);
	setGoto(17,25,9);

      newGotoTable(18,3);
	setGoto(18,3,55);
	setGoto(18,7,8);
	setGoto(18,25,9);

      newGotoTable(19,8);
	setGoto(19,3,12);
	setGoto(19,7,8);
	setGoto(19,25,9);
	setGoto(19,9,63);
	setGoto(19,10,23);
	setGoto(19,12,60);
	setGoto(19,13,62);
	setGoto(19,14,64);

      newGotoTable(20,5);
	setGoto(20,3,12);
	setGoto(20,7,8);
	setGoto(20,25,9);
	setGoto(20,9,67);
	setGoto(20,10,23);

      newGotoTable(21,8);
	setGoto(21,3,12);
	setGoto(21,7,8);
	setGoto(21,25,9);
	setGoto(21,9,63);
	setGoto(21,10,23);
	setGoto(21,12,69);
	setGoto(21,13,62);
	setGoto(21,14,64);

      newGotoTable(22,2);
	setGoto(22,25,73);
	setGoto(22,8,75);

    }

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

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

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

  Stack lhs;
  Stack rhs;
}

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

  Stack symbols;
}

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

  Stack sortList;
}

class OsfV2PsiTerm extends OsfV2UntaggedPsiTerm 
{
  OsfV2PsiTerm (ParseNode node)
    {
      super(node);
    }

  String tag;
}

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

  Stack keys;
  Stack subterms;
}

class OsfV2UntaggedPsiTerm extends OsfV2Body_opt 
{
  OsfV2UntaggedPsiTerm (ParseNode node)
    {
      super(node);
    }

  SortExpression sort;
}

class OsfV2SubTerms extends OsfV2Body_opt 
{
  OsfV2SubTerms (ParseNode node)
    {
      super(node);
    }

  
}

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

  Object key;
  Object psiterm;
}

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

  Object feature;
}

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

  Stack args;
}

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

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

