Пример #1
0
        public OclCompilerResult CompileEvolutionScript(string text, Bridge.IBridgeToOCL bridge)
        {
            TypesTable.TypesTable tt      = bridge.TypesTable;
            ErrorCollection       errColl = new ErrorCollection();

            // lexer
            ANTLRStringStream stringStream = new ANTLRStringStream(text);
            OCLSyntaxLexer    lexer        = new OCLSyntaxLexer(stringStream, errColl);

            // syntax
            CommonTokenStream tokenStream = new CommonTokenStream(lexer);
            OCLSyntaxParser   parser      = new OCLSyntaxParser(tokenStream, errColl);
            var output = parser.evolutionDeclarationList();

            // semantic
            Antlr.Runtime.Tree.CommonTreeNodeStream treeStream = new CommonTreeNodeStream(output.Tree);
            OCLAst semantic = new OCLAst(treeStream, errColl);

            semantic.TypesTable = tt;
            semantic.Bridge     = bridge;
            semantic.EnvironmentStack.Push(new NamespaceEnvironment(tt.Library.RootNamespace));
            AST.Constraints             constraints;
            AST.PropertyInitializations initializations;
            // try {
            OCLAst.evolutionDeclarationList_return evolutionDeclarationListReturn = semantic.evolutionDeclarationList();
            constraints     = evolutionDeclarationListReturn.Constraints;
            initializations = evolutionDeclarationListReturn.PropertyInitializations;
            // }
            //catch{
            //     constraints = new AST.Constraints();
            //    errColl.AddError(new ErrorItem("Fatal error."));
            // }

            return(new OclCompilerResult(constraints, initializations, errColl, tt.Library, bridge));
        }
Пример #2
0
        public OclCompilerResult CompileToAst()
        {
            Bridge.BridgeFactory factory = new Bridge.BridgeFactory();
            Bridge.IBridgeToOCL  bridge  = factory.Create(Schema);

            Compiler.Compiler compiler = new Compiler.Compiler();
            //Environment nsEnv = new NamespaceEnvironment(tt.Library.RootNamespace);

            //VariableDeclaration varSelf = new VariableDeclaration(selfName, contextClassifier, null);
            //Environment classifierEnv = nsEnv.CreateFromClassifier(contextClassifier, varSelf);

            //Environment selfEnv = Environment.AddElement(selfName, contextClassifier, varSelf, true);

            if (Type == EOclScriptType.Evolution)
            {
                return(compiler.CompileEvolutionScript(Contents, bridge));
            }
            else
            {
                return(compiler.CompileScript(Contents, bridge));
            }
        }