Esempio n. 1
0
        public void ParseInputFile(System.IO.StreamReader fIn)
        {
            var input       = new Antlr4.Runtime.AntlrInputStream(fIn);
            var lexer       = new Grammars.ZeroCode2Lexer(input);
            var tokenStream = new Antlr4.Runtime.CommonTokenStream(lexer);
            var parser      = new Grammars.ZeroCode2(tokenStream);


            var walker = new Antlr4.Runtime.Tree.ParseTreeWalker();

            var Listener = new ZeroCodeListener();

            walker.Walk(Listener, parser.zcDefinition());

            ModelCollector = Listener.Collector;

            GraphElements = Listener.GraphElements;

            if (ResolveInheritance() == false)
            {
                logger.Error("Not all Inheritances were resolved");
                HasErrors = true;
            }

            if (parser.NumberOfSyntaxErrors > 0)
            {
                HasErrors = true;
                logger.Error("Errors exist in the input file");
            }
            // dump all errors:
            Errors.ForEach(e => logger.Error(e));
        }
Esempio n. 2
0
        } // End Sub LexerTest

        static void WalkerTest(string text)
        {
            try
            {
                System.IO.StringReader          reader = new System.IO.StringReader(text);
                Antlr4.Runtime.AntlrInputStream input  = new Antlr4.Runtime.AntlrInputStream(reader);
                TSqlLexer lexer = new TSqlLexer(input);
                Antlr4.Runtime.CommonTokenStream tokens = new Antlr4.Runtime.CommonTokenStream(lexer);
                TSqlParser parser = new TSqlParser(tokens);
                // Specify our entry point

                // TSqlParser.Query_specificationContext
                TSqlParser.Tsql_fileContext fileContext = parser.tsql_file();
                // Antlr4.Runtime.Tree.IParseTree root = (Antlr4.Runtime.Tree.IParseTree)fileContext;


                // TSqlParser.Query_specificationContext tsqlParser.Tsql_fileContext fileContext = parser.tsql_file();
                System.Console.WriteLine("fileContext.ChildCount = " + fileContext.ChildCount.ToString());
                // Walk it and attach our listener
                Antlr4.Runtime.Tree.ParseTreeWalker walker = new Antlr4.Runtime.Tree.ParseTreeWalker();
                // AntlrTsqListener listener = new AntlrTsqListener();
                EverythingListener listener = new EverythingListener();

                walker.Walk(listener, fileContext);
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine(e.Message);
            }
        } // End Sub WalkerTest
Esempio n. 3
0
        public void ProcessWorkload(string aScriptPath, EventHandler <string> aOnAnalyzingError)
        {
            string            lText   = ReadFile(aScriptPath);
            StringReader      lReader = new StringReader(lText);
            AntlrInputStream  lInput  = new AntlrInputStream(lReader);
            TSqlLexer         lLexer  = new TSqlLexer(new CaseChangingCharStream(lInput, true));
            CommonTokenStream lTokens = new CommonTokenStream(lLexer);
            TSqlParser        lParser = new TSqlParser(lTokens);

            TSqlParser.Tsql_fileContext Tsql_fileContext1 = lParser.tsql_file();

            Antlr4.Runtime.Tree.ParseTreeWalker lWalker = new Antlr4.Runtime.Tree.ParseTreeWalker();
            AntlrTsqlListener lListener = new AntlrTsqlListener();

            lListener.OnAnalyzingError += aOnAnalyzingError;
            lWalker.Walk(lListener, Tsql_fileContext1);
            Tables = lListener.AnalyzedWorkload;
        }
        public void ParseTemplateFile(System.IO.StreamReader fIn)
        {
            var input       = new Antlr4.Runtime.AntlrInputStream(fIn);
            var lexer       = new Grammars.ZeroCode2TemplateLexer(input);
            var tokenStream = new Antlr4.Runtime.CommonTokenStream(lexer);
            var parser      = new Grammars.ZeroCode2Template(tokenStream);

            var walker = new Antlr4.Runtime.Tree.ParseTreeWalker();

            var Listener = new ZeroCode2TemplateListener
            {
                Program = Program
            };

            walker.Walk(Listener, parser.template());

            Errors.AddRange(Program.Errors());
            HasErrors = Errors.Count > 0;
        }
        public override void ExitDatatableRowCell([NotNull] SBP.DatatableRowCellContext context)
        {
            var           text  = context.GetText().Trim();
            TypeReference type  = null;
            object        value = null;

            if (!String.IsNullOrEmpty(text))
            {
                // TODO: It MUST be possible to make this simpler... (e.g. re-use tokens)
                Antlr4.Runtime.ITokenSource lexer  = new Lexer(new Antlr4.Runtime.AntlrInputStream(text));
                Antlr4.Runtime.ITokenStream tokens = new Antlr4.Runtime.CommonTokenStream(lexer);
                var parser = new SBP(tokens);
                parser.RemoveErrorListeners();
                parser.AddErrorListener(m_errors);
                parser.BuildParseTree = true;
                var cellContext = parser.datatableRowCellContent();
                var walker      = new Antlr4.Runtime.Tree.ParseTreeWalker();
                m_expressionData.PushStackLevel("VariableType");
                walker.Walk(this, cellContext);
                var stack           = m_expressionData.PopStackLevel();
                var expressionValue = stack.Pop();
                if (expressionValue.IsConstant)
                {
                    type  = expressionValue.DataType;
                    value = expressionValue.Value;
                }
                else if (expressionValue.IsUnresolvedIdentifier)
                {
                    type  = new TypeReference(typeof(StepBro.Core.Data.Identifier));
                    value = expressionValue.Value;
                }
                else
                {
                    m_errors.SymanticError(context.Start.Line, context.Start.Column, false, "Error parsing cell value.");
                }
            }

            m_currentDatatableRowData.Add(new Tuple <string, TypeReference, object>(text, type, value));
        }
Esempio n. 6
0
        ///<summary>
        /// Constructor.
        ///</summary>
        public DomainProblem(string domainfile, string problemfile) : this()
        {
            using (var domstream = new StreamReader(domainfile)) {
                var inp    = new Antlr4.Runtime.AntlrInputStream(domstream);
                var lexer  = new pddlLexer(inp);
                var stream = new Antlr4.Runtime.CommonTokenStream(lexer);
                var parser = new pddlParser(stream);
                var tree   = parser.domain();
                this.domain = new DomainListener();
                var walker = new Antlr4.Runtime.Tree.ParseTreeWalker();
                walker.Walk(this.domain, tree);
            }

            using (var probstream = new StreamReader(problemfile)) {
                var inp    = new Antlr4.Runtime.AntlrInputStream(probstream);
                var lexer  = new pddlLexer(inp);
                var stream = new Antlr4.Runtime.CommonTokenStream(lexer);
                var parser = new pddlParser(stream);
                var tree   = parser.problem();
                this.problem = new ProblemListener();
                var walker = new Antlr4.Runtime.Tree.ParseTreeWalker();
                walker.Walk(this.problem, tree);
            }
        }