Grammar in Coco notation (Cocol =  EBNF with semantic actions).
/*-------------------------------------------------------------------------*/
/*- Lexical grammar: character sets----------------------------------------*/
/*-------------------------------------------------------------------------*/
CHARACTERS
  letter    = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_".
  cr        = '\u000d'. /*13 = CR*/
  eol       = '\u000a'. /*10 = LF*/
  tab       = '\u0009'. /*9*/

  decimalDigit                            = "0123456789".
  hexDigit                                = decimalDigit + "ABCDEFabcdef".
  newLine                                 = cr + eol. /* Line separator character (U+2028) + Paragraph separator character (U+2029) */
  singleVerbatimStringLiteralCharacter    = ANY - '"'.
  singleRegularStringLiteralCharacter     = ANY - '"' - '\\' - newLine.
  notNumberSign                           = ANY - "#".
  singleCharacter                         = ANY - "'" - '\\' - newLine.
  inputCharacter                          = ANY - newLine.
  fileNameCharacter                       = ANY - '"' - newLine - '\u0022' .

  anyExceptNewLine                        = ANY - newLine .
  anyExceptAsterisk                       = ANY - "*" .
  anyExceptSlash                          = ANY - "/".

  ws                                      = tab + " " + '\u000b' + '\u000c' . /* Any character with Unicode class Zs*/

IGNORE eol + cr + tab

/*-------------------------------------------------------------------------*/
/*- Lexical grammar: token definitions-------------------------------------*/
/*-------------------------------------------------------------------------*/
TOKENS

literal
= /*  "true" | "false" |  "null" | moved to PrimaryExpression */
  "@\"" { singleVerbatimStringLiteralCharacter | "\"\"" } "\""
  | "\""  { singleRegularStringLiteralCharacter
          | "\\\'" | "\\\"" | "\\\\" | "\\0" | "\\a" | "\\b" | "\\f" | "\\n" | "\\r" | "\\t" | "\\v"
          | "\\x" hexDigit [hexDigit] [hexDigit] [hexDigit]
          | "\\u" hexDigit hexDigit hexDigit hexDigit
          | "\\U" hexDigit hexDigit hexDigit hexDigit hexDigit hexDigit hexDigit hexDigit
          } "\""
  | "'" (  singleCharacter
          | "\\\'" | "\\\"" | "\\\\" | "\\0" | "\\a" | "\\b" | "\\f" | "\\n" | "\\r" | "\\t" | "\\v"
          | "\\x" hexDigit [hexDigit] [hexDigit] [hexDigit]
          | "\\u" hexDigit hexDigit hexDigit hexDigit
          | "\\U" hexDigit hexDigit hexDigit hexDigit hexDigit hexDigit hexDigit hexDigit
        ) "'"
  | ("0x"|"0X") hexDigit { hexDigit } ["U" | "u" | "L" | "l" | "UL" | "Ul" | "uL" | "ul" | "LU" | "Lu" | "lU" | "lu"]
  | "." decimalDigit {decimalDigit}
      (  [ ("e"|"E") ["+"|"-"] decimalDigit {decimalDigit} ] ["F" | "f" | "D" | "d" | "M" | "m"]
        | ( "F" | "f" | "D" | "d" | "M" | "m")
      )
  | decimalDigit {decimalDigit} [ "U" | "u" | "L" | "l" | "UL" | "Ul" | "uL" | "ul" | "LU" | "Lu" | "lU" | "lu"]
  .


ident
= letter {letter | decimalDigit}.

/* Predefined types followed by "." used in PrimaryExpression via PredefinedTypeDot*/
boolDot        = "bool" "." .
byteDot        = "byte" "." .
charDot        = "char" "." .
decimalDot     = "decimal" "." .
doubleDot      = "double" "." .
floatDot       = "float" "." .
intDot         = "int" "." .
longDot        = "long" "." .
objectDot      = "object" "." .
sbyteDot       = "sbyte" "." .
shortDot       = "short" "." .
stringDot      = "string" "." .
uintDot        = "uint" "." .
ulongDot       = "ulong" "." .
ushortDot      = "ushort" "." .


/*------------------------------------------------------------------------*/
/*- Artificial LL1 tokens ------------------------------------------------*/
/*- This tokens are inserted by help functions to get a LL1 grammar.------*/
/*------------------------------------------------------------------------*/

llIdentAssignToken                                         = "²" "IdentAssign".
llIdentCommaOrAssignOrSemicolonToken                       = "²" "IdentCommaOrAssignOrSemicolon" .
llNoFinalCommaToken                                        = "²" "NoFinalComma" .
llVoidNoAsteriskToken                                      = "²" "VoidNoAsterisk" .
llCheckedOrUncheckedCurlBraceOpenToken                     = "²" "CheckedOrUncheckedCurlBraceOpen" .
llDotIdentToken                                            = "²" "DotIdent" .
llIdentColonToken                                          = "²" "IdentColon" .
llIdentBraceOpenToken                                      = "²" "IdentBraceOpen" .
llCatchBraceOpenToken                                      = "²" "CatchBraceOpen" .
llSquareBraceOpenIdentIsAssemblyToken                      = "²" "SquareBraceOpenIdentIsAssembly" .
llSquareBraceOpenCommaOrSquareBraceCloseToken              = "²" "SquareBraceOpenCommaOrSquareBraceClose" .
llQualidentNoIdentOrAsteriskOrSquareBraceOpenOptCommaToken = "²" "QualidentNoIdentOrAsteriskOrSquareBraceOpenOptComma" .
llTypeCastToken                                            = "²" "TypeCast" .
llIdentIsGetToken                                          = "²" "IdentIsGet" .
llIdentIsSetToken                                          = "²" "IdentIsSet" .
llIdentIsAddToken                                          = "²" "IdentIsAdd" .
llIdentIsRemoveToken                                       = "²" "IdentIsRemove" .
llAttributeTargetToken                                     = "²" "AttributeTarget" .

/*------------------------------------------------------------------------*/
/*- Lexical grammar: pragma definitions-----------------------------------*/
/*- pragma ... token followed by an optional semantic action--------------*/
/*------------------------------------------------------------------------*/

PRAGMAS

/*------------------------------------------------------------------------*/
/*- In case of #if, #else and #elif we removed the optional conditional  -*/
/*- section, because it is easier to jump over tokens than to create     -*/
/*- tokens while processing a pragma.                                    -*/
/*- To remove the central recursion "(" ppExpression ")" we added {"("}  -*/
/*- in front of ppExpression part and {")"} at the back, so we do not   -*/
/*- guarantee the right amount of opening and closing brackets.          -*/
/*------------------------------------------------------------------------*/
ppDirective
= "#" {ws}
  (
    ("define" | "undef") {ws} letter {letter | decimalDigit}                                                   /* ppDeclaration */
    | "if" {ws} /*ppExpression*/
      ( {"("} {ws} {"!"} {ws} {"("} {ws} ("true" | "false" | letter {letter | decimalDigit} ) {ws} {")"}       /* | "(" ppExpression ")" ... braces into rule inserted, annotation: leads to less strict rule */
          {  {ws} ("==" | "!=" | "&&" | "||") {ws}
              {"("} {ws} {"!"} {ws} {"("} {ws} ("true" | "false" | letter {letter | decimalDigit} ) {ws} {")"} /* | "(" ppExpression ")" ... braces into rule inserted, annotation: leads to less strict rule */
          }
      )
    | "elif" {ws}
      /*ppExpression*/
      ( {"("} {ws} {"!"} {ws} {"("} {ws} ("true" | "false" | letter {letter | decimalDigit} ) {ws} {")"}       /* | "(" ppExpression ")" ... braces into rule inserted, annotation: leads to less strict rule */
          {  {ws} ("==" | "!=" | "&&" | "||") {ws}
              {"("} {ws} {"!"} {ws} {"("} {ws} ("true" | "false" | letter {letter | decimalDigit} ) {ws} {")"} /* | "(" ppExpression ")" ... braces into rule inserted, annotation: leads to less strict rule */
          }
      )
    | "else"                                                                                                   /* ppElseSection */
    | "endif"                                                                                                  /* ppEndif */
    | "line" {ws} ( {decimalDigit} {ws} ['"' fileNameCharacter {fileNameCharacter} '"'] | "default" )          /* ppLine */
    | ("error" | "warning") {inputCharacter}                                                                   /* ppDiagnostic */
    | "region" {inputCharacter}                                                                                /* ppStartRegion */
    | "endregion" {inputCharacter}                                                                             /* ppEndRegion */
  )
  .

Comment
= "/*" { anyExceptAsterisk | "*" anyExceptSlash } "*/".

LineComment
= "//" { anyExceptNewLine } .

/*-------------------------------------------------------------------------*/
/*- Syntactic grammar------------------------------------------------------*/
/*-------------------------------------------------------------------------*/

PRODUCTIONS

CompilationUnit =
  { UsingDirective }                                                                             (./* Do not alter ! */ SetSquareBraceOpenIdentIsAssemblyToken(); .)
  {  llSquareBraceOpenIdentIsAssemblyToken GlobalAttributeSection                                (. /* Do not alter ! */ SetSquareBraceOpenIdentIsAssemblyToken(); .)
  }
  { NamespaceMemberDeclaration } .

UsingDirective =
                                                                                                 (. /* Do not alter ! */ string qualident; .)
  "using"                                                                                        (. /* Do not alter ! */ SetIdentAssignToken(); .)
  [ llIdentAssignToken ident "=" ] Qualident<out qualident>                                      (. /* Do not alter ! */ if (qualident!=null) { usingNamespaces.Add(qualident); } .)
  ";" .

NamespaceMemberDeclaration =
                                                                                                 (. /* Do not alter ! */Modifiers m=new Modifiers();
                                                                                                   string qualident;
                                                                                                 .)
(  "namespace" Qualident<out qualident> NamespaceBody  [ ";" ]
|  { AttributeSection } { ClassModifier<out m> } TypeDeclaration<m>
) .

GlobalAttributeSection =
  "[" ident                                                                                      (. /* Do not alter ! */ if (token.val!="assembly") { Error("assembly expected"); } .)
  /* "assembly" */ ":" Attribute                                                                 (. /* Do not alter ! */ SetNoFinalCommaToken(); .)
  { llNoFinalCommaToken "," Attribute                                                            (. /* Do not alter ! */ SetNoFinalCommaToken(); .)
  } [ "," ] "]" .

TypeDeclaration<Modifiers m> =
    (  /* check modifier: class */                                                               (. /* Do not alter ! */ m.CheckModifiers(Modifier.classes); .)
    "class" ident [ ClassBase ] ClassBody [ ";" ]
      | /* check modifier: struct interface enum delegate */                                     (. /* Do not alter ! */ m.CheckModifiers(Modifier.structsInterfacesEnumsDelegates); .)
        (  "struct" ident [ StructInterfaces ] StructBody  [ ";" ]
          |  "interface" ident [ InterfaceBase ] InterfaceBody [ ";" ]
          |  "enum" ident [ ":" IntegralType ] EnumBody [ ";" ]
          |  "delegate"                                                                          (. /* Do not alter ! */ SetVoidNoAsteriskToken(); .)
            (Type | llVoidNoAsteriskToken "void") ident "(" [ FormalParameterList ] ")" ";"
        )
    ) .

Qualident<out string qualident> =
  ident                                                                                          (. /* Do not alter ! */ qualident=token.val; .)
                                                                                                 (. /* Do not alter ! */ SetDotIdentToken(); .)
    { llDotIdentToken "."                                                                        (. /* Do not alter ! */ qualident += "."; .) 
      ident                                                                                      (. /* Do not alter ! */ qualident += token.val; .)
                                                                                                 (. /* Do not alter ! */ SetDotIdentToken(); .)
    } .

NamespaceBody =
  "{" { UsingDirective } { NamespaceMemberDeclaration } "}" .

Attribute =
                                                                                                 (. /* Do not alter ! */ string qualident; .)
  Qualident<out qualident> [ AttributeArguments ] .

ClassBase =
                                                                                                 (. /* Do not alter ! */ string qualident; .)
  ":" (Qualident<out qualident> | "object" | "string") { "," Qualident<out qualident> } .

ClassBody =
  "{" { ClassMemberDeclaration } "}" .

StructInterfaces =
                                                                                                 (. /* Do not alter ! */ string qualident; .)
  ":" Qualident<out qualident> { "," Qualident<out qualident> } .

StructBody =
                                                                                                 (. /* Do not alter ! */Modifiers m1, m2=new Modifiers();.)
  "{" { { AttributeSection } { MemberModifier<out m1>                                            (. /* Do not alter ! */ m2.AddModifier(m1.cur); .)
  } StructMemberDeclaration<m2> } "}" .

InterfaceBase =
                                                                                                 (. /* Do not alter ! */ string qualident; .)
  ":" Qualident<out qualident> { "," Qualident<out qualident> } .

InterfaceBody =
  "{"                                                                                            (. /* Do not alter ! */ SetVoidNoAsteriskToken(); .)
  { InterfaceMemberDeclaration                                                                   (. /* Do not alter ! */ SetVoidNoAsteriskToken(); .)
  } "}" .

EnumBody =
  "{" [EnumMemberDeclaration                                                                     (. /* Do not alter ! */ SetNoFinalCommaToken(); .)
  { llNoFinalCommaToken "," EnumMemberDeclaration                                                (. /* Do not alter ! */ SetNoFinalCommaToken(); .)
  } [","]] "}" .

Type =
                                                                                                 (. /* Do not alter ! */ string qualident; .)
  ( Qualident<out qualident> | SimpleType | "object" | "string" | ( "void" "*" ) )               (. /* Do not alter ! */ SetSquareBraceOpenCommaOrSquareBraceCloseToken(); .)
      {
        ( "*" | llSquareBraceOpenCommaOrSquareBraceCloseToken "[" { "," } "]"
          /* { "[" { "," } "]" covered by outer iteration} */ )                                  (. /* Do not alter ! */ SetSquareBraceOpenCommaOrSquareBraceCloseToken(); .)
      }.

FormalParameterList =
                                                                                                 (. /* Do not alter ! */ bool parameterArrayUsed=false; .)
  { AttributeSection }
    (  FixedParameter
        { "," /* check if no ParameterArray has been used before */                              (. /* Do not alter ! */
                                                                                                 if(parameterArrayUsed) { Error("ParameterArray must be at the end."); } .)
          { AttributeSection }
            (  FixedParameter
            |   /* Set Parameter usage */                                                        (. /* Do not alter ! */ parameterArrayUsed=true; .)
            ParameterArray
            )
        }
    |  ParameterArray
    ) .

AttributeArguments =
                                                                                                 (. /* Do not alter ! */  bool namedArgs=false, identFound=false; .)
  "("
    [                                                                                            (. /* Do not alter ! */ SetIdentAssignToken(); .)
      [ llIdentAssignToken                                                                       (. /* Do not alter ! */ namedArgs=true; .)
        ident "=" ] Expression
        {                                                                                        (. /* Do not alter ! */ identFound=false; .)
          ","                                                                                    (. /* Do not alter ! */ SetIdentAssignToken(); .)
          [ llIdentAssignToken                                                                   (. /* Do not alter ! */ identFound=true; .)
            ident "=" ]
                                                                                                 (. /* Do not alter ! */ if (!namedArgs && identFound) { namedArgs=true; }
                                                                                                   else if (namedArgs && ! identFound) {
                                                                                                     Error("No positionl argument after named argument.");
                                                                                                   }
                                                                                                 .)
              Expression
        }
    ]
  ")" .

ClassModifier<out Modifiers m> =
                                                                                                 (. /* Do not alter ! */ m=new Modifiers(); .)
(  "new"                                                                                         (. /* Do not alter ! */ m.AddModifier(Modifier._new); .)
|  "public"                                                                                      (. /* Do not alter ! */ m.AddModifier(Modifier._public); .)
|  "protected"                                                                                   (. /* Do not alter ! */ m.AddModifier(Modifier._protected); .)
|  "internal"                                                                                    (. /* Do not alter ! */ m.AddModifier(Modifier._internal); .)
|  "private"                                                                                     (. /* Do not alter ! */ m.AddModifier(Modifier._private); .)
|  "unsafe"                                                                                      (. /* Do not alter ! */ m.AddModifier(Modifier._unsafe); .)
|  "abstract"                                                                                    (. /* Do not alter ! */ m.AddModifier(Modifier._abstract); .)
|  "sealed"                                                                                      (. /* Do not alter ! */ m.AddModifier(Modifier._sealed); .)
) .

ClassType =
                                                                                                 (. /* Do not alter ! */ string qualident; .)
(  Qualident<out qualident>
|  "object"
|  "string"
) .

IntegralType =
(  "sbyte"
|  "byte"
|  "short"
|  "ushort"
|  "int"
|  "uint"
|  "long"
|  "ulong"
|  "char"
) .

ParameterArray =
"params" Type /* "[" { "," } "]" { "[" { "," } "]" } covered by Type  */ ident .

AttributeSection =
  "["                                                                                            (. /* Do not alter ! */ SetAttributeTargetToken(); .)
      [
        (  "event"
        | "return"
        | llAttributeTargetToken ident
          /* "field"|  "method" | "module" | "param" | "property"  | "type" */                   (. /* Do not alter ! */  if (  token.val!="field" || token.val!="method" || token.val!="module" ||
                                                                                                     token.val!="param" || token.val!="property" || token.val!="type") {
                                                                                                       Error("event, return, field, method, module, param, property or type expected");
                                                                                                     }
                                                                                                 .)
        ) ":"
      ] Attribute                                                                                (. /* Do not alter ! */ SetNoFinalCommaToken(); .)
  { llNoFinalCommaToken "," Attribute                                                            (. /* Do not alter ! */ SetNoFinalCommaToken(); .)
  } [ "," ] "]" .

ClassMemberDeclaration =
                                                                                                 (. /* Do not alter ! */Modifiers m1, m2=new Modifiers();.)
  { AttributeSection } { MemberModifier<out m1>                                                  (. /* Do not alter ! */ m2.AddModifier(m1.cur); .)
  }
    (  StructMemberDeclaration<m2>
    |  /* check modifier: destructor */                                                          (. /* Do not alter ! */ m2.CheckModifiers(Modifier.destructors); .)
      "~" ident "(" ")" ( Block | ";" )
    ).

MemberModifier<out Modifiers m> =
                                                                                                 (. /* Do not alter ! */ m=new Modifiers(); .)
(  "abstract"                                                                                    (. /* Do not alter ! */ m.AddModifier(Modifier._abstract); .)
|  "extern"                                                                                      (. /* Do not alter ! */ m.AddModifier(Modifier._extern); .)
|  "internal"                                                                                    (. /* Do not alter ! */ m.AddModifier(Modifier._internal); .)
|  "new"                                                                                         (. /* Do not alter ! */ m.AddModifier(Modifier._new); .)
|  "override"                                                                                    (. /* Do not alter ! */ m.AddModifier(Modifier._override); .)
|  "private"                                                                                     (. /* Do not alter ! */ m.AddModifier(Modifier._private); .)
|  "protected"                                                                                   (. /* Do not alter ! */ m.AddModifier(Modifier._protected); .)
|  "public"                                                                                      (. /* Do not alter ! */ m.AddModifier(Modifier._public); .)
|  "readonly"                                                                                    (. /* Do not alter ! */ m.AddModifier(Modifier._readonly); .)
|  "sealed"                                                                                      (. /* Do not alter ! */ m.AddModifier(Modifier._sealed); .)
|  "static"                                                                                      (. /* Do not alter ! */ m.AddModifier(Modifier._static); .)
|  "unsafe"                                                                                      (. /* Do not alter ! */ m.AddModifier(Modifier._unsafe); .)
|  "virtual"                                                                                     (. /* Do not alter ! */ m.AddModifier(Modifier._virtual); .)
|  "volatile"                                                                                    (. /* Do not alter ! */ m.AddModifier(Modifier._volatile); .)
) .

StructMemberDeclaration<Modifiers m> =
  (. /* Do not alter ! */  string qualident;
      Token op;
      bool binary=false;
  .)
  (. /* Do not alter ! */  SetVoidNoAsteriskToken();
      SetIdentBraceOpenToken();
  .)
  (   /* check modifier: constant */                                                             (. /* Do not alter ! */ m.CheckModifiers(Modifier.constants); .)
    "const" Type ident "=" Expression { "," ident "=" Expression } ";"

  |  /* check modifier: property event method */                                                 (. /* Do not alter ! */ m.CheckModifiers(Modifier.propertysEventsMethods); .)
    llVoidNoAsteriskToken "void" Qualident<out qualident>
      "(" [ FormalParameterList ] ")" ( Block | ";" )

  |  /* check modifier: property event method */                                                 (. /* Do not alter ! */ m.CheckModifiers(Modifier.propertysEventsMethods); .)
    "event" Type                                                                                 (. /* Do not alter ! */ SetIdentCommaOrAssignOrSemicolonToken(); .)
    (  llIdentCommaOrAssignOrSemicolonToken VariableDeclarator { "," VariableDeclarator } ";"
      |  Qualident<out qualident> "{" EventAccessorDeclarations "}"
    )

  |  /* check modifier: constructor || static constructor */                                     (. /* Do not alter ! */ m.CheckModifiers(Modifier.constructors | Modifier.staticConstructors); .)
    llIdentBraceOpenToken ident
      "(" [ /* check modifier: constructor: */                                                   (. /* Do not alter ! */ m.CheckModifiers(Modifier.constructors); .)
        FormalParameterList ] ")" [ /* check modifier: constructor: */                           (. /* Do not alter ! */ m.CheckModifiers(Modifier.constructors); .)
          ConstructorInitializer ] ( Block | ";" )

  |  /* check modifier: operator + one must be set */                                            (. /* Do not alter ! */ m.CheckModifiers(Modifier.operatiors);
                                                                                                 if (m.cur==0) {Error("One modifier must be set."); } .)
    ( "implicit" | "explicit" ) "operator" Type "(" Type ident ")" ( Block | ";" )

  |  TypeDeclaration<m>

  |  Type                                                                                        (. /* Do not alter ! */ SetIdentCommaOrAssignOrSemicolonToken(); .)
          (
            /* check modifier: operator + one must be set */                                     (. /* Do not alter ! */ m.CheckModifiers(Modifier.operatiors);
                                                                                                 if (m.cur==0) {Error("One modifier must be set."); } .)
          "operator" OverloadableOperator<out op> "(" Type ident [ /* set binary */              (. /* Do not alter ! */ binary=true; .)
            "," Type ident] /* check arity */                                                    (. /* Do not alter ! */
                                                                                                   if ((binary && !IsBinaryOperator(op)) || (!binary && !IsUnaryOperator(op))) {
                                                                                                     Error("Wrong arity of operator.");
                                                                                                   }
                                                                                                 .)
              ")" ( Block | ";" )

          | Qualident<out qualident> (
                        (  /* check modifier: property event method */                           (. /* Do not alter ! */ m.CheckModifiers(Modifier.propertysEventsMethods); .)
                          "(" [ FormalParameterList ] ")" ( Block | ";" )
                        | "{" AccessorDeclarations "}" )
                        |  /* check modifier: indexer */                                         (. /* Do not alter ! */ m.CheckModifiers(Modifier.indexers); .)
                          "." "this" "[" FormalParameterList "]" "{" AccessorDeclarations "}"
                      )
          |  /* check modifier: indexer */                                                       (. /* Do not alter ! */ m.CheckModifiers(Modifier.indexers); .)
          "this" "[" FormalParameterList "]" "{" AccessorDeclarations "}"

          |  /* check modifier: field */                                                         (. /* Do not alter ! */ m.CheckModifiers(Modifier.fields); .)
          llIdentCommaOrAssignOrSemicolonToken VariableDeclarator { "," VariableDeclarator } ";"

        )
  ) .

InterfaceMemberDeclaration =
  { AttributeSection } [ "new" ]                                                                 (. /* Do not alter ! */ SetVoidNoAsteriskToken(); .)
    (  llVoidNoAsteriskToken "void" ident "(" [ FormalParameterList ] ")" ";"
    | ( Type (
                ident (
                        "(" [ FormalParameterList ] ")" ";"
                        | "{" InterfaceAccessors "}"
                      )
                | "this" "[" FormalParameterList "]" "{" InterfaceAccessors "}"
              )
      |  "event" Type ident ";"
      )
    ) .

EnumMemberDeclaration =
  { AttributeSection } ident [ "=" Expression ] .

FixedParameter =
  [ "ref" |  "out" ] Type ident .

SimpleType =
  IntegralType
|  "float"
|  "double"
|  "decimal"
|  "bool" .

AccessorDeclarations =
  { AttributeSection }                                                                           (. /* Do not alter ! */ SetIdentIsGetTokenOrIdentIsSetToken(); .)
    (  llIdentIsGetToken GetAccessorDeclaration [ { AttributeSection } SetAccessorDeclaration ]
    |  llIdentIsSetToken SetAccessorDeclaration [ { AttributeSection } GetAccessorDeclaration ]
    ).

EventAccessorDeclarations =
  { AttributeSection }                                                                           (. /* Do not alter ! */ SetIdentIsAddTokenOrIdentIsRemoveToken(); .)
    (  llIdentIsAddToken AddAccessorDeclaration { AttributeSection } RemoveAccessorDeclaration
    |  llIdentIsRemoveToken RemoveAccessorDeclaration { AttributeSection } AddAccessorDeclaration
    ).

InterfaceAccessors =
                                                                                                 (. /* Do not alter ! */ bool wasGet=false;.)
  { AttributeSection }
    ident /* ("get" | "set") */
                                                                                                 (. /* Do not alter ! */   if (token.val=="get") {
                                                                                                       wasGet=true;
                                                                                                     } else if (token.val!="set") {
                                                                                                       Error("set or get expected");
                                                                                                     }
                                                                                                 .)
      ";" [ { AttributeSection } ident /* ("get" | "set") */
                                                                                                 (. /* Do not alter ! */   if (wasGet) {
                                                                                                       if (token.val!="set") {
                                                                                                         Error("set expected");
                                                                                                       }
                                                                                                     }
                                                                                                     else if (token.val!="get") {
                                                                                                       Error("set expected");
                                                                                                     }
                                                                                                 .)
        ";" ] .

Expression =
  UnaryExpression
  (  ConditionalExpression /* IN result of UnaryExpression */
  |  Assignment            /* IN result of UnaryExpression */
  ).

VariableDeclarator =
  ident [ "=" VariableInitializer ] .

Block =
  "{" { Statement } "}" .

GetAccessorDeclaration =
  ident /* "get" */                                                                              (. /* Do not alter ! */ if (token.val!="get") { Error("get expected"); } .)
  ( Block | ";" ) .

SetAccessorDeclaration =
  ident /* "set" */                                                                              (. /* Do not alter ! */ if (token.val!="set") { Error("set expected"); } .)
  ( Block | ";" ) .

AddAccessorDeclaration =
  ident /* "add" */                                                                              (. /* Do not alter ! */ if (token.val!="add") { Error("add expected"); } .)
  Block .

RemoveAccessorDeclaration =
  ident /* "remove" */                                                                           (. /* Do not alter ! */ if (token.val!="remove") { Error("remove expected"); } .)
  Block .

ConstructorInitializer =
  ":" ( "base" | "this" ) "(" [ Argument { "," Argument } ] ")" .

ConditionalExpression =
  ConditionalOrExpression [ "?" Expression ":" Expression ] .

Assignment =
 AssignmentOperator Expression .

VariableInitializer =
  Expression
|  ArrayInitializer
|  "stackalloc" Type "[" Expression "]" .

OverloadableOperator<out Token op> =
(  "+"
|  "-"
|  "!"
|  "~"
|  "++"
|  "--"
|  "true"
|  "false"
|  "*"
|  "/"
|  "%"
|  "&"
|  "|"
|  "^"
|  "<<"
|  ">>"
|  "=="
|  "!="
|  ">"
|  "<"
|  ">="
|  "<="
)                                                                                                (. /* Do not alter ! */ op=token; .)
.

Argument =
  [ "ref" | "out" ] Expression .

ConditionalOrExpression =
  ConditionalAndExpression { "||" UnaryExpression ConditionalAndExpression } .

UnaryExpression =
                                                                                                 (. /* Do not alter ! */ SetTypeCastToken(); .)
  {
    (   "+"
      |  "-"
      |  "!"
      |  "~"
      |  "*"
      |  "++"
      |  "--"
      |  /*  Problem: Type and Expression (from PrimaryExpression: "(" Expression ")") are not distinguishable
            Solution: use external information from compiled assembly or guess
        */
        llTypeCastToken "(" Type ")"
      |  "&"
    )
                                                                                                 (. /* Do not alter ! */ SetTypeCastToken(); .)
  } PrimaryExpression
  .

AssignmentOperator =
  "="
|  "+="
|  "-="
|  "*="
|  "/="
|  "%="
|  "&="
|  "|="
|  "^="
|  "<<="
|  ">>=" .

ArrayInitializer =
  "{" [ VariableInitializer
                                                                                                 (. /* Do not alter ! */ SetNoFinalCommaToken(); .)
  { llNoFinalCommaToken "," VariableInitializer
                                                                                                 (. /* Do not alter ! */ SetNoFinalCommaToken(); .)
  } [ "," ] ] "}" .

Statement =
(. /* Do not alter ! */  SetIdentColonToken();
    SetQualidentNoIdentOrAsteriskOrSquareBraceOpenOptCommaToken();
.)
(  llIdentColonToken ident ":" Statement
| "const" Type ident "=" Expression { "," ident "=" Expression } ";" /* LocalConstantDeclaration */
| LocalVariableDeclaration ";"
|  [ llQualidentNoIdentOrAsteriskOrSquareBraceOpenOptCommaToken ] EmbeddedStatement      /* case: ident "." {ident} { "[" Expression ... */
) .

ConditionalAndExpression =
  InclusiveOrExpression { "&&" UnaryExpression InclusiveOrExpression } .

EmbeddedStatement =
                                                                                                 (. /* Do not alter ! */ SetCheckedOrUncheckedCurlBraceOpenToken(); .)
(  Block
|  ";"
|  StatementExpression ";"
|  "if" "(" Expression ")" EmbeddedStatement [ "else" EmbeddedStatement ]
|  "switch" "(" Expression ")" "{" { SwitchSection } "}"
|  "while" "(" Expression ")" EmbeddedStatement
|  "do" EmbeddedStatement "while" "(" Expression ")" ";"
|  "for" "(" [ ForInitializer ] ";" [ Expression ] ";" [ ForIterator ] ")" EmbeddedStatement
|  "foreach" "(" Type ident "in" Expression ")" EmbeddedStatement
|  "break" ";"
|  "continue" ";"
|  GotoStatement
|  "return" [ Expression ] ";"
|  "throw" [ Expression ] ";"
|  TryStatement
|  llCheckedOrUncheckedCurlBraceOpenToken ("checked" | "unchecked") Block
|  "lock" "(" Expression ")" EmbeddedStatement
|  "using" "(" ResourceAcquisition ")" EmbeddedStatement
|  "unsafe" Block
|  "fixed" "(" Type /* check if pointer type else error */ ident "="
     /*[ "&" ]*/ Expression { "," ident "="
       /*[ "&" ]*/ Expression } ")" EmbeddedStatement
         /* ["&"] Expression => LL1 conflict, cause "&" covered by Expression, solution: remove ["&"] */
) .

InclusiveOrExpression =
  ExclusiveOrExpression { "|" UnaryExpression ExclusiveOrExpression } .

PrimaryExpression =
                                                                                                 (. /* Do not alter ! */ bool onlyDigits=true; .)
(  literal [                                                                                     (. /* Do not alter ! */
                                                                                                   foreach (char c in token.val) {
                                                                                                     onlyDigits &= Char.IsDigit(c);
                                                                                                     if (!onlyDigits) { break; }
                                                                                                   }
                                                                                                   if (onlyDigits && t.val.StartsWith(".")) {
                                                                                                     token.val += t.val;
                                                                                                     tokenNode.next=tNode.next;
                                                                                                     t=token;
                                                                                                   }
                                                                                                   else {
                                                                                                     Error("Invalid literal: " + token.val + t.val);
                                                                                                   }
                                                                                                 .)
            literal
          ]
| "true"    /* from literal */
| "false"    /* from literal */
|  "null"     /* from literal */
|  ident
|  "(" Expression ")"
|  PredefinedTypeDot ident /* from MemberAccess */
|  "this"
|  "base" (  "." ident | "[" Expression { "," Expression } "]" )
|  "new" Type (
                "(" [ Argument { "," Argument } ] ")"
                  /* Delegate-creation-expression and Object-creation-expression */
                | /* Array-creation-expression */
                  "[" (
                        Expression { "," Expression } "]"                                        (. /* Do not alter ! */ SetSquareBraceOpenCommaOrSquareBraceCloseToken(); .)
                          { llSquareBraceOpenCommaOrSquareBraceCloseToken "[" { "," } "]"        (. /* Do not alter ! */ SetSquareBraceOpenCommaOrSquareBraceCloseToken(); .)
                          } [ ArrayInitializer ]
                      |  { "," } "]"                                                             (. /* Do not alter ! */ SetSquareBraceOpenCommaOrSquareBraceCloseToken(); .)
                        { llSquareBraceOpenCommaOrSquareBraceCloseToken "[" { "," } "]"          (. /* Do not alter ! */ SetSquareBraceOpenCommaOrSquareBraceCloseToken(); .)
                        }
                      )
                | ArrayInitializer /* Array-creation-expression */
              )
|  "typeof" "("                                                                                  (. /* Do not alter ! */ SetVoidNoAsteriskToken(); .)
     ( Type | llVoidNoAsteriskToken "void" ) ")"
|  "sizeof" "(" Type ")"
|  "checked" "(" Expression ")"
|  "unchecked" "(" Expression ")"
)
{  "++"
  | "--"
  | "->" ident
  | "[" Expression { "," Expression } "]" /* from ElementAccess and ...*/
  | "." ident                             /* from MemberAccess */
  | "(" [ Argument { "," Argument } ] ")" /* from InvocationExpression */
} .

LocalVariableDeclaration =
  Type LocalVariableDeclarator { "," LocalVariableDeclarator } .

TryStatement =
  "try" Block
    (  CatchClauses [ "finally" Block ]
    |  "finally" Block
    ) .

ExclusiveOrExpression =
  AndExpression { "^" UnaryExpression AndExpression } .

StatementExpression =
  /*
    PrimaryExpression /*
      [ "(" [ Argument { "," Argument } ] ")" ] covered by primaryExpression
    */ covered by UnaryExpression
  */
                                                                                                 (. /* Do not alter ! */ bool mustBeAssignment = (t.kind==Tokens._Plus ||
                                                                                                    t.kind==Tokens._Minus || t.kind==Tokens._Not || t.kind==Tokens._Tilde ||
                                                                                                    t.kind==Tokens._Times || t.kind==Tokens._And || IsTypeCast());
                                                                                                 .)
  UnaryExpression ( Assignment |                                                                 (. /* Do not alter ! */ if (mustBeAssignment) { Error("Error in assignment."); } .)
  )
  /* covered by UnaryExpression
  |  "++" UnaryExpression
  |  "--" UnaryExpression
  */
.

GotoStatement =
  "goto"
    (  ident ";"
    |  "case" Expression ";"
    |  "default" ";"
    ) .

CatchClauses =
  "catch"
    (
      Block
      | "(" ClassType [ ident ] ")" Block                                                        (. /* Do not alter ! */ SetCatchBraceOpenToken(); .)
        {
          llCatchBraceOpenToken "catch" "(" ClassType [ ident ] ")" Block                        (. /* Do not alter ! */ SetCatchBraceOpenToken(); .)
        }
        [ "catch" Block ]
    ) .

/* LL1 Conflict problem, solution test if next is Qualident followed by ident
          -> LocalVariableDeclaration and new Problem first set of ResourceAcquisition changes !!
*/
ResourceAcquisition =
                                                                                                 (. /* Do not alter ! */SetQualidentNoIdentOrAsteriskOrSquareBraceOpenOptCommaToken(); .)
(  LocalVariableDeclaration
|  [ llQualidentNoIdentOrAsteriskOrSquareBraceOpenOptCommaToken ] Expression
) .

AndExpression =
  EqualityExpression { "&" UnaryExpression EqualityExpression } .

PredefinedTypeDot =
  boolDot
  | byteDot
  | charDot
  | decimalDot
  | doubleDot
  | floatDot
  | intDot
  | longDot
  | objectDot
  | sbyteDot
  | shortDot
  | stringDot
  | uintDot
  | ulongDot
  | ushortDot
  .

LocalVariableDeclarator =
  ident [ "=" LocalVariableInitializer ] .

ForInitializer =
                                                                                                 (. /* Do not alter ! */SetQualidentNoIdentOrAsteriskOrSquareBraceOpenOptCommaToken(); .)
(  LocalVariableDeclaration
|  [ llQualidentNoIdentOrAsteriskOrSquareBraceOpenOptCommaToken ] StatementExpression
     { "," StatementExpression }     /* case ident ";" LL1 Conflict problem */
) .

ForIterator =
  StatementExpression { "," StatementExpression } .

EqualityExpression =
  RelationalExpression  { ( "!=" | "==" ) UnaryExpression RelationalExpression } .

LocalVariableInitializer =
  Expression
|  ArrayInitializer .

RelationalExpression =
  ShiftExpression
    { ( "<" | ">" | "<=" | ">=" ) UnaryExpression ShiftExpression
    | ( "is" | "as" ) Type
    } .

SwitchSection =
  SwitchLabel { SwitchLabel } Statement { Statement } .

ShiftExpression =
  AdditiveExpression { ( "<<" | ">>" ) UnaryExpression AdditiveExpression } .

AdditiveExpression =
  MultiplicativeExpression { ( "+" | "-" ) UnaryExpression MultiplicativeExpression } .

SwitchLabel =
  "case" Expression ":"
|  "default" ":" .

MultiplicativeExpression =
  { ( "*" | "/" | "%" ) UnaryExpression } .

Help functions, used for artificial token insertion.
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
public enum Modifier {none=0, _new=1, _public=2, _protected=4, _internal=8, _private=16, constants=31, _unsafe=32,
  structsInterfacesEnumsDelegates=63, _static=64,
  _readonly=128, _volatile=256, fields=511, _virtual=512,
  _sealed=1024,  _override=2048, _abstract=4096, classes=5183, _extern=8192, destructors=8224, constructors=8254,
  staticConstructors=8288, operatiors=8290, propertysEventsMethods=15999, indexers=15935, all=16383};

public class Modifiers {
  public Modifier cur;

  public Modifiers() {
    cur=Modifier.none;
  }

  public bool AddModifier(Modifier modifier) {
    bool result=((cur&modifier)==0);
    if (result) {
      cur |= modifier;
    }
    else {
      Error("You have defined the modifier twice: " + modifier.ToString().Substring(1));
    }
    return result;
  }

  public void CheckModifiers (Modifier allowed) {
    string errorString="";
    Modifier temp = cur & (allowed ^ Modifier.all);

    for (Modifier m=Modifier._new; m<=Modifier.all; m=(Modifier)((int)m<<1)) {
      if ((temp&m)!=0) {
        errorString = errorString + (temp&m).ToString().Substring(1) + " ,";
      }
    }
    if (!errorString.Equals("")) {
      errorString = errorString.Substring(0, errorString.Length-1);
      Error("These modifieres are not allowed here: " + errorString);
    }
  }
}
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
private static bool IsUnaryOperator(Token t) {
  return (t.kind==Tokens._Plus || t.kind==Tokens._Minus || t.kind==Tokens._Not || t.kind==Tokens._PlusPlus ||
  t.kind==Tokens._MinusMinus || t.kind==Tokens._true || t.kind==Tokens._false || t.kind==Tokens._Tilde);
}
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
private static bool IsBinaryOperator(Token t) {
  return (t.kind==Tokens._Plus || t.kind==Tokens._Minus || t.kind==Tokens._Times || t.kind==Tokens._Div ||
  t.kind==Tokens._Mod || t.kind==Tokens._And || t.kind==Tokens._Or || t.kind==Tokens._Pow || t.kind==Tokens._BiggerBigger ||
  t.kind==Tokens._SmallerSmaller || t.kind==Tokens._Equals || t.kind==Tokens._NotAssign || t.kind==Tokens._Bigger ||
  t.kind==Tokens._Smaller || t.kind==Tokens._BiggerAssign || t.kind==Tokens._SmallerAssign);
}
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
private static void SetIdentAssignToken() {
  Token ll1Token;

  if (t.kind==Tokens._ident) {
    StartPeek();
    Get();
    if (t.kind==Tokens._Assign) {
      ll1Token=new Token();
      ll1Token.val="IdentAssignToken";
      ll1Token.kind=Tokens._llIdentAssignToken;
    }
    else {
      ll1Token=null;
    }
    ClosePeek(ll1Token);
  }
}
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
private static void SetIdentCommaOrAssignOrSemicolonToken() {
  Token ll1Token;

  if (t.kind==Tokens._ident) {
    StartPeek();
    Get();
    if (t.kind==Tokens._Assign || t.kind==Tokens._Comma || t.kind==Tokens._Semicolon) {
      ll1Token=new Token();
      ll1Token.val="CommaOrAssignOrSemicolonToken";
      ll1Token.kind=Tokens._llIdentCommaOrAssignOrSemicolonToken;
    }
    else {
      ll1Token=null;
    }
    ClosePeek(ll1Token);
  }
}
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
private static void SetNoFinalCommaToken() {
  Token ll1Token;

  if (t.kind==Tokens._Comma) {
    StartPeek();
    Get();
    if (t.kind != Tokens._CurlBraceClose && t.kind != Tokens._SquareBraceClose) {
      ll1Token=new Token();
      ll1Token.val="NoFinalCommaToken";
      ll1Token.kind=Tokens._llNoFinalCommaToken;
    }
    else {
      ll1Token=null;
    }
    ClosePeek(ll1Token);
  }
}
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
private static void SetVoidNoAsteriskToken() {
  Token ll1Token;

  if (t.kind==Tokens._void) {
    StartPeek();
    Get();
    if (t.kind!=Tokens._Times) {
      ll1Token=new Token();
      ll1Token.val="VoidNoAsteriskToken";
      ll1Token.kind=Tokens._llVoidNoAsteriskToken;
    }
    else {
      ll1Token=null;
    }
    ClosePeek(ll1Token);
  }
}
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
private static void SetCheckedOrUncheckedCurlBraceOpenToken() {
  Token ll1Token;

  if (t.kind==Tokens._checked || t.kind==Tokens._unchecked) {
    StartPeek();
    Get();
    if (t.kind!=Tokens._CurlBraceOpen) {
      ll1Token=new Token();
      ll1Token.val="CheckedOrUncheckedCurlBraceOpenToken";
      ll1Token.kind=Tokens._llCheckedOrUncheckedCurlBraceOpenToken;
    }
    else {
      ll1Token=null;
    }
    ClosePeek(ll1Token);
  }
}
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
private static void SetDotIdentToken() {
  Token ll1Token;

  if (t.kind==Tokens._Dot) {
    StartPeek();
    Get();
    if (t.kind==Tokens._ident) {
      ll1Token=new Token();
      ll1Token.val="DotIdentToken";
      ll1Token.kind=Tokens._llDotIdentToken;
    }
    else {
      ll1Token=null;
    }
    ClosePeek(ll1Token);
  }
}
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
private static void SetIdentColonToken() {
  Token ll1Token;

  if (t.kind==Tokens._ident) {
    StartPeek();
    Get();
    if (t.kind==Tokens._Colon) {
      ll1Token=new Token();
      ll1Token.val="IdentColonToken";
      ll1Token.kind=Tokens._llIdentColonToken;
    }
    else {
      ll1Token=null;
    }
    ClosePeek(ll1Token);
  }
}
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
private static void SetIdentBraceOpenToken() {
  Token ll1Token;

  if (t.kind==Tokens._ident) {
    StartPeek();
    Get();
    if (t.kind==Tokens._BraceOpen) {
      ll1Token=new Token();
      ll1Token.val="IdentBraceOpenToken";
      ll1Token.kind=Tokens._llIdentBraceOpenToken;
    }
    else {
      ll1Token=null;
    }
    ClosePeek(ll1Token);
  }
}
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
private static void SetCatchBraceOpenToken() {
  Token ll1Token;

  if (t.kind==Tokens._catch) {
    StartPeek();
    Get();
    if (t.kind==Tokens._BraceOpen) {
      ll1Token=new Token();
      ll1Token.val="CatchBraceOpenToken";
      ll1Token.kind=Tokens._llCatchBraceOpenToken;
    }
    else {
      ll1Token=null;
    }
    ClosePeek(ll1Token);
  }
}
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
private static void SetSquareBraceOpenIdentIsAssemblyToken() {
  Token ll1Token;

  if (t.kind==Tokens._SquareBraceOpen) {
    StartPeek();
    Get();
    if (t.kind==Tokens._ident && t.val=="assembly") {
      ll1Token=new Token();
      ll1Token.val="SquareBraceOpenIdentIsAssemblyToken";
      ll1Token.kind=Tokens._llSquareBraceOpenIdentIsAssemblyToken;
    }
    else {
      ll1Token=null;
    }
    ClosePeek(ll1Token);
  }
}
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
private static void SetSquareBraceOpenCommaOrSquareBraceCloseToken() {
  Token ll1Token;

  if (t.kind==Tokens._SquareBraceOpen) {
    StartPeek();
    Get();
    if (t.kind==Tokens._Comma || t.kind==Tokens._SquareBraceClose) {
      ll1Token=new Token();
      ll1Token.val="SquareBraceOpenCommaOrSquareBraceCloseToken";
      ll1Token.kind=Tokens._llSquareBraceOpenCommaOrSquareBraceCloseToken;
    }
    else {
      ll1Token=null;
    }
    ClosePeek(ll1Token);
  }
}
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
private static void SetQualidentNoIdentOrAsteriskOrSquareBraceOpenOptCommaToken() {
  Token ll1Token=null;
  bool isQualident=true;

  if (t.kind==Tokens._ident) {
    StartPeek();
    Get();
    while(t.kind==Tokens._Dot){
      Get(); // ident
      if (t.kind!=Tokens._ident) {
        isQualident=false;
        break;
      }
      Get();
    }

    if (isQualident && (t.kind!=Tokens._ident) && (t.kind!=Tokens._SquareBraceOpen) && (t.kind!=Tokens._Times)) {
      ll1Token=new Token();
      ll1Token.val="QualidentNoIdentOrAsteriskOrSquareBraceOpenOptCommaToken";
      ll1Token.kind=Tokens._llQualidentNoIdentOrAsteriskOrSquareBraceOpenOptCommaToken;
    }
    else if (isQualident && (t.kind==Tokens._SquareBraceOpen)) {
      Get();
      if ((t.kind!=Tokens._Comma) && (t.kind!=Tokens._SquareBraceClose)) {
        ll1Token=new Token();
        ll1Token.val="QualidentNoIdentOrAsteriskOrSquareBraceOpenOptCommaToken";
        ll1Token.kind=Tokens._llQualidentNoIdentOrAsteriskOrSquareBraceOpenOptCommaToken;
      }
    }
    ClosePeek(ll1Token);
  }
}
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
private static void CreateTypeStrings(string assemblyName) {
  Assembly a;
  Type[] types;
  AssemblyName [] assemblyNames;
  int curAssembly=0;

  if (assemblyName!=null) {
    typeStrings=new Hashtable();
    a = Assembly.LoadFrom(assemblyName);
    types = a.GetTypes();
    foreach(Type t in types) { typeStrings.Add(t.FullName.GetHashCode(), t.FullName); }
    assemblyNames = a.GetReferencedAssemblies();

    while (curAssembly < assemblyNames.Length) {
      a = Assembly.LoadFrom(assemblyNames[curAssembly].Name);
      ++curAssembly;
      types = a.GetExportedTypes();

      foreach(Type t in types) {
        if (usingNamespaces.Contains(t.FullName.Substring(0, t.FullName.LastIndexOf('.')))) {
          typeStrings.Add(t.FullName.GetHashCode(), t.FullName);
        }
      }
    }
  }
}
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
private static bool GuessTypeCast() {
  Token saveToken;
  bool isQualident=true;
  bool result=false;

  if (t.kind==Tokens._BraceOpen) {
    StartPeek();
    Get();
    if (t.kind==Tokens._ident) {
      Get();
      while(t.kind==Tokens._Dot){
        Get(); // ident
        if (t.kind!=Tokens._ident) {
          isQualident=false;
          break;
        }
        Get();
      }
      if (isQualident) {
        while(t.kind==Tokens._Times || t.kind==Tokens._SquareBraceOpen) {
          if (t.kind==Tokens._SquareBraceOpen) {
            Get();
            while(t.kind==Tokens._Comma) {
              Get();
            }
            if (t.kind!=Tokens._SquareBraceClose) {
              break;
            }
          }
          Get();
        }
      }
      saveToken=t;
      Get();
      result = (isQualident && saveToken.kind==Tokens._BraceClose &&
      (t.kind==Tokens._literal || t.kind==Tokens._BraceOpen || t.kind==Tokens._Minus || t.kind==Tokens._Plus ||
      t.kind==Tokens._PlusPlus || t.kind==Tokens._MinusMinus || t.kind==Tokens._Not || t.kind==Tokens._Tilde ||
      t.kind==Tokens._boolDot || t.kind==Tokens._byteDot || t.kind==Tokens._charDot || t.kind==Tokens._decimalDot ||
      t.kind==Tokens._floatDot || t.kind==Tokens._intDot || t.kind==Tokens._longDot || t.kind==Tokens._objectDot ||
      t.kind==Tokens._sbyteDot || t.kind==Tokens._shortDot || t.kind==Tokens._stringDot || t.kind==Tokens._uintDot ||
      t.kind==Tokens._ulongDot || t.kind==Tokens._ushortDot || t.kind==Tokens._new || t.kind==Tokens._this ||
      t.kind==Tokens._base || t.kind==Tokens._true || t.kind==Tokens._false || t.kind==Tokens._checked ||
      t.kind==Tokens._unchecked || t.kind==Tokens._null ||  t.kind==Tokens._doubleDot ||
      t.kind==Tokens._ident || t.kind==Tokens._typeof || t.kind==Tokens._sizeof));
    }
    else if (t.kind==Tokens._sbyte || t.kind==Tokens._byte || t.kind==Tokens._short || t.kind==Tokens._ushort ||
            t.kind==Tokens._int || t.kind==Tokens._uint || t.kind==Tokens._long || t.kind==Tokens._ulong ||
            t.kind==Tokens._object || t.kind==Tokens._string || t.kind==Tokens._decimal || t.kind==Tokens._float ||
            t.kind==Tokens._char || t.kind==Tokens._double || t.kind==Tokens._bool)
    {
      Get();
      while(t.kind==Tokens._Times || t.kind==Tokens._SquareBraceOpen) {
        if (t.kind==Tokens._SquareBraceOpen) {
          Get();
          while(t.kind==Tokens._Comma) {
            Get();
          }
          if (t.kind!=Tokens._SquareBraceClose) {
            break;
          }
        }
        Get();
      }
      result = (t.kind==Tokens._BraceClose);
    }
    ClosePeek(null);
  }

  return result;
}
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
private static bool IsType(string qualident) {
  bool result;
  int cur=0;

  result = typeStrings.ContainsValue(qualident);

  while (!result && cur<usingNamespaces.Count) {
    result = typeStrings.ContainsValue(usingNamespaces[cur] + "." + qualident);
    ++cur;
  }

  return result;
}
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
private static bool CheckTypeCast() {
  string qualident;
  bool isQualident=true;
  bool result = false;

  if (t.kind==Tokens._BraceOpen) {
    StartPeek();
    Get();
    if (t.kind==Tokens._ident) {
      qualident=t.val;
      Get();
      while(t.kind==Tokens._Dot) {
        Get();
        if (t.kind==Tokens._ident) {
          qualident = qualident + "." + t.val;
        }
        else {
          isQualident=false;
        }
        Get();
      }
      while(t.kind==Tokens._Times || t.kind==Tokens._SquareBraceOpen) {
        if (t.kind==Tokens._SquareBraceOpen) {
          Get();
          while(t.kind==Tokens._Comma) {
            Get();
          }
          if (t.kind!=Tokens._SquareBraceClose) {
            break;
          }
        }
        Get();
      }
      result = (isQualident && (t.kind==Tokens._BraceClose) && IsType(qualident));
    }
    ClosePeek(null);
  }

  return result;
}
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
private static bool IsTypeCast() {
  bool result=false;

  if (assemblyName==null) {
    result = GuessTypeCast();
  }
  else if (typeStrings==null) {
    CreateTypeStrings(assemblyName);
    result = CheckTypeCast();
  }

  return result;
}
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
private static void SetTypeCastToken() { // "(" Type ")" .
  Token ll1Token;

  if (IsTypeCast()) {
    ll1Token=new Token();
    ll1Token.val="TypeCastToken";
    ll1Token.kind=Tokens._llTypeCastToken;
    StartPeek();
    ClosePeek(ll1Token);
  }
}
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
private static void SetIdentIsGetTokenOrIdentIsSetToken() {
  Token ll1Token=null;

  if (t.kind==Tokens._ident) {
    StartPeek();
    if (t.val=="get") {
      ll1Token=new Token();
      ll1Token.val="IdentIsGetToken";
      ll1Token.kind=Tokens._llIdentIsGetToken;
    }
    else if (t.val=="set") {
      ll1Token=new Token();
      ll1Token.val="IdentIsSetToken";
      ll1Token.kind=Tokens._llIdentIsSetToken;
    }
    ClosePeek(ll1Token);
  }
}
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
private static void SetIdentIsAddTokenOrIdentIsRemoveToken() {
  Token ll1Token=null;

  if (t.kind==Tokens._ident) {
    StartPeek();
    if (t.val=="add") {
      ll1Token=new Token();
      ll1Token.val="IdentIsAddToken";
      ll1Token.kind=Tokens._llIdentIsAddToken;
    }
    else if (t.val=="remove") {
      ll1Token=new Token();
      ll1Token.val="IdentIsRemoveToken";
      ll1Token.kind=Tokens._llIdentIsRemoveToken;
    }
    ClosePeek(ll1Token);
  }
}
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
private static void SetAttributeTargetToken() {
  Token ll1Token=null;

  if (t.kind==Tokens._ident && (t.val=="field" || t.val=="method" || t.val=="module" ||
      t.val=="param" || t.val=="property" || t.val=="type")) {
    StartPeek();
    Get();
    if (t.kind==Tokens._Colon) {
      ll1Token=new Token();
      ll1Token.val="AttributeTargetToken";
      ll1Token.kind=Tokens._llAttributeTargetToken;
    }
    ClosePeek(ll1Token);
  }
}