public static void createCodeChunk(TES4VariableDeclarationList chunk, TES5CodeScope codeScope)
 {
     foreach (TES4VariableDeclaration variable in chunk.getVariableList())
     {
         TES4Type          variableType = variable.VariableType;
         TES5LocalVariable property;
         if (variableType == TES4Type.T_FLOAT)
         {
             property = new TES5LocalVariable(variable.VariableName, TES5BasicType.T_FLOAT);
         }
         else if (variableType == TES4Type.T_INT || variableType == TES4Type.T_SHORT || variableType == TES4Type.T_LONG)
         {
             property = new TES5LocalVariable(variable.VariableName, TES5BasicType.T_INT);
         }
         else if (variableType == TES4Type.T_REF)
         {
             //most basic one, if something from inherited class is used, we will set to the inheriting class
             property = new TES5LocalVariable(variable.VariableName, TES5BasicType.T_FORM);
         }
         else
         {
             throw new ConversionException("Unknown local variable declaration type.");
         }
         codeScope.LocalScope.AddVariable(property);
     }
 }
Beispiel #2
0
 public readonly TES5BasicType?TES5Type; //WTM:  Change:  Added
 public TES4VariableDeclaration(string variableName, TES4Type variableType, Nullable <int> formID = null, TES5BasicType?tes5Type = null)
 {
     this.VariableName = variableName;
     this.VariableType = variableType;
     FormID            = formID;
     TES5Type          = tes5Type;
 }
        public static ITES5Primitive createValue(ITES4Primitive value)
        {
            TES4Type valueType = value.Type;
            object   valueData = value.Data;

            if (valueType == TES4Type.T_INT)
            {
                return(new TES5Integer((int)valueData));
            }
            else if (valueType == TES4Type.T_STRING)
            {
                return(new TES5String((string)valueData));
            }
            else if (valueType == TES4Type.T_FLOAT)
            {
                return(new TES5Float((float)valueData));
            }
            throw new ConversionException("Unknown value type to be factored from " + value.GetType().FullName);
        }
Beispiel #4
0
        private TES5Property CreateProperty(TES4VariableDeclaration variable, TES5GlobalVariables globalVariables)
        {
            string   variableName = variable.VariableName;
            TES4Type variableType = variable.VariableType;

            if (variableType == TES4Type.T_FLOAT)
            {
                return(ConstructWithoutFormID(variableName, TES5BasicType.T_FLOAT, null));
            }
            if (variableType == TES4Type.T_INT || variableType == TES4Type.T_SHORT || variableType == TES4Type.T_LONG)
            {
                return(ConstructWithoutFormID(variableName, TES5BasicType.T_INT, null));
            }
            if (variableType == TES4Type.T_REF)
            {
                return(CreatePropertyFromReference(variable, globalVariables));
            }
            throw new ConversionException("Unknown variable declaration type.");
        }
        /*
         * @throws ConversionException
         */
        public static void CreateProperties(TES4VariableDeclarationList variableList, TES5GlobalScope globalScope, TES5GlobalVariables globalVariables)
        {
            Dictionary <string, TES4VariableDeclaration> alreadyDefinedVariables = new Dictionary <string, TES4VariableDeclaration>();

            foreach (TES4VariableDeclaration variable in variableList.getVariableList())
            {
                string   variableName      = variable.VariableName;
                string   variableNameLower = variableName.ToLower();
                TES4Type variableType      = variable.VariableType;
                TES4VariableDeclaration alreadyDefinedVariable;
                if (alreadyDefinedVariables.TryGetValue(variableNameLower, out alreadyDefinedVariable))
                {
                    if (variableType == alreadyDefinedVariable.VariableType)
                    {
                        continue; //Same variable defined twice, smack the original script developer and fallthrough silently.
                    }
                    throw new ConversionException("Double definition of variable named " + variableName + " with different types ( " + alreadyDefinedVariables[variableNameLower].VariableType.Name + " and " + variable.VariableType.Name + " )");
                }

                TES5Property property;
                if (variableType == TES4Type.T_FLOAT)
                {
                    property = new TES5Property(variable.VariableName, TES5BasicType.T_FLOAT, null);
                }
                else if (variableType == TES4Type.T_INT || variableType == TES4Type.T_SHORT || variableType == TES4Type.T_LONG)
                {
                    property = new TES5Property(variable.VariableName, TES5BasicType.T_INT, null);
                }
                else if (variableType == TES4Type.T_REF)
                {
                    property = CreatePropertyFromReference(variable, globalVariables);
                }
                else
                {
                    throw new ConversionException("Unknown variable declaration type.");
                }

                globalScope.AddProperty(property);
                alreadyDefinedVariables.Add(variableNameLower, variable);
            }
        }
Beispiel #6
0
        /*
         * @throws ConversionException
         */
        public void CreateAndAddProperties(TES4VariableDeclarationList variableList, TES5GlobalScope globalScope, TES5GlobalVariables globalVariables)
        {
            Dictionary <string, TES4VariableDeclaration> alreadyDefinedVariables = new Dictionary <string, TES4VariableDeclaration>();

            foreach (TES4VariableDeclaration variable in variableList.VariableList)
            {
                string   variableName      = variable.VariableName;
                string   variableNameLower = variableName.ToLower();
                TES4Type variableType      = variable.VariableType;
                TES4VariableDeclaration?alreadyDefinedVariable;
                if (alreadyDefinedVariables.TryGetValue(variableNameLower, out alreadyDefinedVariable))
                {
                    if (variableType == alreadyDefinedVariable.VariableType)
                    {
                        continue; //Same variable defined twice, smack the original script developer and fallthrough silently.
                    }
                    throw GetDuplicatePropertyException(variableName, alreadyDefinedVariable.VariableType.Name, variable.VariableType.Name);
                }

                CreateAndAddProperty(variable, globalScope, globalVariables);
                alreadyDefinedVariables.Add(variableNameLower, variable);
            }
        }
        protected void createObscriptCodeParsingTree()
        {
            __invoke("Code+").Is("Code+", "Code").Call((TES4CodeChunks list, ITES4CodeChunk codeDeclaration) =>
            {
                list.Add(codeDeclaration);
                return(list);
            }).
            Is("Code").Call((ITES4CodeChunk codeDeclaration) =>
            {
                TES4CodeChunks list = new TES4CodeChunks();
                list.Add(codeDeclaration);
                return(list);
            });
            __invoke("Code").Is("Branch").Is("SetValue", "NWL").Is("Function", "NWL").Is("ObjectCall", "NWL").Is("LocalVariableDeclaration+").Is("Return");
//todo-THIS should be fixed on lexer level, right now it ignores NWL after the return
            __invoke("LocalVariableDeclaration+").Is("LocalVariableDeclaration+", "LocalVariableDeclaration").Call((TES4VariableDeclarationList list, TES4VariableDeclaration variableDeclaration) =>
            {
                list.add(variableDeclaration);
                return(list);
            }).

            Is("LocalVariableDeclaration").Call((TES4VariableDeclaration variableDeclaration) =>
            {
                TES4VariableDeclarationList list = new TES4VariableDeclarationList();
                list.add(variableDeclaration);
                return(list);
            })

            ;
            __invoke("LocalVariableDeclaration").Is("LocalVariableDeclarationType", "VariableName").Call((System.Func <CommonToken, CommonToken, TES4VariableDeclaration>)((CommonToken variableDeclarationType, CommonToken variableName) =>
            {
                return(new TES4VariableDeclaration((string)variableName.Value, TES4Type.GetFirst((string)variableDeclarationType.Value.ToLower())));
            }))

            ;
            __invoke("Branch").Is("BranchStart", "BranchEndToken") //If a == 2 { doSomeCode(); endIf
            .Call((TES4SubBranch branchStart, object end) =>
            {
                return(new TES4Branch(branchStart, null, null));
            }).

            Is("BranchStart", "BranchSubBranch+", "BranchEndToken") //If a == 2 { doSomeCode(); endIf
            .Call((TES4SubBranch branchStart, TES4SubBranchList subbranches, object end) =>
            {
                return(new TES4Branch(branchStart, subbranches, null));
            }).

            Is("BranchStart", "BranchElse", "BranchEndToken") //If a == 2 { doSomeCode(); endIf
            .Call((TES4SubBranch branchStart, TES4ElseSubBranch branchElse, object end) =>
            {
                return(new TES4Branch(branchStart, null, branchElse));
            }).

            Is("BranchStart", "BranchSubBranch+", "BranchElse", "BranchEndToken").Call((TES4SubBranch branchStart, TES4SubBranchList subbranches, TES4ElseSubBranch branchElse, object end) =>
            {
                return(new TES4Branch(branchStart, subbranches, branchElse));
            })

            ;
            __invoke("BranchElse").Is("BranchElseToken", "Code+").Call((object branchElseToken, TES4CodeChunks code) =>
            {
                return(new TES4ElseSubBranch(code));
            }).

            Is("BranchElseToken").Call((branchElseToken) =>
            {
                return(new TES4ElseSubBranch(null));
            })

            ;
            __invoke("BranchStart").Is("BranchStartToken", "Value", "NWL", "Code+").Call((object branchStart, ITES4Value expression, object newLine, TES4CodeChunks code) =>
            {
                return(new TES4SubBranch(expression, code));
            }).

            Is("BranchStartToken", "Value", "NWL").Call((object branchStart, ITES4Value expression, object newLine) =>
            {
                return(new TES4SubBranch(expression, null));
            })

            ;
            __invoke("BranchSubBranch+").Is("BranchSubBranch+", "BranchSubBranch").Call((TES4SubBranchList list, TES4SubBranch branchSubBranchDeclaration) =>
            {
                list.Add(branchSubBranchDeclaration);
                return(list);
            }).

            Is("BranchSubBranch").Call((TES4SubBranch branchSubBranchDeclaration) =>
            {
                TES4SubBranchList list = new TES4SubBranchList();
                list.Add(branchSubBranchDeclaration);
                return(list);
            })

            ;
            __invoke("BranchSubBranch").Is("BranchElseifToken", "Value", "NWL", "Code+").Call((object branchElseif, ITES4Value expression, object nwl, TES4CodeChunks codeChunks) =>
            {
                return(new TES4SubBranch(expression, codeChunks));
            }).

            Is("BranchElseifToken", "Value", "NWL").Call((object branchElseif, ITES4Value expression, object nwl) =>
            {
                return(new TES4SubBranch(expression, null));
            })

            ;
            __invoke("MathOperator").Is("==").Call((System.Func <CommonToken, TES4ComparisonExpressionOperator>)((CommonToken op) =>
            {
                return(TES4ComparisonExpressionOperator.GetFirst((string)op.Value));
            })).

            Is("!=").Call((System.Func <CommonToken, TES4ComparisonExpressionOperator>)((CommonToken op) =>
            {
                return(TES4ComparisonExpressionOperator.GetFirst((string)op.Value));
            })).

            Is(">").Call((System.Func <CommonToken, TES4ComparisonExpressionOperator>)((CommonToken op) =>
            {
                return(TES4ComparisonExpressionOperator.GetFirst((string)op.Value));
            })).

            Is("<").Call((System.Func <CommonToken, TES4ComparisonExpressionOperator>)((CommonToken op) =>
            {
                return(TES4ComparisonExpressionOperator.GetFirst((string)op.Value));
            })).

            Is("<=").Call((System.Func <CommonToken, TES4ComparisonExpressionOperator>)((CommonToken op) =>
            {
                return(TES4ComparisonExpressionOperator.GetFirst((string)op.Value));
            })).

            Is(">=").Call((System.Func <CommonToken, TES4ComparisonExpressionOperator>)((CommonToken op) =>
            {
                return(TES4ComparisonExpressionOperator.GetFirst((string)op.Value));
            }))

            ;
            __invoke("LogicalOperator").Is("||").Call((System.Func <CommonToken, TES4LogicalExpressionOperator>)((CommonToken op) =>
            {
                return(TES4LogicalExpressionOperator.GetFirst((string)op.Value));
            })).

            Is("&&").Call((System.Func <CommonToken, TES4LogicalExpressionOperator>)((CommonToken op) =>
            {
                return(TES4LogicalExpressionOperator.GetFirst((string)op.Value));
            }))

            ;
            __invoke("Value").Is("Value", "LogicalOperator", "NotLogicalValue").Call((ITES4Value left, TES4LogicalExpressionOperator op, ITES4Value right) =>
            {
                return(new TES4LogicalExpression(left, op, right));
            }).

            Is("NotLogicalValue");
            __invoke("NotLogicalValue").Is("NotLogicalValue", "MathOperator", "NotLogicalAndBinaryValue").Call((ITES4Value left, TES4ComparisonExpressionOperator op, ITES4Value right) =>
            {
                return(new TES4ComparisonExpression(left, op, right));
            }).

            Is("NotLogicalAndBinaryValue");
            __invoke("NotLogicalAndBinaryValue").Is("NotLogicalAndBinaryValue", "BinaryOperator", "NonExpressionValue").Call((ITES4Value left, TES4ArithmeticExpressionOperator op, ITES4Value right) =>
            {
                return(new TES4ArithmeticExpression(left, op, right));
            }).

            Is("NonExpressionValue");
            __invoke("NonExpressionValue").Is("ObjectAccess").Is("Function").Is("APIToken").Is("Primitive");
            __invoke("BinaryOperator").Is("+").Call((System.Func <CommonToken, TES4ArithmeticExpressionOperator>)((CommonToken op) =>
            {
                return(TES4ArithmeticExpressionOperator.GetFirst((string)op.Value));
            })).

            Is("-").Call((System.Func <CommonToken, TES4ArithmeticExpressionOperator>)((CommonToken op) =>
            {
                return(TES4ArithmeticExpressionOperator.GetFirst((string)op.Value));
            })).

            Is("*").Call((System.Func <CommonToken, TES4ArithmeticExpressionOperator>)((CommonToken op) =>
            {
                return(TES4ArithmeticExpressionOperator.GetFirst((string)op.Value));
            })).

            Is("/").Call((System.Func <CommonToken, TES4ArithmeticExpressionOperator>)((CommonToken op) =>
            {
                return(TES4ArithmeticExpressionOperator.GetFirst((string)op.Value));
            }))

            ;
            __invoke("ObjectAccess").Is("ObjectCall").Is("ObjectProperty");
            __invoke("ObjectCall").Is("APIToken", "TokenDelimiter", "Function").Call((TES4ApiToken apiToken, object delimiter, TES4Function function) =>
            {
                return(new TES4ObjectCall(apiToken, function));
            })

            ;
            __invoke("ObjectProperty").Is("APIToken", "TokenDelimiter", "APIToken").Call((TES4ApiToken apiToken, object delimiter, TES4ApiToken nextApiToken) =>
            {
                return(new TES4ObjectProperty(apiToken, nextApiToken));
            })

            ;
            __invoke("SetValue").Is("SetInitialization", "ObjectProperty", "Value").Call((object setInitialization, TES4ObjectProperty objectProperty, ITES4Value expression) =>
            {
                return(new TES4VariableAssignation(objectProperty, expression));
            }).

            Is("SetInitialization", "APIToken", "Value").Call((object setInitialization, TES4ApiToken apiToken, ITES4Value expression) =>
            {
                return(new TES4VariableAssignation(apiToken, expression));
            })

            ;
            __invoke("Function").Is("FunctionCall", "FunctionArguments").Call((TES4FunctionCall functionCall, TES4FunctionArguments functionArguments) =>
            {
                return(new TES4Function(functionCall, functionArguments));
            }).

            Is("FunctionCall").Call((TES4FunctionCall functionCall) =>
            {
                return(new TES4Function(functionCall, new TES4FunctionArguments()));
            })

            ;
            __invoke("FunctionCall").Is("FunctionCallToken").Call((System.Func <CommonToken, TES4FunctionCall>)((CommonToken functionCall) =>
            {
                return(new TES4FunctionCall((string)functionCall.Value));
            }))

            ;
            __invoke("APIToken").Is("ReferenceToken").Call((System.Func <CommonToken, TES4ApiToken>)((CommonToken token) =>
            {
                return(new TES4ApiToken((string)token.Value));
            }))

            ;
            __invoke("FunctionArguments").Is("FunctionArguments", "FunctionParameter").Call((TES4FunctionArguments list, ITES4StringValue value) =>
            {
                list.Add(value);
                return(list);
            }).

            Is("FunctionParameter").Call((ITES4StringValue value) =>
            {
                TES4FunctionArguments list = new TES4FunctionArguments();
                list.Add(value);
                return(list);
            })

            ;
            __invoke("FunctionParameter").Is("ObjectAccess").Is("Function").Is("APIToken").Is("Primitive");
            __invoke("Primitive").Is("Float").Call((System.Func <CommonToken, TES4Float>)((CommonToken fl) =>
            {
                string floatValue = fl.Value;
                if (floatValue.StartsWith("."))
                {
                    floatValue = "0" + floatValue;
                }

                return(new TES4Float(float.Parse(floatValue)));
            })).

            Is("Integer").Call((System.Func <CommonToken, TES4Integer>)((CommonToken token) =>
            {
                return(new TES4Integer(int.Parse((string)token.Value)));
            })).

            Is("Boolean").Call((System.Func <CommonToken, TES4Integer>)((CommonToken token) =>
            {
                if (token.Value.ToLower() == "true")
                {
                    return(new TES4Integer(1));
                }
                return(new TES4Integer(0));
            })).

            Is("String").Call((System.Func <CommonToken, TES4String>)((CommonToken str) =>
            {
                return(new TES4String((string)str.Value));
            }))

            ;
            __invoke("Return").Is("ReturnToken", "NWL").Call((object returnToken, object nwl) =>
            {
                return(new TES4Return());
            }).

            Is("ReturnToken").Call((returnToken) =>
            {
                return(new TES4Return());
            })

            ;
        }
 public TES4VariableDeclaration(string variableName, TES4Type variableType)
 {
     this.VariableName = PapyrusCompiler.FixReferenceName(variableName);
     this.VariableType = variableType;
 }
Beispiel #9
0
        public TES4OBScriptGrammar()
            : base(false)
        {
            __invoke("Script").Is("ScriptHeader", "Block+").Call((TES4ScriptHeader header, TES4BlockList blockList) =>
            {
                return(new TES4Script(header, null, blockList));
            }).

            Is("ScriptHeader", "VariableDeclaration+").Call((TES4ScriptHeader header, TES4VariableDeclarationList variableList) =>
            {
                return(new TES4Script(header, variableList, null));
            }).

            Is("ScriptHeader", "VariableDeclaration+", "Block+").Call((TES4ScriptHeader header, TES4VariableDeclarationList variableList, TES4BlockList blockList) =>
            {
                return(new TES4Script(header, variableList, blockList));
            })

            ;
            __invoke("ScriptHeader").Is("ScriptHeaderToken", "ScriptName").Call((System.Func <object, CommonToken, TES4ScriptHeader>)((object headerToken, CommonToken scriptName) =>
            {
                return(new TES4ScriptHeader((string)scriptName.Value));
            }))

            ;
            __invoke("VariableDeclaration+").Is("VariableDeclaration+", "VariableDeclaration").Call((TES4VariableDeclarationList list, TES4VariableDeclaration variableDeclaration) =>
            {
                list.add(variableDeclaration);
                return(list);
            }).

            Is("VariableDeclaration").Call((TES4VariableDeclaration variableDeclaration) =>
            {
                TES4VariableDeclarationList list = new TES4VariableDeclarationList();
                list.add(variableDeclaration);
                return(list);
            })

            ;
            __invoke("VariableDeclaration").Is("VariableDeclarationType", "VariableName").Call((System.Func <CommonToken, CommonToken, TES4VariableDeclaration>)((CommonToken variableDeclarationType, CommonToken variableName) =>
            {
                return(new TES4VariableDeclaration((string)variableName.Value, TES4Type.GetFirst((string)variableDeclarationType.Value.ToLower())));
            }))

            ;
            __invoke("Block+").Is("Block+", "Block").Call((TES4BlockList list, TES4CodeBlock blockDeclaration) =>
            {
                list.Add(blockDeclaration);
                return(list);
            }).

            Is("Block").Call((TES4CodeBlock blockDeclaration) =>
            {
                TES4BlockList list = new TES4BlockList();
                list.Add(blockDeclaration);
                return(list);
            })

            ;
            __invoke("Block").Is("BlockStart", "BlockType", "BlockParameter+", "Code+", "BlockEnd").Call((System.Func <object, CommonToken, TES4BlockParameterList, TES4CodeChunks, object, TES4CodeBlock>)((object blockStart, CommonToken blockType, TES4BlockParameterList blockParameters, TES4CodeChunks codeChunks, object blockEnd) =>
            {
                return(new TES4CodeBlock((string)blockType.Value, blockParameters, codeChunks));
            })).

            Is("BlockStart", "BlockType", "BlockParameter+", "BlockEnd").Call((System.Func <object, CommonToken, TES4BlockParameterList, object, TES4CodeBlock>)((object blockStart, CommonToken blockType, TES4BlockParameterList blockParameters, object blockEnd) =>
            {
                return(new TES4CodeBlock((string)blockType.Value, blockParameters, null));
            }))  //rare empty block
            .

            Is("BlockStart", "BlockType", "Code+", "BlockEnd").Call((System.Func <object, CommonToken, TES4CodeChunks, object, TES4CodeBlock>)((object blockStart, CommonToken blockType, TES4CodeChunks codeChunks, object blockEnd) =>
            {
                return(new TES4CodeBlock((string)blockType.Value, null, codeChunks));
            })).

            Is("BlockStart", "BlockType", "BlockEnd").Call((System.Func <object, CommonToken, object, TES4CodeBlock>)((object blockStart, CommonToken blockType, object blockEnd) =>
            {
                return(new TES4CodeBlock((string)blockType.Value, null, null));
            }))

            ; //rare empty block
            __invoke("BlockParameter+").Is("BlockParameter+", "BlockParameter").Call((TES4BlockParameterList list, TES4BlockParameter blockParameter) =>
            {
                list.Add(blockParameter);
                return(list);
            }).

            Is("BlockParameter").Call((TES4BlockParameter blockParameter) =>
            {
                TES4BlockParameterList block = new TES4BlockParameterList();
                block.Add(blockParameter);
                return(block);
            })

            ;
            __invoke("BlockParameter").Is("BlockParameterToken").Call((System.Func <CommonToken, TES4BlockParameter>)((CommonToken token) =>
            {
                return(new TES4BlockParameter((string)token.Value));
            }))

            ;
            this.createObscriptCodeParsingTree();
            this.Start("Script");
        }
Beispiel #10
0
        public TES4OBScriptGrammar()
            : base(false)
        {
            __invoke("Script").Is("ScriptHeader", "Block+").Call((TES4ScriptHeader header, TES4BlockList blockList) =>
            {
                return(new TES4Script(header, null, blockList));
            }).

            Is("ScriptHeader", "VariableDeclaration+").Call((TES4ScriptHeader header, TES4VariableDeclarationList variableList) =>
            {
                return(new TES4Script(header, variableList, null));
            }).

            Is("ScriptHeader", "VariableDeclaration+", "Block+").Call((TES4ScriptHeader header, TES4VariableDeclarationList variableList, TES4BlockList blockList) =>
            {
                return(new TES4Script(header, variableList, blockList));
            })

#if NEWBT
            .
            Is("ScriptHeader").Call((TES4ScriptHeader header) =>//WTM:  Change:  I added this section to allow for a few more scripts to parsed (scripts that are just a header).
            {
                return(new TES4Script(header, null, null));
            })
#endif

            ;
            __invoke("ScriptHeader").Is("ScriptHeaderToken", "ScriptName").Call((object headerToken, CommonToken scriptName) =>
            {
                return(new TES4ScriptHeader(scriptName.Value));
            })

            ;
            __invoke("VariableDeclaration+").Is("VariableDeclaration+", "VariableDeclaration").Call((TES4VariableDeclarationList list, TES4VariableDeclaration variableDeclaration) =>
            {
                list.Add(variableDeclaration);
                return(list);
            }).

            Is("VariableDeclaration").Call((TES4VariableDeclaration variableDeclaration) =>
            {
                TES4VariableDeclarationList list = new TES4VariableDeclarationList();
                list.Add(variableDeclaration);
                return(list);
            })

            ;
            __invoke("VariableDeclaration").Is("VariableDeclarationType", "VariableName").Call((CommonToken variableDeclarationType, CommonToken variableName) =>
            {
                return(new TES4VariableDeclaration(variableName.Value, TES4Type.GetFirst(variableDeclarationType.Value.ToLower())));
            })

            ;
            __invoke("Block+").Is("Block+", "Block").Call((TES4BlockList list, TES4CodeBlock blockDeclaration) =>
            {
                list.Add(blockDeclaration);
                return(list);
            }).

            Is("Block").Call((TES4CodeBlock blockDeclaration) =>
            {
                TES4BlockList list = new TES4BlockList();
                list.Add(blockDeclaration);
                return(list);
            })

            ;
            __invoke("Block").Is("BlockStart", "BlockType", "BlockParameter+", "Code+", "BlockEnd").Call((object blockStart, CommonToken blockType, TES4BlockParameterList blockParameters, TES4CodeChunks codeChunks, object blockEnd) =>
            {
                return(new TES4CodeBlock(blockType.Value, blockParameters, codeChunks));
            }).

            Is("BlockStart", "BlockType", "BlockParameter+", "BlockEnd").Call((object blockStart, CommonToken blockType, TES4BlockParameterList blockParameters, object blockEnd) =>
            {
                return(new TES4CodeBlock(blockType.Value, blockParameters, null));
            }) //rare empty block
            .

            Is("BlockStart", "BlockType", "Code+", "BlockEnd").Call((object blockStart, CommonToken blockType, TES4CodeChunks codeChunks, object blockEnd) =>
            {
                return(new TES4CodeBlock(blockType.Value, null, codeChunks));
            }).

            Is("BlockStart", "BlockType", "BlockEnd").Call((object blockStart, CommonToken blockType, object blockEnd) =>
            {
                return(new TES4CodeBlock(blockType.Value, null, null));
            })

            ; //rare empty block
            __invoke("BlockParameter+").Is("BlockParameter+", "BlockParameter").Call((TES4BlockParameterList list, TES4BlockParameter blockParameter) =>
            {
                list.Add(blockParameter);
                return(list);
            }).

            Is("BlockParameter").Call((TES4BlockParameter blockParameter) =>
            {
                TES4BlockParameterList block = new TES4BlockParameterList();
                block.Add(blockParameter);
                return(block);
            })

            ;
            __invoke("BlockParameter").Is("BlockParameterToken").Call((CommonToken token) =>
            {
                return(new TES4BlockParameter(token.Value));
            })

            ;
            this.CreateObscriptCodeParsingTree();
            this.Start("Script");
        }