context: // Generated by TinyPG v1.3 available at www.codeproject.com
  
  using System;
  using System.Collections.Generic;
  using System.Text;
  using System.Xml.Serialization;
  
  namespace kOS.Compilation.KS
  {
      #region ParseTree
      [Serializable]
      public class ParseErrors : List<ParseError>
      {
      }
  
      [Serializable]
      public class ParseError
      {
          private string file;
          private string message;
          private int code;
          private int line;
          private int col;
          private int pos;
          private int length;
  
          public string File { get { return file; } }
          public int Code { get { return code; } }
          public int Line { get { return line; } }
          public int Column { get { return col; } }
          public int Position { get { return pos; } }
          public int Length { get { return length; } }
          public string Message { get { return message; } }
  
          // just for the sake of serialization
          public ParseError()
          {
          }
  
          public ParseError(string message, int code, ParseNode node) : this(message, code, node.Token)
          {
          }
  
          public ParseError(string message, int code, Token token) : this(message, code, token.File, token.Line, token.Column, token.StartPos, token.Length)
          {
          }
  
          public ParseError(string message, int code) : this(message, code, string.Empty, 0, 0, 0, 0)
          {
          }
  
          public ParseError(string message, int code, string file, int line, int col, int pos, int length)
          {
              this.file = file;
              this.message = message;
              this.code = code;
              this.line = line;
              this.col = col;
              this.pos = pos;
              this.length = length;
          }
      }
  
      // rootlevel of the node tree
      [Serializable]
      public partial class ParseTree : ParseNode
      {
          public ParseErrors Errors;
  
          public List<Token> Skipped;
  
          public ParseTree() : base(new Token(), "ParseTree")
          {
              Token.Type = TokenType.Start;
              Token.Text = "Root";
              Errors = new ParseErrors();
          }
  
          public string PrintTree()
          {
              StringBuilder sb = new StringBuilder();
              int indent = 0;
              PrintNode(sb, this, indent);
              return sb.ToString();
          }
  
          private void PrintNode(StringBuilder sb, ParseNode node, int indent)
          {
              
              string space = "".PadLeft(indent, ' ');
  
              sb.Append(space);
              sb.AppendLine(node.Text);
  
              foreach (ParseNode n in node.Nodes)
                  PrintNode(sb, n, indent + 2);
          }
          
          /// <summary>
          /// this is the entry point for executing and evaluating the parse tree.
          /// </summary>
          /// <param name="paramlist">additional optional input parameters</param>
          /// <returns>the output of the evaluation function</returns>
          public object Eval(params object[] paramlist)
          {
              return Nodes[0].Eval(this, paramlist);
          }
      }
  
      [Serializable]
      [XmlInclude(typeof(ParseTree))]
      public partial class ParseNode
      {
          protected string text;
          protected List<ParseNode> nodes;
          
          public List<ParseNode> Nodes { get {return nodes;} }
          
          [XmlIgnore] // avoid circular references when serializing
          public ParseNode Parent;
          public Token Token; // the token/rule
  
          [XmlIgnore] // skip redundant text (is part of Token)
          public string Text { // text to display in parse tree 
              get { return text;} 
              set { text = value; }
          } 
  
          public virtual ParseNode CreateNode(Token token, string text)
          {
              ParseNode node = new ParseNode(token, text);
              node.Parent = this;
              return node;
          }
  
          protected ParseNode(Token token, string text)
          {
              this.Token = token;
              this.text = text;
              this.nodes = new List<ParseNode>();
          }
  
          protected object GetValue(ParseTree tree, TokenType type, int index)
          {
              return GetValue(tree, type, ref index);
          }
  
          protected object GetValue(ParseTree tree, TokenType type, ref int index)
          {
              object o = null;
              if (index < 0) return o;
  
              // left to right
              foreach (ParseNode node in nodes)
              {
                  if (node.Token.Type == type)
                  {
                      index--;
                      if (index < 0)
                      {
                          o = node.Eval(tree);
                          break;
                      }
                  }
              }
              return o;
          }
  
          /// <summary>
          /// this implements the evaluation functionality, cannot be used directly
          /// </summary>
          /// <param name="tree">the parsetree itself</param>
          /// <param name="paramlist">optional input parameters</param>
          /// <returns>a partial result of the evaluation</returns>
          internal object Eval(ParseTree tree, params object[] paramlist)
          {
              object Value = null;
  
              switch (Token.Type)
              {
                  case TokenType.Start:
                      Value = EvalStart(tree, paramlist);
                      break;
                  case TokenType.instruction_block:
                      Value = Evalinstruction_block(tree, paramlist);
                      break;
                  case TokenType.instruction:
                      Value = Evalinstruction(tree, paramlist);
                      break;
                  case TokenType.set_stmt:
                      Value = Evalset_stmt(tree, paramlist);
                      break;
                  case TokenType.if_stmt:
                      Value = Evalif_stmt(tree, paramlist);
                      break;
                  case TokenType.until_stmt:
                      Value = Evaluntil_stmt(tree, paramlist);
                      break;
                  case TokenType.lock_stmt:
                      Value = Evallock_stmt(tree, paramlist);
                      break;
                  case TokenType.unlock_stmt:
                      Value = Evalunlock_stmt(tree, paramlist);
                      break;
                  case TokenType.print_stmt:
                      Value = Evalprint_stmt(tree, paramlist);
                      break;
                  case TokenType.on_stmt:
                      Value = Evalon_stmt(tree, paramlist);
                      break;
                  case TokenType.toggle_stmt:
                      Value = Evaltoggle_stmt(tree, paramlist);
                      break;
                  case TokenType.wait_stmt:
                      Value = Evalwait_stmt(tree, paramlist);
                      break;
                  case TokenType.when_stmt:
                      Value = Evalwhen_stmt(tree, paramlist);
                      break;
                  case TokenType.onoff_stmt:
                      Value = Evalonoff_stmt(tree, paramlist);
                      break;
                  case TokenType.stage_stmt:
                      Value = Evalstage_stmt(tree, paramlist);
                      break;
                  case TokenType.clear_stmt:
                      Value = Evalclear_stmt(tree, paramlist);
                      break;
                  case TokenType.add_stmt:
                      Value = Evaladd_stmt(tree, paramlist);
                      break;
                  case TokenType.remove_stmt:
                      Value = Evalremove_stmt(tree, paramlist);
                      break;
                  case TokenType.log_stmt:
                      Value = Evallog_stmt(tree, paramlist);
                      break;
                  case TokenType.break_stmt:
                      Value = Evalbreak_stmt(tree, paramlist);
                      break;
                  case TokenType.preserve_stmt:
                      Value = Evalpreserve_stmt(tree, paramlist);
                      break;
                  case TokenType.declare_stmt:
                      Value = Evaldeclare_stmt(tree, paramlist);
                      break;
                  case TokenType.switch_stmt:
                      Value = Evalswitch_stmt(tree, paramlist);
                      break;
                  case TokenType.copy_stmt:
                      Value = Evalcopy_stmt(tree, paramlist);
                      break;
                  case TokenType.rename_stmt:
                      Value = Evalrename_stmt(tree, paramlist);
                      break;
                  case TokenType.delete_stmt:
                      Value = Evaldelete_stmt(tree, paramlist);
                      break;
                  case TokenType.edit_stmt:
                      Value = Evaledit_stmt(tree, paramlist);
                      break;
                  case TokenType.run_stmt:
                      Value = Evalrun_stmt(tree, paramlist);
                      break;
                  case TokenType.filevol_name:
                      Value = Evalfilevol_name(tree, paramlist);
                      break;
                  case TokenType.list_stmt:
                      Value = Evallist_stmt(tree, paramlist);
                      break;
                  case TokenType.reboot_stmt:
                      Value = Evalreboot_stmt(tree, paramlist);
                      break;
                  case TokenType.shutdown_stmt:
                      Value = Evalshutdown_stmt(tree, paramlist);
                      break;
                  case TokenType.for_stmt:
                      Value = Evalfor_stmt(tree, paramlist);
                      break;
                  case TokenType.unset_stmt:
                      Value = Evalunset_stmt(tree, paramlist);
                      break;
                  case TokenType.batch_stmt:
  
gt:                     Value = Evalbatch_stmt(tree, paramlist);