Parser.cs :  » Profilers » Prof-It » at » jku » ssw » ProfIt » Coco » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Profilers » Prof It 
Prof It » at » jku » ssw » ProfIt » Coco » Parser.cs
using System.Collections;
using System.Text;
using System.Reflection;

using System;
using at.jku.ssw.ProfIt.Components;

namespace at.jku.ssw.ProfIt.Coco{



public class Parser {
  const int _EOF = 0;
  const int _ident = 1;
  const int _intCon = 2;
  const int _realCon = 3;
  const int _charCon = 4;
  const int _stringCon = 5;
  const int _base = 6;
  const int _bool = 7;
  const int _byte = 8;
  const int _char = 9;
  const int _checked = 10;
  const int _decimal = 11;
  const int _double = 12;
  const int _event = 13;
  const int _false = 14;
  const int _float = 15;
  const int _int = 16;
  const int _long = 17;
  const int _new = 18;
  const int _null = 19;
  const int _object = 20;
  const int _return = 21;
  const int _sbyte = 22;
  const int _short = 23;
  const int _sizeof = 24;
  const int _string = 25;
  const int _this = 26;
  const int _true = 27;
  const int _typeof = 28;
  const int _uint = 29;
  const int _ulong = 30;
  const int _unchecked = 31;
  const int _ushort = 32;
  const int _void = 33;
  const int _and = 34;
  const int _assgn = 35;
  const int _colon = 36;
  const int _comma = 37;
  const int _dec = 38;
  const int _dot = 39;
  const int _inc = 40;
  const int _lbrace = 41;
  const int _lbrack = 42;
  const int _lpar = 43;
  const int _minus = 44;
  const int _not = 45;
  const int _plus = 46;
  const int _rbrace = 47;
  const int _rbrack = 48;
  const int _rpar = 49;
  const int _scolon = 50;
  const int _tilde = 51;
  const int _times = 52;
  const int maxT = 128;

    static CounterCollection counters;
    // initialize curBlock to avoid 'not-null-checks' in create-methods
    static IBlock curBlock;
    static ClassCounter curClass;
    static MethodCounter curMethod;
    static int numberOfInserts = 0;

  const bool T = true;
  const bool x = false;
  const int minErrDist = 2;

  public static Token t;    // last recognized token
  public static Token la;   // lookahead token
  static int errDist = minErrDist;

static ArrayList typeNames = null;             // names of declared or imported types
static ArrayList nsNames = new ArrayList();    // names of imported namespaces
static Hashtable aliasNames = new Hashtable(); // alias names of using directives
static string curNamespace = "";               // current namespace
static string assemblyName = null;

public static string ContainingAssembly {      // assembly name of compiled source file
  set { assemblyName = value; }                // must be set by the main program
}

enum TypeKind {simple, array, pointer}

/*------------------------- modifier handling -----------------------------*/

[Flags]
enum Modifier {
  /* available modifiers (reserve one bit per modifier) */
  @new     = 0x0001, @public = 0x0002, @protected= 0x0004, @internal = 0x0008, 
  @private = 0x0010, @unsafe = 0x0020, @static   = 0x0040, @readonly = 0x0080,
  @volatile= 0x0100, @virtual= 0x0200, @sealed   = 0x0400, @override = 0x0800,
  @abstract= 0x1000, @extern = 0x2000,

  /* sets of modifiers that can be attached to certain program elements    *
   * e.g., "constants" marks all modifiers that may be used with constants */
  none          = 0x0000,
  constants     = @new|@public|@protected|@internal|@private,                                     //0x001f
  nonClassTypes = @new|@public|@protected|@internal|@private|@unsafe|@static,                     //0x007f
  fields        = @new|@public|@protected|@internal|@private|@unsafe|@static|@readonly|@volatile, //0x01ff
  classes       = @new|@public|@protected|@internal|@private|@unsafe|@sealed|@abstract,           //0x143f
  destructors   = @unsafe|@extern,                                                                //0x2020
  constructors  = @public|@protected|@internal|@private|@unsafe|@extern,                          //0x203e
  operators     = @public|@unsafe|@static|@extern,                                                //0x2062
  indexers      = @new|@public|@protected|@internal|@private|@unsafe|@virtual|@sealed|@override|@abstract|@extern,         //0x3e3f
  propEvntMeths = @new|@public|@protected|@internal|@private|@unsafe|@static|@virtual|@sealed|@override|@abstract|@extern, //0x3e7f
  all           = 0x3fff
}

class Modifiers {
  private Modifier cur = Modifier.none;
  
  public void Add (Modifier m) {
    if ((cur & m) == 0) cur |= m;
    else Error("modifier " + m + " already defined");
  }
  
  public void Add (Modifiers m) { Add(m.cur); }

  public bool IsNone { get { return cur == Modifier.none; } }

  public void Check (Modifier allowed) {
    Modifier wrong = cur & (allowed ^ Modifier.all);
    if (wrong != Modifier.none)
      Error("modifier(s) " + wrong + " not allowed here");
  }
}

/*----------------------------- token sets -------------------------------*/

const int maxTerminals = 160;  // set size

static BitArray NewSet(params int[] values) {
  BitArray a = new BitArray(maxTerminals);
  foreach (int x in values) a[x] = true;
  return a;
}

static BitArray
  unaryOp      = NewSet(_plus, _minus, _not, _tilde, _inc, _dec, _true, _false),
  typeKW       = NewSet(_char, _bool, _object, _string, _sbyte, _byte, _short,
                 _ushort, _int, _uint, _long, _ulong, _float, _double, _decimal),
  unaryHead    = NewSet(_plus, _minus, _not, _tilde, _times, _inc, _dec, _and),
  assnStartOp  = NewSet(_plus, _minus, _not, _tilde, _times),
  castFollower = NewSet(_ident, _intCon, _realCon, _charCon, _stringCon, _lpar, 
                 _new, _this, _base, _null, _checked, _unchecked, _typeof, _sizeof).Or(unaryOp);

/*---------------------------- auxiliary methods ------------------------*/

static void Error (string s) {
  if (errDist >= minErrDist) Errors.Error(la.line, la.col, s);
  errDist = 0;
}

static bool IsTypeCast () {
  if (la.kind != _lpar) return false;
  if (IsSimpleTypeCast()) return true;
  if (assemblyName != null) return CheckTypeCast();
  return GuessTypeCast();
}

// "(" type ("[" {","} "]" | "*") ")"
static bool IsSimpleTypeCast () {
  // assert: la.kind == _lpar
  Scanner.ResetPeek();
  Token pt1 = Scanner.Peek();
  Token pt = Scanner.Peek();
  return (typeKW[pt1.kind] || pt1.kind == _void) && IsPointerOrDims(ref pt) && pt.kind == _rpar;
}

// "(" Qualident ("[" {","} "]" | "*") ")"
static bool CheckTypeCast () {
  // assert: la.kind == _lpar
  string id;
  Scanner.ResetPeek();
  Token pt = Scanner.Peek();
  return IsQualident(ref pt, out id) && IsPointerOrDims(ref pt) && 
         pt.kind == _rpar && IsType(id);
}

// "(" Qualident ("[" {","} "]" | "*") ")" castFollower
static bool GuessTypeCast () {
  // assert: la.kind == _lpar
  string id;
  Scanner.ResetPeek();
  Token pt = Scanner.Peek();
  if (IsQualident(ref pt, out id) && IsPointerOrDims(ref pt) && pt.kind == _rpar) {
    pt = Scanner.Peek(); // check successor
    return castFollower[pt.kind] || (typeKW[pt.kind] && Scanner.Peek().kind == _dot);
  } else return false;
}

static bool IsType (string qualident) {
  if (typeNames == null) FillTypeNames();
  if (typeNames.BinarySearch(qualident) >= 0) return true;                     // fully qualified type
  if (typeNames.BinarySearch(curNamespace + "." + qualident) >= 0) return true;// local type
  foreach (string ns in nsNames)                                               // imported type
    if (typeNames.BinarySearch(ns + "." + qualident) >= 0) return true;
  foreach (string alias in aliasNames.Keys)                                    // alias type
    if (qualident.StartsWith(alias)) {
      string s = aliasNames[alias] + qualident.Substring(alias.Length);
      if (typeNames.BinarySearch(s) >= 0) return true;
    }
  return false;
}

static void FillTypeNames () {
  if (assemblyName != null && assemblyName.Length > 0) {
    typeNames = new ArrayList();
    Assembly a = Assembly.LoadFrom(assemblyName);
    foreach (Type t in a.GetTypes()) typeNames.Add(t.FullName);
    foreach (AssemblyName refAssembly in a.GetReferencedAssemblies()) {
      a = Assembly.Load(refAssembly);
      foreach(Type t in a.GetExportedTypes())
        if (nsNames.Contains(t.FullName.Substring(0, t.FullName.LastIndexOf('.'))))
          typeNames.Add(t.FullName);
    }
    typeNames.Sort();
  }
}

/* Checks whether the next sequence of tokens is a qualident *
 * and returns the qualident string                          *
 * !!! Proceeds from current peek position !!!               */
static bool IsQualident (ref Token pt, out string qualident) {
  qualident = "";
  if (pt.kind == _ident) {
    qualident = pt.val;
    pt = Scanner.Peek();
    while (pt.kind == _dot) {
      pt = Scanner.Peek();
      if (pt.kind != _ident) return false;
      qualident += "." + pt.val;
      pt = Scanner.Peek();
    }
    return true;
  } else return false;
}

// Return the n-th token after the current lookahead token
static Token Peek (int n) {
  Scanner.ResetPeek();
  Token x = la;
  while (n > 0) { x = Scanner.Peek(); n--; }
  return x;
}

/*-----------------------------------------------------------------*
 * Resolver routines to resolve LL(1) conflicts:                   *                                                  *
 * These routines return a boolean value that indicates            *
 * whether the alternative at hand shall be choosen or not.        *
 * They are used in IF ( ... ) expressions.                        *       
 *-----------------------------------------------------------------*/

// ident "="
static bool IsAssignment () {
  return la.kind == _ident && Peek(1).kind == _assgn;
}

// ident ("," | "=" | ";")
static bool IsFieldDecl () {
  int peek = Peek(1).kind;
  return la.kind == _ident && 
         (peek == _comma || peek == _assgn || peek == _scolon);
}

/* True, if the comma is not a trailing one, *
 * like the last one in: a, b, c,            */
static bool NotFinalComma () {
  int peek = Peek(1).kind;
  return la.kind == _comma && peek != _rbrace && peek != _rbrack;
}

// "void" "*"
static bool NotVoidPointer () {
  return la.kind == _void && Peek(1).kind != _times;
}

// ("checked" | "unchecked") "{"
static bool UnCheckedAndLBrace () {
  return la.kind == _checked || la.kind == _unchecked &&
         Peek(1).kind == _lbrace;
}

// "." ident
static bool DotAndIdent () {
  return la.kind == _dot && Peek(1).kind == _ident;
}

// ident ":"
static bool IsLabel () {
  return la.kind == _ident && Peek(1).kind == _colon;
}

// ident "("
static bool IdentAndLPar () {
  return la.kind == _ident && Peek(1).kind == _lpar;
}

// "[" "assembly" or "[" "module"
static bool IsGlobalAttrTarget () {
  Token pt = Peek(1);
  return la.kind == _lbrack && pt.kind == _ident && (pt.val == "assembly" || pt.val == "module");
}

// "[" ("," | "]")
static bool IsDims () {
  int peek = Peek(1).kind;
  return la.kind == _lbrack && (peek == _comma || peek == _rbrack);
}

// "*" | "[" ("," | "]")
static bool IsPointerOrDims () {
  return la.kind == _times || IsDims();
}

/* skip: { "[" { "," } "]" | "*" }             */
/* !!! Proceeds from current peek position !!! */
static bool IsPointerOrDims (ref Token pt) {
  for (;;) {
    if (pt.kind == _lbrack) {
      do pt = Scanner.Peek();
      while (pt.kind == _comma);
      if (pt.kind != _rbrack) return false;
    } else if (pt.kind != _times) break;
    pt = Scanner.Peek();
  }
  return true;
}

// Type ident (Type can be void*)
static bool IsLocalVarDecl () {
  if (typeKW[la.kind] || la.kind == _void) return true;
  Scanner.ResetPeek();
  Token pt = la;
  string ignore;
  return IsQualident(ref pt, out ignore) && IsPointerOrDims(ref pt) && pt.kind == _ident;
}

/* True, if lookahead is a local attribute target specifier, *
 * i.e. one of "event", "return", "field", "method",         *
 *             "module", "param", "property", or "type"      */
static bool IsLocalAttrTarget () {
  int cur = la.kind;
  string val = la.val;
  return cur == _event || cur == _return ||
         (Peek(1).kind == _colon &&
           (val == "field" || val == "method"   || val == "module" ||
            val == "param" || val == "property" || val == "type"));
}

  #region Profiler methods

  // Creates a new block and adds it to the counters
  // if useStatementBlock is true, a StatementBlock is created, otherwise a CalcBlock
  static IBlock CreateBlock(bool useStatementBlock, IBlock dependentBlock) {
    if (useStatementBlock) {
      curBlock = new StatementBlock(new Position(la.pos, la.line, numberOfInserts));
    } else {
      curBlock = new CalcBlock(new Position(la.pos, la.line, numberOfInserts), dependentBlock);
    }
    Add(curBlock);
    return curBlock;
  }

  static IBlock CreateBlock() { return CreateBlock(true, null); }
  static IBlock CreateBlock(IBlock block) { return CreateBlock(false, block); }
  
  static void Add(IBlock block) {
    counters.AddBlock(block);
    curMethod.AddBlock(block);
  }
  
  static void AddStatement() {
    if (curBlock != null)
      curBlock.AddStatement();
  }
  
  
  
  static void CreateMethodBlock() {
    curMethod = new MethodCounter(new Position(la.pos, la.line, numberOfInserts));
    curBlock = curMethod;
  }
  
  static void EndMethodBlock() {
    EndMethodBlock("");
  }
  
  static void EndMethodBlock(string template) {
    ((MethodCounter)curBlock).Name = template + Buffer.GetString(curBlock.Start.Abs-numberOfInserts, t.pos+t.val.Length);
    curClass.AddMethod((MethodCounter)curBlock);
    counters.AddMethod((MethodCounter)curBlock);
    curMethod = (MethodCounter)EndBlock();
  }

  static void CreateClassCounter() {
    curClass = new ClassCounter(new Position(la.pos, la.line, numberOfInserts));
    curBlock = curClass;
  }
  
  static void EndClassCounter(string id) {
    curClass.Name = id;
    counters.AddClass(curClass);
    curClass = (ClassCounter)EndBlock();
  }


  // Sets the start position of the curBlock to the position of the look ahead token
  static void SetStart() {
    curBlock.Start = new Position(la.pos, la.line, numberOfInserts);
  }
  
  static void SetBodyStart() {
    curClass.BodyStart = new Position(la.pos, la.line, numberOfInserts);
  }

  static IBlock EndBlock() {
    // don't override end position
    if (curBlock != null && curBlock.End == null)
      curBlock.End = new Position(t.pos + t.val.Length - 1, t.line, numberOfInserts);
    /*AbstractBlock returnBlock = (AbstractBlock)curBlock; curBlock = null;
    return returnBlock; */
    return curBlock;
  }
  
  static string storedTemplate = "";
  
  static void StoreTemplate() {
    storedTemplate = Buffer.GetString(curBlock.Start.Abs-numberOfInserts, t.pos + t.val.Length) + ".";
  }
  
  static void AddLeftBrace() {
    counters.AddBrace(t.pos + t.val.Length - 1, Brace.Left);
    numberOfInserts++;
  }
  
  static void AddRightBrace() {
    counters.AddBrace(t.pos + t.val.Length - 1, Brace.Right);
    numberOfInserts++;
  }
 

  #endregion
/*------------------------------------------------------------------------*
 *----- SCANNER DESCRIPTION ----------------------------------------------*
 *------------------------------------------------------------------------*/



  static void SynErr (int n) {
    if (errDist >= minErrDist) Errors.SynErr(la.line, la.col, n);
    errDist = 0;
  }

  public static void SemErr (string msg) {
    if (errDist >= minErrDist) Errors.Error(t.line, t.col, msg);
    errDist = 0;
  }
  
  static void Get () {
    for (;;) {
      t = la;
      la = Scanner.Scan();
      if (la.kind <= maxT) { 
        if (la.val==";") 
          AddStatement(); 
        ++errDist; break; 
      }
        if (la.kind == 129) {
        }
        if (la.kind == 130) {
        }
        if (la.kind == 131) {
        }
        if (la.kind == 132) {
        }
        if (la.kind == 133) {
        }
        if (la.kind == 134) {
        }
        if (la.kind == 135) {
        }
        if (la.kind == 136) {
        }
        if (la.kind == 137) {
        }
        if (la.kind == 138) {
        }
        if (la.kind == 139) {
        }

      la = t;
    }
  }
  
  static void Expect (int n) {
    if (la.kind==n) Get(); else { SynErr(n); }
  }
  
  static bool StartOf (int s) {
    return set[s, la.kind];
  }
  
  static void ExpectWeak (int n, int follow) {
    if (la.kind == n) Get();
    else {
      SynErr(n);
      while (!StartOf(follow)) Get();
    }
  }
  
  static bool WeakSeparator (int n, int syFol, int repFol) {
    bool[] s = new bool[maxT+1];
    if (la.kind == n) { Get(); return true; }
    else if (StartOf(repFol)) return false;
    else {
      for (int i=0; i <= maxT; i++) {
        s[i] = set[syFol, i] || set[repFol, i] || set[0, i];
      }
      SynErr(n);
      while (!s[la.kind]) Get();
      return StartOf(syFol);
    }
  }
  
  static void CS() {
    while (la.kind == 53) {
      UsingDirective();
    }
    while (IsGlobalAttrTarget()) {
      GlobalAttributes();
    }
    while (StartOf(1)) {
      NamespaceMember();
    }
  }

  static void UsingDirective() {
    string ns, alias = null; 
    Expect(53);
    if (IsAssignment()) {
      Expect(1);
      alias = t.val; 
      Expect(35);
    }
    Qualident(out ns);
    if (alias != null) aliasNames[alias] = ns;
    else nsNames.Add(ns);
    
    Expect(50);
  }

  static void GlobalAttributes() {
    Expect(42);
    Expect(1);
    if (t.val != "assembly" && t.val != "module") Error("global attribute target specifier (\"assembly\") or (\"module\") expected"); 
    Expect(36);
    Attribute();
    while (NotFinalComma()) {
      Expect(37);
      Attribute();
    }
    if (la.kind == 37) {
      Get();
    }
    Expect(48);
  }

  static void NamespaceMember() {
    Modifiers m = new Modifiers(); 
    string id, oldNamespace; 
    if (la.kind == 54) {
      Get();
      Qualident(out id);
      oldNamespace = curNamespace; curNamespace += id; 
      Expect(41);
      while (la.kind == 53) {
        UsingDirective();
      }
      while (StartOf(1)) {
        NamespaceMember();
      }
      Expect(47);
      if (la.kind == 50) {
        Get();
      }
      curNamespace = oldNamespace; 
    } else if (StartOf(2)) {
      while (la.kind == 42) {
        Attributes();
      }
      while (StartOf(3)) {
        TypeModifier(m);
      }
      TypeDecl(m);
    } else SynErr(129);
  }

  static void Qualident(out string qualident) {
    Expect(1);
    qualident = t.val; 
    while (DotAndIdent()) {
      Expect(39);
      Expect(1);
      qualident += "." + t.val; 
    }
  }

  static void Attributes() {
    Expect(42);
    if (IsLocalAttrTarget()) {
      if (la.kind == 13) {
        Get();
      } else if (la.kind == 21) {
        Get();
      } else if (la.kind == 1) {
        Get();
        if (t.val != "field"    && t.val != "method" &&
           t.val != "module"   && t.val != "param"  &&
           t.val != "property" && t.val != "type")
         Error("attribute target specifier (event, return, field," +
               "method, module, param, property, or type) expected");
        
      } else SynErr(130);
      Expect(36);
    }
    Attribute();
    while (NotFinalComma()) {
      Expect(37);
      Attribute();
    }
    if (la.kind == 37) {
      Get();
    }
    Expect(48);
  }

  static void TypeModifier(Modifiers m) {
    switch (la.kind) {
    case 18: {
      Get();
      m.Add(Modifier.@new); 
      break;
    }
    case 68: {
      Get();
      m.Add(Modifier.@public); 
      break;
    }
    case 69: {
      Get();
      m.Add(Modifier.@protected); 
      break;
    }
    case 70: {
      Get();
      m.Add(Modifier.@internal); 
      break;
    }
    case 71: {
      Get();
      m.Add(Modifier.@private); 
      break;
    }
    case 72: {
      Get();
      m.Add(Modifier.@unsafe); 
      break;
    }
    case 73: {
      Get();
      m.Add(Modifier.@abstract); 
      break;
    }
    case 74: {
      Get();
      m.Add(Modifier.@sealed); 
      break;
    }
    default: SynErr(131); break;
    }
  }

  static void TypeDecl(Modifiers m) {
    TypeKind dummy; 
    if (la.kind == 55) {
      m.Check(Modifier.classes); 
      CreateClassCounter(); 
      Get();
      Expect(1);
      EndClassCounter(t.val); 
      if (la.kind == 36) {
        ClassBase();
      }
      ClassBody();
      if (la.kind == 50) {
        Get();
      }
    } else if (StartOf(4)) {
      m.Check(Modifier.nonClassTypes); 
      if (la.kind == 56) {
        CreateClassCounter(); 
        Get();
        Expect(1);
        EndClassCounter(t.val); 
        if (la.kind == 36) {
          Base();
        }
        StructBody();
        if (la.kind == 50) {
          Get();
        }
      } else if (la.kind == 57) {
        Get();
        Expect(1);
        if (la.kind == 36) {
          Base();
        }
        Expect(41);
        while (StartOf(5)) {
          InterfaceMember();
        }
        Expect(47);
        if (la.kind == 50) {
          Get();
        }
      } else if (la.kind == 58) {
        Get();
        Expect(1);
        if (la.kind == 36) {
          Get();
          IntType();
        }
        EnumBody();
        if (la.kind == 50) {
          Get();
        }
      } else {
        Get();
        if (NotVoidPointer()) {
          Expect(33);
        } else if (StartOf(6)) {
          Type(out dummy);
        } else SynErr(132);
        Expect(1);
        Expect(43);
        if (StartOf(7)) {
          FormalParams();
        }
        Expect(49);
        Expect(50);
      }
    } else SynErr(133);
  }

  static void ClassBase() {
    string id; 
    Expect(36);
    ClassType();
    while (la.kind == 37) {
      Get();
      Qualident(out id);
    }
  }

  static void ClassBody() {
    Expect(41);
    SetBodyStart(); 
    while (StartOf(8)) {
      while (la.kind == 42) {
        Attributes();
      }
      Modifiers m = new Modifiers(); 
      CreateMethodBlock(); 
      while (StartOf(9)) {
        MemberModifier(m);
      }
      ClassMember(m);
    }
    Expect(47);
  }

  static void Base() {
    string id; 
    Expect(36);
    Qualident(out id);
    while (la.kind == 37) {
      Get();
      Qualident(out id);
    }
  }

  static void StructBody() {
    Expect(41);
    SetBodyStart(); 
    while (StartOf(10)) {
      while (la.kind == 42) {
        Attributes();
      }
      Modifiers m = new Modifiers(); 
      CreateMethodBlock(); 
      while (StartOf(9)) {
        MemberModifier(m);
      }
      StructMember(m);
    }
    Expect(47);
  }

  static void InterfaceMember() {
    TypeKind dummy; 
    while (la.kind == 42) {
      Attributes();
    }
    if (la.kind == 18) {
      Get();
    }
    if (NotVoidPointer()) {
      Expect(33);
      Expect(1);
      Expect(43);
      if (StartOf(7)) {
        FormalParams();
      }
      Expect(49);
      Expect(50);
    } else if (StartOf(6)) {
      Type(out dummy);
      if (la.kind == 1) {
        Get();
        if (la.kind == 43) {
          Get();
          if (StartOf(7)) {
            FormalParams();
          }
          Expect(49);
          Expect(50);
        } else if (la.kind == 41) {
          Get();
          InterfaceAccessors();
          Expect(47);
        } else SynErr(134);
      } else if (la.kind == 26) {
        Get();
        Expect(42);
        FormalParams();
        Expect(48);
        Expect(41);
        InterfaceAccessors();
        Expect(47);
      } else SynErr(135);
    } else if (la.kind == 13) {
      Get();
      Type(out dummy);
      Expect(1);
      Expect(50);
    } else SynErr(136);
  }

  static void IntType() {
    switch (la.kind) {
    case 22: {
      Get();
      break;
    }
    case 8: {
      Get();
      break;
    }
    case 23: {
      Get();
      break;
    }
    case 32: {
      Get();
      break;
    }
    case 16: {
      Get();
      break;
    }
    case 29: {
      Get();
      break;
    }
    case 17: {
      Get();
      break;
    }
    case 30: {
      Get();
      break;
    }
    case 9: {
      Get();
      break;
    }
    default: SynErr(137); break;
    }
  }

  static void EnumBody() {
    Expect(41);
    if (la.kind == 1 || la.kind == 42) {
      EnumMember();
      while (NotFinalComma()) {
        Expect(37);
        EnumMember();
      }
      if (la.kind == 37) {
        Get();
      }
    }
    Expect(47);
  }

  static void Type(out TypeKind type) {
    type = TypeKind.simple; 
    if (StartOf(11)) {
      SimpleType();
    } else if (la.kind == 1 || la.kind == 20 || la.kind == 25) {
      ClassType();
    } else if (la.kind == 33) {
      Get();
      Expect(52);
      type = TypeKind.pointer; 
    } else SynErr(138);
    while (IsPointerOrDims()) {
      if (la.kind == 52) {
        Get();
        type = TypeKind.pointer; 
      } else if (la.kind == 42) {
        Get();
        while (la.kind == 37) {
          Get();
        }
        Expect(48);
        type = TypeKind.array; 
      } else SynErr(139);
    }
  }

  static void FormalParams() {
    while (la.kind == 42) {
      Attributes();
    }
    if (StartOf(12)) {
      Par();
      if (la.kind == 37) {
        Get();
        FormalParams();
      }
    } else if (la.kind == 67) {
      ParArray();
    } else SynErr(140);
  }

  static void ClassType() {
    string id; 
    if (la.kind == 1) {
      Qualident(out id);
    } else if (la.kind == 20) {
      Get();
    } else if (la.kind == 25) {
      Get();
    } else SynErr(141);
  }

  static void MemberModifier(Modifiers m) {
    switch (la.kind) {
    case 73: {
      Get();
      m.Add(Modifier.@abstract); 
      break;
    }
    case 75: {
      Get();
      m.Add(Modifier.@extern); 
      break;
    }
    case 70: {
      Get();
      m.Add(Modifier.@internal); 
      break;
    }
    case 18: {
      Get();
      m.Add(Modifier.@new); 
      break;
    }
    case 76: {
      Get();
      m.Add(Modifier.@override); 
      break;
    }
    case 71: {
      Get();
      m.Add(Modifier.@private); 
      break;
    }
    case 69: {
      Get();
      m.Add(Modifier.@protected); 
      break;
    }
    case 68: {
      Get();
      m.Add(Modifier.@public); 
      break;
    }
    case 77: {
      Get();
      m.Add(Modifier.@readonly); 
      break;
    }
    case 74: {
      Get();
      m.Add(Modifier.@sealed); 
      break;
    }
    case 78: {
      Get();
      m.Add(Modifier.@static); 
      break;
    }
    case 72: {
      Get();
      m.Add(Modifier.@unsafe); 
      break;
    }
    case 79: {
      Get();
      m.Add(Modifier.@virtual); 
      break;
    }
    case 80: {
      Get();
      m.Add(Modifier.@volatile); 
      break;
    }
    default: SynErr(142); break;
    }
  }

  static void ClassMember(Modifiers m) {
    if (StartOf(13)) {
      StructMember(m);
    } else if (la.kind == 51) {
      Get();
      Expect(1);
      Expect(43);
      Expect(49);
      if (la.kind == 41) {
        Block();
      } else if (la.kind == 50) {
        Get();
      } else SynErr(143);
    } else SynErr(144);
  }

  static void StructMember(Modifiers m) {
    string id; TypeKind dummy; 
    if (la.kind == 60) {
      m.Check(Modifier.constants); 
      Get();
      Type(out dummy);
      Expect(1);
      Expect(35);
      Expr();
      while (la.kind == 37) {
        Get();
        Expect(1);
        Expect(35);
        Expr();
      }
      Expect(50);
    } else if (NotVoidPointer()) {
      m.Check(Modifier.propEvntMeths); 
      Expect(33);
      Qualident(out id);
      Expect(43);
      if (StartOf(7)) {
        FormalParams();
      }
      Expect(49);
      if (la.kind == 41) {
        EndMethodBlock(); 
        Block();
      } else if (la.kind == 50) {
        Get();
      } else SynErr(145);
    } else if (la.kind == 13) {
      m.Check(Modifier.propEvntMeths); 
      Get();
      Type(out dummy);
      if (IsFieldDecl()) {
        Field();
        while (la.kind == 37) {
          Get();
          Field();
        }
        Expect(50);
      } else if (la.kind == 1) {
        Qualident(out id);
        StoreTemplate(); 
        Expect(41);
        EventAccessors();
        Expect(47);
      } else SynErr(146);
    } else if (IdentAndLPar()) {
      m.Check(Modifier.constructors | Modifier.@static); 
      Expect(1);
      Expect(43);
      if (StartOf(7)) {
        m.Check(Modifier.constructors); 
        FormalParams();
      }
      Expect(49);
      if (la.kind == 36) {
        m.Check(Modifier.constructors); 
        ConstructorCall();
      }
      if (la.kind == 41) {
        EndMethodBlock(); 
        Block();
      } else if (la.kind == 50) {
        Get();
      } else SynErr(147);
    } else if (la.kind == 61 || la.kind == 62) {
      m.Check(Modifier.operators);
      if (m.IsNone) Error("at least one modifier must be set"); 
      
      if (la.kind == 61) {
        Get();
      } else {
        Get();
      }
      Expect(63);
      Type(out dummy);
      Expect(43);
      Type(out dummy);
      Expect(1);
      Expect(49);
      if (la.kind == 41) {
        EndMethodBlock(); 
        Block();
      } else if (la.kind == 50) {
        Get();
      } else SynErr(148);
    } else if (StartOf(14)) {
      TypeDecl(m);
    } else if (StartOf(6)) {
      Type(out dummy);
      if (la.kind == 63) {
        Token op;
        m.Check(Modifier.operators);
        if (m.IsNone) Error("at least one modifier must be set");
        
        Get();
        OverloadableOp(out op);
        Expect(43);
        Type(out dummy);
        Expect(1);
        if (la.kind == 37) {
          Get();
          Type(out dummy);
          Expect(1);
          if (unaryOp[op.kind]) Error("too many operands for unary operator"); 
        } else if (la.kind == 49) {
          if (!unaryOp[op.kind]) Error("too few operands for binary operator"); 
        } else SynErr(149);
        Expect(49);
        if (la.kind == 41) {
          EndMethodBlock(); 
          Block();
        } else if (la.kind == 50) {
          Get();
        } else SynErr(150);
      } else if (IsFieldDecl()) {
        m.Check(Modifier.fields); 
        Field();
        while (la.kind == 37) {
          Get();
          Field();
        }
        Expect(50);
      } else if (la.kind == 26) {
        m.Check(Modifier.indexers); 
        Get();
        Expect(42);
        FormalParams();
        Expect(48);
        StoreTemplate(); 
        Expect(41);
        Accessors();
        Expect(47);
      } else if (la.kind == 1) {
        Qualident(out id);
        if (la.kind == 43) {
          m.Check(Modifier.propEvntMeths); 
          Get();
          if (StartOf(7)) {
            FormalParams();
          }
          Expect(49);
          if (la.kind == 41) {
            EndMethodBlock(); 
            Block();
          } else if (la.kind == 50) {
            Get();
          } else SynErr(151);
        } else if (la.kind == 41) {
          StoreTemplate(); 
          Get();
          Accessors();
          Expect(47);
        } else if (la.kind == 39) {
          m.Check(Modifier.indexers); 
          Get();
          Expect(26);
          Expect(42);
          FormalParams();
          Expect(48);
          StoreTemplate(); 
          Expect(41);
          Accessors();
          Expect(47);
        } else SynErr(152);
      } else SynErr(153);
    } else SynErr(154);
  }

  static void EnumMember() {
    while (la.kind == 42) {
      Attributes();
    }
    Expect(1);
    if (la.kind == 35) {
      Get();
      Expr();
    }
  }

  static void Block() {
    bool incl = false; 
    Expect(41);
    if (curMethod.Ref == null) { curMethod.Ref = CreateBlock(); }  
    else CreateBlock(); 
    while (StartOf(15)) {
      Statement(out incl);
    }
    EndBlock(); 
    Expect(47);
  }

  static void Expr() {
    Unary();
    if (StartOf(16)) {
      OrExpr();
      if (la.kind == 110) {
        Get();
        Expr();
        Expect(36);
        Expr();
      }
    } else if (StartOf(17)) {
      AssignOp();
      Expr();
    } else SynErr(155);
  }

  static void Field() {
    Expect(1);
    if (la.kind == 35) {
      Get();
      Init();
    }
  }

  static void EventAccessors() {
    while (la.kind == 42) {
      Attributes();
    }
    if (la.val == "add") {
      AddAccessor();
      while (la.kind == 42) {
        Attributes();
      }
      RemoveAccessor();
    } else if (la.val == "remove") {
      RemoveAccessor();
      while (la.kind == 42) {
        Attributes();
      }
      AddAccessor();
    } else if (la.kind == 1) {
      Get();
      Error("add or remove accessor declaration expected"); 
    } else SynErr(156);
  }

  static void ConstructorCall() {
    Expect(36);
    if (la.kind == 6) {
      Get();
    } else if (la.kind == 26) {
      Get();
    } else SynErr(157);
    Expect(43);
    if (StartOf(18)) {
      Argument();
      while (la.kind == 37) {
        Get();
        Argument();
      }
    }
    Expect(49);
  }

  static void OverloadableOp(out Token op) {
    switch (la.kind) {
    case 46: {
      Get();
      break;
    }
    case 44: {
      Get();
      break;
    }
    case 45: {
      Get();
      break;
    }
    case 51: {
      Get();
      break;
    }
    case 40: {
      Get();
      break;
    }
    case 38: {
      Get();
      break;
    }
    case 27: {
      Get();
      break;
    }
    case 14: {
      Get();
      break;
    }
    case 52: {
      Get();
      break;
    }
    case 125: {
      Get();
      break;
    }
    case 126: {
      Get();
      break;
    }
    case 34: {
      Get();
      break;
    }
    case 113: {
      Get();
      break;
    }
    case 114: {
      Get();
      break;
    }
    case 123: {
      Get();
      break;
    }
    case 124: {
      Get();
      break;
    }
    case 116: {
      Get();
      break;
    }
    case 115: {
      Get();
      break;
    }
    case 118: {
      Get();
      break;
    }
    case 117: {
      Get();
      break;
    }
    case 120: {
      Get();
      break;
    }
    case 119: {
      Get();
      break;
    }
    default: SynErr(158); break;
    }
    op = t; 
  }

  static void Accessors() {
    while (la.kind == 42) {
      Attributes();
    }
    if (la.val == "get") {
      GetAccessor();
      if (la.kind == 1 || la.kind == 42) {
        while (la.kind == 42) {
          Attributes();
        }
        SetAccessor();
      }
    } else if (la.val == "set") {
      SetAccessor();
      if (la.kind == 1 || la.kind == 42) {
        while (la.kind == 42) {
          Attributes();
        }
        GetAccessor();
      }
    } else if (la.kind == 1) {
      Get();
      Error("get or set accessor declaration expected"); 
    } else SynErr(159);
  }

  static void InterfaceAccessors() {
    bool getFound = false, setFound = false; 
    while (la.kind == 42) {
      Attributes();
    }
    if (la.val == "get") {
      Expect(1);
      getFound = true; 
    } else if (la.val == "set") {
      Expect(1);
      setFound = true; 
    } else if (la.kind == 1) {
      Get();
      Error("set or get expected"); 
    } else SynErr(160);
    Expect(50);
    if (la.kind == 1 || la.kind == 42) {
      while (la.kind == 42) {
        Attributes();
      }
      if (la.val == "get") {
        Expect(1);
        if (getFound) Error("get already declared"); 
      } else if (la.val == "set") {
        Expect(1);
        if (setFound) Error("set already declared"); 
      } else if (la.kind == 1) {
        Get();
        Error("set or get expected"); 
      } else SynErr(161);
      Expect(50);
    }
  }

  static void Init() {
    if (StartOf(19)) {
      Expr();
    } else if (la.kind == 41) {
      ArrayInit();
    } else SynErr(162);
  }

  static void LocalVarDecl() {
    TypeKind dummy; 
    Type(out dummy);
    LocalVar();
    while (la.kind == 37) {
      Get();
      LocalVar();
    }
  }

  static void LocalVar() {
    TypeKind dummy; 
    Expect(1);
    if (la.kind == 35) {
      Get();
      if (StartOf(20)) {
        Init();
      } else if (la.kind == 64) {
        Get();
        Type(out dummy);
        Expect(42);
        Expr();
        Expect(48);
      } else SynErr(163);
    }
  }

  static void ArrayInit() {
    Expect(41);
    if (StartOf(20)) {
      Init();
      while (NotFinalComma()) {
        Expect(37);
        Init();
      }
      if (la.kind == 37) {
        Get();
      }
    }
    Expect(47);
  }

  static void Par() {
    TypeKind dummy; 
    if (la.kind == 65 || la.kind == 66) {
      if (la.kind == 65) {
        Get();
      } else {
        Get();
      }
    }
    Type(out dummy);
    Expect(1);
  }

  static void ParArray() {
    TypeKind dummy; 
    Expect(67);
    Type(out dummy);
    Expect(1);
  }

  static void Argument() {
    if (la.kind == 65 || la.kind == 66) {
      if (la.kind == 65) {
        Get();
      } else {
        Get();
      }
    }
    Expr();
  }

  static void GetAccessor() {
    CreateMethodBlock(); 
    Expect(1);
    if (t.val != "get") Error("get expected"); 
    EndMethodBlock(storedTemplate); 
    if (la.kind == 41) {
      Block();
    } else if (la.kind == 50) {
      Get();
    } else SynErr(164);
  }

  static void SetAccessor() {
    CreateMethodBlock(); 
    Expect(1);
    if (t.val != "set") Error("set expected"); 
    EndMethodBlock(storedTemplate); 
    if (la.kind == 41) {
      Block();
    } else if (la.kind == 50) {
      Get();
    } else SynErr(165);
  }

  static void AddAccessor() {
    CreateMethodBlock(); 
    Expect(1);
    if (t.val != "add") Error("add expected"); 
    EndMethodBlock(storedTemplate); 
    Block();
  }

  static void RemoveAccessor() {
    CreateMethodBlock(); 
    Expect(1);
    if (t.val != "remove") Error("remove expected"); 
    EndMethodBlock(storedTemplate);   
    Block();
  }

  static void Attribute() {
    string id; 
    Qualident(out id);
    if (la.kind == 43) {
      AttributeArguments();
    }
  }

  static void AttributeArguments() {
    bool nameFound = false; 
    Expect(43);
    if (StartOf(19)) {
      if (IsAssignment()) {
        nameFound = true; 
        Expect(1);
        Expect(35);
      }
      Expr();
      while (la.kind == 37) {
        Get();
        if (IsAssignment()) {
          nameFound = true; 
          Expect(1);
          Expect(35);
        } else if (StartOf(19)) {
          if (nameFound) Error("no positional argument after named argument"); 
        } else SynErr(166);
        Expr();
      }
    }
    Expect(49);
  }

  static void SimpleType() {
    if (StartOf(21)) {
      IntType();
    } else if (la.kind == 15) {
      Get();
    } else if (la.kind == 12) {
      Get();
    } else if (la.kind == 11) {
      Get();
    } else if (la.kind == 7) {
      Get();
    } else SynErr(167);
  }

  static void Statement(out bool inclJump) {
    TypeKind dummy; inclJump = false; 
    if (IsLabel()) {
      EndBlock(); 
      Expect(1);
      Expect(36);
      CreateBlock(); 
      Statement(out inclJump);
    } else if (la.kind == 60) {
      Get();
      Type(out dummy);
      Expect(1);
      Expect(35);
      Expr();
      while (la.kind == 37) {
        Get();
        Expect(1);
        Expect(35);
        Expr();
      }
      Expect(50);
    } else if (IsLocalVarDecl()) {
      LocalVarDecl();
      Expect(50);
    } else if (StartOf(22)) {
      EmbeddedStatement(out inclJump);
    } else SynErr(168);
  }

  static void EmbeddedStatement(out bool inclJump) {
    TypeKind type; inclJump = false;
    if (la.kind == 41) {
      Block2(out inclJump);
    } else if (la.kind == 50) {
      Get();
    } else if (UnCheckedAndLBrace()) {
      if (la.kind == 10) {
        Get();
      } else if (la.kind == 31) {
        Get();
      } else SynErr(169);
      Block2(out inclJump);
    } else if (StartOf(19)) {
      StatementExpr();
      Expect(50);
    } else if (la.kind == 81) {
      IBlock bBeforeIf = EndBlock(); 
      Get();
      Expect(43);
      CreateBlock(bBeforeIf); AddStatement(); 
      Expr();
      EndBlock(); 
      Expect(49);
      AddLeftBrace(); IBlock bIfEm = CreateBlock(); 
      EmbeddedStatement(out inclJump);
      EndBlock(); AddRightBrace(); 
      if (la.kind == 82) {
        Get();
        IBlock bElseEm = CreateBlock(bBeforeIf - bIfEm); 
        EmbeddedStatement(out inclJump);
        EndBlock(); 
      }
      CreateBlock(inclJump, bBeforeIf); 
    } else if (la.kind == 83) {
      IBlock bBeforeSwitch = EndBlock(); 
      Get();
      Expect(43);
      CreateBlock(false, bBeforeSwitch); 
      Expr();
      AddStatement(); EndBlock(); 
      Expect(49);
      Expect(41);
      while (la.kind == 104 || la.kind == 105) {
        SwitchSection(out inclJump);
      }
      Expect(47);
      CreateBlock(inclJump, bBeforeSwitch); 
    } else if (la.kind == 84) {
      IBlock bBeforeWhile = EndBlock(); 
      Get();
      Expect(43);
      IBlock bWhile = CreateBlock(null); AddStatement(); 
      Expr();
      EndBlock(); 
      Expect(49);
      AddLeftBrace(); IBlock bWhileEm = CreateBlock(); 
      ((CalcBlock)bWhile).Ref = bBeforeWhile + bWhileEm; 
      EmbeddedStatement(out inclJump);
      EndBlock(); AddRightBrace(); 
      CreateBlock(inclJump, bBeforeWhile); 
    } else if (la.kind == 85) {
      IBlock bBeforeDo = EndBlock(); 
      Get();
      AddLeftBrace(); IBlock bDoEm = CreateBlock(); 
      EmbeddedStatement(out inclJump);
      EndBlock(); AddRightBrace(); 
      Expect(84);
      Expect(43);
      CreateBlock(bDoEm); 
      Expr();
      AddStatement(); EndBlock(); 
      Expect(49);
      Expect(50);
      CreateBlock(inclJump, bBeforeDo); 
    } else if (la.kind == 86) {
      IBlock bBeforeFor = EndBlock(); 
      Get();
      Expect(43);
      if (StartOf(23)) {
        CreateBlock(bBeforeFor);  
        ForInit();
        EndBlock(); 
      }
      Expect(50);
      IBlock bFor = null; 
      if (StartOf(19)) {
        bFor = CreateBlock(null);  
        Expr();
        EndBlock(); 
      }
      Expect(50);
      IBlock bForInc = null; 
      if (StartOf(19)) {
        bForInc = CreateBlock(null); 
        ForInc();
        AddStatement(); EndBlock(); 
      }
      Expect(49);
      AddLeftBrace(); IBlock forEm = CreateBlock();  
      if (bFor != null) ((CalcBlock)bFor).Ref = forEm + bBeforeFor; 
      if (bForInc != null) ((CalcBlock)bForInc).Ref = forEm; 
      EmbeddedStatement(out inclJump);
      EndBlock(); AddRightBrace(); 
      CreateBlock(inclJump, bBeforeFor); 
    } else if (la.kind == 87) {
      IBlock bBeforeFe = EndBlock(); 
      Get();
      Expect(43);
      IBlock bFe = CreateBlock(bBeforeFe); 
      Type(out type);
      Expect(1);
      Expect(88);
      Expr();
      AddStatement(); EndBlock(); 
      Expect(49);
      AddLeftBrace(); IBlock bFeEm = CreateBlock();   
      EmbeddedStatement(out inclJump);
      EndBlock(); AddRightBrace();   
      CreateBlock(inclJump, bBeforeFe); 
    } else if (la.kind == 89) {
      Get();
      Expect(50);
      inclJump = true; EndBlock(); CreateBlock();  
    } else if (la.kind == 90) {
      Get();
      Expect(50);
      inclJump = true; EndBlock(); CreateBlock();  
    } else if (la.kind == 106) {
      GotoStatement();
      inclJump = true; EndBlock(); CreateBlock();  
    } else if (la.kind == 21) {
      Get();
      if (StartOf(19)) {
        Expr();
      }
      Expect(50);
      inclJump = true; EndBlock(); CreateBlock();  
    } else if (la.kind == 91) {
      Get();
      if (StartOf(19)) {
        Expr();
      }
      Expect(50);
      inclJump = true; EndBlock(); CreateBlock();  
    } else if (la.kind == 107) {
      TryStatement(out inclJump);
    } else if (la.kind == 92) {
      Get();
      Expect(43);
      Expr();
      Expect(49);
      EmbeddedStatement(out inclJump);
    } else if (la.kind == 53) {
      Get();
      Expect(43);
      Resource();
      Expect(49);
      EmbeddedStatement(out inclJump);
    } else if (la.kind == 72) {
      Get();
      Block2(out inclJump);
    } else if (la.kind == 93) {
      Get();
      Expect(43);
      Type(out type);
      if (type != TypeKind.pointer) Error("can only fix pointer types"); 
      Expect(1);
      Expect(35);
      Expr();
      while (la.kind == 37) {
        Get();
        Expect(1);
        Expect(35);
        Expr();
      }
      Expect(49);
      EmbeddedStatement(out inclJump);
    } else SynErr(170);
  }

  static void Block2(out bool inclJump) {
    bool statementIncl = false; inclJump = false; 
    Expect(41);
    if (new Position(t.pos, t.line, numberOfInserts).Equals(curBlock.Start)) SetStart(); 
    while (StartOf(15)) {
      Statement(out statementIncl);
      inclJump = inclJump || statementIncl; 
      statementIncl = false; 
    }
    EndBlock(); 
    Expect(47);
  }

  static void StatementExpr() {
    bool isAssignment = assnStartOp[la.kind] || IsTypeCast(); 
    Unary();
    if (StartOf(17)) {
      AssignOp();
      Expr();
    } else if (la.kind == 37 || la.kind == 49 || la.kind == 50) {
      if (isAssignment) Error("error in assignment."); 
    } else SynErr(171);
  }

  static void SwitchSection(out bool inclJump) {
    bool stateIncl = false; inclJump = false; 
    SwitchLabel();
    while (la.kind == 104 || la.kind == 105) {
      SwitchLabel();
    }
    IBlock blockStat = CreateBlock(true, null); 
    Statement(out stateIncl);
    inclJump = stateIncl; 
    while (StartOf(15)) {
      Statement(out stateIncl);
      inclJump = inclJump || stateIncl; 
    }
    EndBlock(); 
  }

  static void ForInit() {
    if (IsLocalVarDecl()) {
      LocalVarDecl();
    } else if (StartOf(19)) {
      StatementExpr();
      while (la.kind == 37) {
        Get();
        StatementExpr();
      }
    } else SynErr(172);
  }

  static void ForInc() {
    StatementExpr();
    while (la.kind == 37) {
      Get();
      StatementExpr();
    }
  }

  static void GotoStatement() {
    Expect(106);
    if (la.kind == 1) {
      Get();
      Expect(50);
    } else if (la.kind == 104) {
      Get();
      Expr();
      Expect(50);
    } else if (la.kind == 105) {
      Get();
      Expect(50);
    } else SynErr(173);
  }

  static void TryStatement(out bool inclJump) {
    bool blockJump=false; inclJump=false; IBlock bBeforeFor = EndBlock(); 
    Expect(107);
    IBlock bTry = CreateBlock(bBeforeFor); 
    Block2(out blockJump);
    EndBlock(); inclJump = inclJump || blockJump; 
    if (la.kind == 109) {
      CatchClauses(out blockJump);
      inclJump = inclJump || blockJump; 
      if (la.kind == 108) {
        Get();
        CreateBlock(bTry); 
        Block2(out blockJump);
        EndBlock(); inclJump = inclJump || blockJump; 
      }
    } else if (la.kind == 108) {
      Get();
      CreateBlock(bTry); 
      Block2(out blockJump);
      EndBlock(); inclJump = inclJump || blockJump; 
    } else SynErr(174);
  }

  static void Resource() {
    if (IsLocalVarDecl()) {
      LocalVarDecl();
    } else if (StartOf(19)) {
      Expr();
    } else SynErr(175);
  }

  static void Unary() {
    TypeKind dummy; 
    while (unaryHead[la.kind] || IsTypeCast()) {
      switch (la.kind) {
      case 46: {
        Get();
        break;
      }
      case 44: {
        Get();
        break;
      }
      case 45: {
        Get();
        break;
      }
      case 51: {
        Get();
        break;
      }
      case 52: {
        Get();
        break;
      }
      case 40: {
        Get();
        break;
      }
      case 38: {
        Get();
        break;
      }
      case 34: {
        Get();
        break;
      }
      case 43: {
        Get();
        Type(out dummy);
        Expect(49);
        break;
      }
      default: SynErr(176); break;
      }
    }
    Primary();
  }

  static void AssignOp() {
    switch (la.kind) {
    case 35: {
      Get();
      break;
    }
    case 94: {
      Get();
      break;
    }
    case 95: {
      Get();
      break;
    }
    case 96: {
      Get();
      break;
    }
    case 97: {
      Get();
      break;
    }
    case 98: {
      Get();
      break;
    }
    case 99: {
      Get();
      break;
    }
    case 100: {
      Get();
      break;
    }
    case 101: {
      Get();
      break;
    }
    case 102: {
      Get();
      break;
    }
    case 103: {
      Get();
      break;
    }
    default: SynErr(177); break;
    }
  }

  static void SwitchLabel() {
    if (la.kind == 104) {
      Get();
      Expr();
      Expect(36);
    } else if (la.kind == 105) {
      Get();
      Expect(36);
    } else SynErr(178);
  }

  static void CatchClauses(out bool inclJump) {
    inclJump = false; bool blockJump; 
    Expect(109);
    if (la.kind == 41) {
      CreateBlock(); 
      Block2(out blockJump);
      EndBlock(); inclJump = inclJump || blockJump; 
    } else if (la.kind == 43) {
      Get();
      ClassType();
      if (la.kind == 1) {
        Get();
      }
      Expect(49);
      CreateBlock(); 
      Block2(out blockJump);
      EndBlock(); inclJump = inclJump || blockJump; 
      if (la.kind == 109) {
        CatchClauses(out inclJump);
      }
    } else SynErr(179);
  }

  static void OrExpr() {
    AndExpr();
    while (la.kind == 111) {
      Get();
      Unary();
      AndExpr();
    }
  }

  static void AndExpr() {
    BitOrExpr();
    while (la.kind == 112) {
      Get();
      Unary();
      BitOrExpr();
    }
  }

  static void BitOrExpr() {
    BitXorExpr();
    while (la.kind == 113) {
      Get();
      Unary();
      BitXorExpr();
    }
  }

  static void BitXorExpr() {
    BitAndExpr();
    while (la.kind == 114) {
      Get();
      Unary();
      BitAndExpr();
    }
  }

  static void BitAndExpr() {
    EqlExpr();
    while (la.kind == 34) {
      Get();
      Unary();
      EqlExpr();
    }
  }

  static void EqlExpr() {
    RelExpr();
    while (la.kind == 115 || la.kind == 116) {
      if (la.kind == 115) {
        Get();
      } else {
        Get();
      }
      Unary();
      RelExpr();
    }
  }

  static void RelExpr() {
    TypeKind dummy; 
    ShiftExpr();
    while (StartOf(24)) {
      if (StartOf(25)) {
        if (la.kind == 117) {
          Get();
        } else if (la.kind == 118) {
          Get();
        } else if (la.kind == 119) {
          Get();
        } else if (la.kind == 120) {
          Get();
        } else SynErr(180);
        Unary();
        ShiftExpr();
      } else {
        if (la.kind == 121) {
          Get();
        } else if (la.kind == 122) {
          Get();
        } else SynErr(181);
        Type(out dummy);
      }
    }
  }

  static void ShiftExpr() {
    AddExpr();
    while (la.kind == 123 || la.kind == 124) {
      if (la.kind == 123) {
        Get();
      } else {
        Get();
      }
      Unary();
      AddExpr();
    }
  }

  static void AddExpr() {
    MulExpr();
    while (la.kind == 44 || la.kind == 46) {
      if (la.kind == 46) {
        Get();
      } else {
        Get();
      }
      Unary();
      MulExpr();
    }
  }

  static void MulExpr() {
    while (la.kind == 52 || la.kind == 125 || la.kind == 126) {
      if (la.kind == 52) {
        Get();
      } else if (la.kind == 125) {
        Get();
      } else {
        Get();
      }
      Unary();
    }
  }

  static void Primary() {
    TypeKind type; bool isArrayCreation = false; 
    switch (la.kind) {
    case 1: {
      Get();
      break;
    }
    case 2: case 3: case 4: case 5: case 14: case 19: case 27: {
      Literal();
      break;
    }
    case 43: {
      Get();
      Expr();
      Expect(49);
      break;
    }
    case 7: case 8: case 9: case 11: case 12: case 15: case 16: case 17: case 20: case 22: case 23: case 25: case 29: case 30: case 32: {
      switch (la.kind) {
      case 7: {
        Get();
        break;
      }
      case 8: {
        Get();
        break;
      }
      case 9: {
        Get();
        break;
      }
      case 11: {
        Get();
        break;
      }
      case 12: {
        Get();
        break;
      }
      case 15: {
        Get();
        break;
      }
      case 16: {
        Get();
        break;
      }
      case 17: {
        Get();
        break;
      }
      case 20: {
        Get();
        break;
      }
      case 22: {
        Get();
        break;
      }
      case 23: {
        Get();
        break;
      }
      case 25: {
        Get();
        break;
      }
      case 29: {
        Get();
        break;
      }
      case 30: {
        Get();
        break;
      }
      case 32: {
        Get();
        break;
      }
      }
      Expect(39);
      Expect(1);
      break;
    }
    case 26: {
      Get();
      break;
    }
    case 6: {
      Get();
      if (la.kind == 39) {
        Get();
        Expect(1);
      } else if (la.kind == 42) {
        Get();
        Expr();
        while (la.kind == 37) {
          Get();
          Expr();
        }
        Expect(48);
      } else SynErr(182);
      break;
    }
    case 18: {
      Get();
      Type(out type);
      if (la.kind == 43) {
        Get();
        if (StartOf(18)) {
          Argument();
          while (la.kind == 37) {
            Get();
            Argument();
          }
        }
        Expect(49);
      } else if (la.kind == 42) {
        isArrayCreation = true; 
        Get();
        Expr();
        while (la.kind == 37) {
          Get();
          Expr();
        }
        Expect(48);
        while (IsDims()) {
          Expect(42);
          while (la.kind == 37) {
            Get();
          }
          Expect(48);
        }
        if (la.kind == 41) {
          ArrayInit();
        }
      } else if (la.kind == 41) {
        if (type != TypeKind.array) Error("array type expected");
        isArrayCreation = true; 
        ArrayInit();
      } else SynErr(183);
      break;
    }
    case 28: {
      Get();
      Expect(43);
      if (NotVoidPointer()) {
        Expect(33);
      } else if (StartOf(6)) {
        Type(out type);
      } else SynErr(184);
      Expect(49);
      break;
    }
    case 24: {
      Get();
      Expect(43);
      Type(out type);
      Expect(49);
      break;
    }
    case 10: {
      Get();
      Expect(43);
      Expr();
      Expect(49);
      break;
    }
    case 31: {
      Get();
      Expect(43);
      Expr();
      Expect(49);
      break;
    }
    default: SynErr(185); break;
    }
    while (StartOf(26)) {
      switch (la.kind) {
      case 40: {
        Get();
        break;
      }
      case 38: {
        Get();
        break;
      }
      case 127: {
        Get();
        Expect(1);
        break;
      }
      case 39: {
        Get();
        Expect(1);
        break;
      }
      case 43: {
        Get();
        if (StartOf(18)) {
          Argument();
          while (la.kind == 37) {
            Get();
            Argument();
          }
        }
        Expect(49);
        break;
      }
      case 42: {
        if (isArrayCreation) Error("element access not allow on array creation"); 
        Get();
        Expr();
        while (la.kind == 37) {
          Get();
          Expr();
        }
        Expect(48);
        break;
      }
      }
    }
  }

  static void Literal() {
    switch (la.kind) {
    case 2: {
      Get();
      break;
    }
    case 3: {
      Get();
      break;
    }
    case 4: {
      Get();
      break;
    }
    case 5: {
      Get();
      break;
    }
    case 27: {
      Get();
      break;
    }
    case 14: {
      Get();
      break;
    }
    case 19: {
      Get();
      break;
    }
    default: SynErr(186); break;
    }
  }



  public static CounterCollection Parse(string filename) {
        #region inserted code
        numberOfInserts = 0;
        curBlock = null;
        curClass = null;
        curMethod = null;  // this is necessary for the number of statements
        Errors.count = 0;
        Scanner.Init(filename);
        counters = new CounterCollection();
        #endregion
      
    la = new Token();
    la.val = "";    
    Get();
    CS();


        #region inserted code
        return counters;
        #endregion
  }

  static bool[,] set = {
  {T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
  {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, x,x,x,x, x,x,x,x, T,T,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
  {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,T, x,x,x,x, x,x,x,x, T,T,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
  {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
  {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
  {x,T,x,x, x,x,x,T, T,T,x,T, T,T,x,T, T,T,T,x, T,x,T,T, x,T,x,x, x,T,T,x, T,T,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
  {x,T,x,x, x,x,x,T, T,T,x,T, T,x,x,T, T,T,x,x, T,x,T,T, x,T,x,x, x,T,T,x, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
  {x,T,x,x, x,x,x,T, T,T,x,T, T,x,x,T, T,T,x,x, T,x,T,T, x,T,x,x, x,T,T,x, T,T,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
  {x,T,x,x, x,x,x,T, T,T,x,T, T,T,x,T, T,T,T,x, T,x,T,T, x,T,x,x, x,T,T,x, T,T,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,T, x,x,x,T, T,T,T,T, T,T,T,x, x,x,x,x, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
  {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
  {x,T,x,x, x,x,x,T, T,T,x,T, T,T,x,T, T,T,T,x, T,x,T,T, x,T,x,x, x,T,T,x, T,T,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,T, T,T,T,x, x,x,x,x, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
  {x,x,x,x, x,x,x,T, T,T,x,T, T,x,x,T, T,T,x,x, x,x,T,T, x,x,x,x, x,T,T,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
  {x,T,x,x, x,x,x,T, T,T,x,T, T,x,x,T, T,T,x,x, T,x,T,T, x,T,x,x, x,T,T,x, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
  {x,T,x,x, x,x,x,T, T,T,x,T, T,T,x,T, T,T,x,x, T,x,T,T, x,T,x,x, x,T,T,x, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
  {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
  {x,T,T,T, T,T,T,T, T,T,T,T, T,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,x, x,x,T,x, T,T,x,T, T,T,T,x, x,x,T,T, T,T,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,T,x,T, T,T,T,T, x,T,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
  {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, T,T,x,x, x,x,x,x, T,x,T,T, T,T,T,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,x, x,x},
  {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, T,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
  {x,T,T,T, T,T,T,T, T,T,T,T, T,x,T,T, T,T,T,T, T,x,T,T, T,T,T,T, T,T,T,T, T,x,T,x, x,x,T,x, T,x,x,T, T,T,T,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
  {x,T,T,T, T,T,T,T, T,T,T,T, T,x,T,T, T,T,T,T, T,x,T,T, T,T,T,T, T,T,T,T, T,x,T,x, x,x,T,x, T,x,x,T, T,T,T,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
  {x,T,T,T, T,T,T,T, T,T,T,T, T,x,T,T, T,T,T,T, T,x,T,T, T,T,T,T, T,T,T,T, T,x,T,x, x,x,T,x, T,T,x,T, T,T,T,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
  {x,x,x,x, x,x,x,x, T,T,x,x, x,x,x,x, T,T,x,x, x,x,T,T, x,x,x,x, x,T,T,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
  {x,T,T,T, T,T,T,T, T,T,T,T, T,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,T,x, x,x,T,x, T,T,x,T, T,T,T,x, x,x,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,T,x,T, T,T,T,T, x,T,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
  {x,T,T,T, T,T,T,T, T,T,T,T, T,x,T,T, T,T,T,T, T,x,T,T, T,T,T,T, T,T,T,T, T,T,T,x, x,x,T,x, T,x,x,T, T,T,T,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x},
  {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, T,T,T,x, x,x,x,x, x,x},
  {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, T,x,x,x, x,x,x,x, x,x},
  {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,x,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x}

  };
} // end Parser


public class Errors {
  public static int count = 0;                                    // number of errors detected
  public static string errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text
  
  public static void SynErr (int line, int col, int n) {
    string s;
    switch (n) {
      case 0: s = "EOF expected"; break;
      case 1: s = "ident expected"; break;
      case 2: s = "intCon expected"; break;
      case 3: s = "realCon expected"; break;
      case 4: s = "charCon expected"; break;
      case 5: s = "stringCon expected"; break;
      case 6: s = "base expected"; break;
      case 7: s = "bool expected"; break;
      case 8: s = "byte expected"; break;
      case 9: s = "char expected"; break;
      case 10: s = "checked expected"; break;
      case 11: s = "decimal expected"; break;
      case 12: s = "double expected"; break;
      case 13: s = "event expected"; break;
      case 14: s = "false expected"; break;
      case 15: s = "float expected"; break;
      case 16: s = "int expected"; break;
      case 17: s = "long expected"; break;
      case 18: s = "new expected"; break;
      case 19: s = "null expected"; break;
      case 20: s = "object expected"; break;
      case 21: s = "return expected"; break;
      case 22: s = "sbyte expected"; break;
      case 23: s = "short expected"; break;
      case 24: s = "sizeof expected"; break;
      case 25: s = "string expected"; break;
      case 26: s = "this expected"; break;
      case 27: s = "true expected"; break;
      case 28: s = "typeof expected"; break;
      case 29: s = "uint expected"; break;
      case 30: s = "ulong expected"; break;
      case 31: s = "unchecked expected"; break;
      case 32: s = "ushort expected"; break;
      case 33: s = "void expected"; break;
      case 34: s = "and expected"; break;
      case 35: s = "assgn expected"; break;
      case 36: s = "colon expected"; break;
      case 37: s = "comma expected"; break;
      case 38: s = "dec expected"; break;
      case 39: s = "dot expected"; break;
      case 40: s = "inc expected"; break;
      case 41: s = "lbrace expected"; break;
      case 42: s = "lbrack expected"; break;
      case 43: s = "lpar expected"; break;
      case 44: s = "minus expected"; break;
      case 45: s = "not expected"; break;
      case 46: s = "plus expected"; break;
      case 47: s = "rbrace expected"; break;
      case 48: s = "rbrack expected"; break;
      case 49: s = "rpar expected"; break;
      case 50: s = "scolon expected"; break;
      case 51: s = "tilde expected"; break;
      case 52: s = "times expected"; break;
      case 53: s = "\"using\" expected"; break;
      case 54: s = "\"namespace\" expected"; break;
      case 55: s = "\"class\" expected"; break;
      case 56: s = "\"struct\" expected"; break;
      case 57: s = "\"interface\" expected"; break;
      case 58: s = "\"enum\" expected"; break;
      case 59: s = "\"delegate\" expected"; break;
      case 60: s = "\"const\" expected"; break;
      case 61: s = "\"implicit\" expected"; break;
      case 62: s = "\"explicit\" expected"; break;
      case 63: s = "\"operator\" expected"; break;
      case 64: s = "\"stackalloc\" expected"; break;
      case 65: s = "\"ref\" expected"; break;
      case 66: s = "\"out\" expected"; break;
      case 67: s = "\"params\" expected"; break;
      case 68: s = "\"public\" expected"; break;
      case 69: s = "\"protected\" expected"; break;
      case 70: s = "\"internal\" expected"; break;
      case 71: s = "\"private\" expected"; break;
      case 72: s = "\"unsafe\" expected"; break;
      case 73: s = "\"abstract\" expected"; break;
      case 74: s = "\"sealed\" expected"; break;
      case 75: s = "\"extern\" expected"; break;
      case 76: s = "\"override\" expected"; break;
      case 77: s = "\"readonly\" expected"; break;
      case 78: s = "\"static\" expected"; break;
      case 79: s = "\"virtual\" expected"; break;
      case 80: s = "\"volatile\" expected"; break;
      case 81: s = "\"if\" expected"; break;
      case 82: s = "\"else\" expected"; break;
      case 83: s = "\"switch\" expected"; break;
      case 84: s = "\"while\" expected"; break;
      case 85: s = "\"do\" expected"; break;
      case 86: s = "\"for\" expected"; break;
      case 87: s = "\"foreach\" expected"; break;
      case 88: s = "\"in\" expected"; break;
      case 89: s = "\"break\" expected"; break;
      case 90: s = "\"continue\" expected"; break;
      case 91: s = "\"throw\" expected"; break;
      case 92: s = "\"lock\" expected"; break;
      case 93: s = "\"fixed\" expected"; break;
      case 94: s = "\"+=\" expected"; break;
      case 95: s = "\"-=\" expected"; break;
      case 96: s = "\"*=\" expected"; break;
      case 97: s = "\"/=\" expected"; break;
      case 98: s = "\"%=\" expected"; break;
      case 99: s = "\"&=\" expected"; break;
      case 100: s = "\"|=\" expected"; break;
      case 101: s = "\"^=\" expected"; break;
      case 102: s = "\"<<=\" expected"; break;
      case 103: s = "\">>=\" expected"; break;
      case 104: s = "\"case\" expected"; break;
      case 105: s = "\"default\" expected"; break;
      case 106: s = "\"goto\" expected"; break;
      case 107: s = "\"try\" expected"; break;
      case 108: s = "\"finally\" expected"; break;
      case 109: s = "\"catch\" expected"; break;
      case 110: s = "\"?\" expected"; break;
      case 111: s = "\"||\" expected"; break;
      case 112: s = "\"&&\" expected"; break;
      case 113: s = "\"|\" expected"; break;
      case 114: s = "\"^\" expected"; break;
      case 115: s = "\"!=\" expected"; break;
      case 116: s = "\"==\" expected"; break;
      case 117: s = "\"<\" expected"; break;
      case 118: s = "\">\" expected"; break;
      case 119: s = "\"<=\" expected"; break;
      case 120: s = "\">=\" expected"; break;
      case 121: s = "\"is\" expected"; break;
      case 122: s = "\"as\" expected"; break;
      case 123: s = "\"<<\" expected"; break;
      case 124: s = "\">>\" expected"; break;
      case 125: s = "\"/\" expected"; break;
      case 126: s = "\"%\" expected"; break;
      case 127: s = "\"->\" expected"; break;
      case 128: s = "??? expected"; break;
      case 129: s = "invalid NamespaceMember"; break;
      case 130: s = "invalid Attributes"; break;
      case 131: s = "invalid TypeModifier"; break;
      case 132: s = "invalid TypeDecl"; break;
      case 133: s = "invalid TypeDecl"; break;
      case 134: s = "invalid InterfaceMember"; break;
      case 135: s = "invalid InterfaceMember"; break;
      case 136: s = "invalid InterfaceMember"; break;
      case 137: s = "invalid IntType"; break;
      case 138: s = "invalid Type"; break;
      case 139: s = "invalid Type"; break;
      case 140: s = "invalid FormalParams"; break;
      case 141: s = "invalid ClassType"; break;
      case 142: s = "invalid MemberModifier"; break;
      case 143: s = "invalid ClassMember"; break;
      case 144: s = "invalid ClassMember"; break;
      case 145: s = "invalid StructMember"; break;
      case 146: s = "invalid StructMember"; break;
      case 147: s = "invalid StructMember"; break;
      case 148: s = "invalid StructMember"; break;
      case 149: s = "invalid StructMember"; break;
      case 150: s = "invalid StructMember"; break;
      case 151: s = "invalid StructMember"; break;
      case 152: s = "invalid StructMember"; break;
      case 153: s = "invalid StructMember"; break;
      case 154: s = "invalid StructMember"; break;
      case 155: s = "invalid Expr"; break;
      case 156: s = "invalid EventAccessors"; break;
      case 157: s = "invalid ConstructorCall"; break;
      case 158: s = "invalid OverloadableOp"; break;
      case 159: s = "invalid Accessors"; break;
      case 160: s = "invalid InterfaceAccessors"; break;
      case 161: s = "invalid InterfaceAccessors"; break;
      case 162: s = "invalid Init"; break;
      case 163: s = "invalid LocalVar"; break;
      case 164: s = "invalid GetAccessor"; break;
      case 165: s = "invalid SetAccessor"; break;
      case 166: s = "invalid AttributeArguments"; break;
      case 167: s = "invalid SimpleType"; break;
      case 168: s = "invalid Statement"; break;
      case 169: s = "invalid EmbeddedStatement"; break;
      case 170: s = "invalid EmbeddedStatement"; break;
      case 171: s = "invalid StatementExpr"; break;
      case 172: s = "invalid ForInit"; break;
      case 173: s = "invalid GotoStatement"; break;
      case 174: s = "invalid TryStatement"; break;
      case 175: s = "invalid Resource"; break;
      case 176: s = "invalid Unary"; break;
      case 177: s = "invalid AssignOp"; break;
      case 178: s = "invalid SwitchLabel"; break;
      case 179: s = "invalid CatchClauses"; break;
      case 180: s = "invalid RelExpr"; break;
      case 181: s = "invalid RelExpr"; break;
      case 182: s = "invalid Primary"; break;
      case 183: s = "invalid Primary"; break;
      case 184: s = "invalid Primary"; break;
      case 185: s = "invalid Primary"; break;
      case 186: s = "invalid Literal"; break;

      default: s = "error " + n; break;
    }
    Console.WriteLine(Errors.errMsgFormat, line, col, s);
    count++;
  }

  public static void SemErr (int line, int col, int n) {
    Console.WriteLine(errMsgFormat, line, col, ("error " + n));
    count++;
  }

  public static void Error (int line, int col, string s) {
    Console.WriteLine(errMsgFormat, line, col, s);
    count++;
  }

  public static void Exception (string s) {
    Console.WriteLine(s); 
    System.Environment.Exit(0);
  }
} // Errors

}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.