public NonlinearEquationDescription CompileEquations(string text)
        {
            compilerErrors = new List <ErrorMessage>();
            constants      = new Dictionary <string, double>();
            variables      = new Dictionary <string, int>();
            variableNames  = new List <string>();
            initialValues  = new List <double>();
            FunctionTable.Init();

            AntlrInputStream     inputStream = new AntlrInputStream(text);
            EquationGrammarLexer eqLexer     = new EquationGrammarLexer(inputStream);

            eqLexer.RemoveErrorListeners();
            ErrorListener <int> lexerListener = new ErrorListener <int>();

            eqLexer.AddErrorListener(lexerListener);
            CommonTokenStream      commonTokenStream = new CommonTokenStream(eqLexer);
            EquationGrammarParser  eqParser          = new EquationGrammarParser(commonTokenStream);
            ErrorListener <IToken> parserListener    = new ErrorListener <IToken>();

            eqParser.RemoveErrorListeners();
            eqParser.AddErrorListener(parserListener);
            EquationGrammarParser.CompileUnitContext eqContext = eqParser.compileUnit();
            compilerErrors = lexerListener.GetErrors();
            if (compilerErrors.Count > 0)
            {
                throw new CompilerException(compilerErrors, "Ошибки лексера");
            }
            compilerErrors = parserListener.GetErrors();
            if (compilerErrors.Count > 0)
            {
                throw new CompilerException(compilerErrors, "Ошибки парсера");
            }
            GrammarVisitor visitor = new GrammarVisitor();
            ASTNode        root    = visitor.VisitCompileUnit(eqContext);

            /*EquationGrammarVisitor visitor = new EquationGrammarVisitor();
             * ASTNode root = visitor.VisitCompileUnit(expContext);
             * var rootSimple = Compiler.ASTCompiler.validate(root);
             * rootSimple = Compiler.ASTCompiler.simplify(rootSimple);
             * return compileASTExpression(rootSimple);*/
            return(CompileEquations((RootNode)root));
        }
        public Implicit.DAEIDescription CompileDAEImplicit(string text)
        {
            compilerErrors = new List <ErrorMessage>();
            parameters     = new Dictionary <string, double>();
            constants      = new Dictionary <string, double>();
            variables      = new Dictionary <string, Variable>();
            FunctionTable.Init();
            //variables.Add("t", new Variable { Name = "t", InitialValue = 0.0, Initialized = true, VarType = Variable.Type.Algebraic, Count = 0 });

            AntlrInputStream        inputStream = new AntlrInputStream(text);
            DAEImplicitGrammarLexer eqLexer     = new DAEImplicitGrammarLexer(inputStream);

            eqLexer.RemoveErrorListeners();
            ErrorListener <int> lexerListener = new ErrorListener <int>();

            eqLexer.AddErrorListener(lexerListener);
            CommonTokenStream        commonTokenStream = new CommonTokenStream(eqLexer);
            DAEImplicitGrammarParser eqParser          = new DAEImplicitGrammarParser(commonTokenStream);
            ErrorListener <IToken>   parserListener    = new ErrorListener <IToken>();

            eqParser.RemoveErrorListeners();
            eqParser.AddErrorListener(parserListener);
            DAEImplicitGrammarParser.CompileUnitContext eqContext = eqParser.compileUnit();
            compilerErrors = lexerListener.GetErrors();
            if (compilerErrors.Count > 0)
            {
                throw new CompilerException(compilerErrors, "Ошибки лексера");
            }
            compilerErrors = parserListener.GetErrors();
            if (compilerErrors.Count > 0)
            {
                throw new CompilerException(compilerErrors, "Ошибки парсера");
            }
            DAEImplicitGrammarVisitor visitor = new DAEImplicitGrammarVisitor();
            ASTNode root = visitor.VisitCompileUnit(eqContext);

            return(CompileDAEImplicit((RootNode)root));
        }