• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Runtime.ANTLRInputStream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Antlr.Runtime.ANTLRInputStream的典型用法代码示例。如果您正苦于以下问题:C# ANTLRInputStream类的具体用法?C# ANTLRInputStream怎么用?C# ANTLRInputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ANTLRInputStream类属于Antlr.Runtime命名空间,在下文中一共展示了ANTLRInputStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Main

		static void Main(string[] args)
		{
			int port = 49101;
			string sql = "select * from t1 left join t2";
			MemoryStream ms = new MemoryStream(ASCIIEncoding.ASCII.GetBytes(sql.ToUpper()));
			ANTLRInputStream input = new ANTLRInputStream(ms);
			MySQL51Lexer lexer = new MySQL51Lexer(input);
			// I need a Tree adaptor to build a DebugEventSocketProxy, but I need a 
			// DebugEventSocketProxy to build a Tree Adaptor.
			// Solution: Create the DebugEventSocketProxy 
			//ITreeAdaptor adaptor = new DebugTreeAdaptor(/*dbg*/ null, new CommonTreeAdaptor());
			// To create a DebugTokenStream I need a DebugEventSocketProxy and viceversa
			// Solution: Create DebugEventSocketProxy in the DebugTokenStream contructor
			// How do I get a ITokenStream implementation?
			// Another Caveat: The instance of DebugEventProxySocket must be the same for the lexer than for the parser.

			//DebugEventSocketProxy proxy = new DebugEventSocketProxy(this, port, adaptor);
			DebugTokenStream tokens = new DebugTokenStream( new BufferedTokenStream( lexer ), port, null);
			//CommonTokenStream tokens = new CommonTokenStream(lexer);
			MySQL51Parser parser = new MySQL51Parser(tokens, port, null);
			StringBuilder sb = new StringBuilder();
			TextWriter tw = new StringWriter(sb);
			try
			{
				parser.TraceDestination = tw;
				MySQL51Parser.statement_list_return r = parser.statement_list();
			}
			catch (RecognitionException re)
			{
				Console.WriteLine(re.StackTrace);
			}
		}
开发者ID:Top-Cat,项目名称:SteamBot,代码行数:32,代码来源:Program.cs


示例2: Main

 public static void Main(string[] args)
 {
     Stream inputStream = Console.OpenStandardInput();
     ANTLRInputStream input = new ANTLRInputStream(inputStream);
     CalculatorLexer lexer = new CalculatorLexer(input);
     CommonTokenStream tokens = new CommonTokenStream(lexer);
     CalculatorParser parser = new CalculatorParser(tokens);
     parser.stat();
 }
开发者ID:QAMichaelPeng,项目名称:CoolCompiler,代码行数:9,代码来源:CalculatorMain.cs


示例3: Main

        static void Main(string[] args)
        {
            Stream inputStream = new MemoryStream(Encoding.UTF8.GetBytes(args[0]));

            ANTLRInputStream input = new ANTLRInputStream(inputStream);
            PonishNotationLexer lexer = new PonishNotationLexer(input);
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            PonishNotationParser parser = new PonishNotationParser(tokens);
            parser.prog();
        }
开发者ID:isaachan,项目名称:on-the-way,代码行数:10,代码来源:Runner.cs


示例4: test

        private static void test()
        {
            string lexstream = "call foo;";

            MemoryStream ms = new MemoryStream(System.Text.ASCIIEncoding.ASCII.GetBytes(lexstream));
            ANTLRInputStream ais = new ANTLRInputStream(ms);
            vmexxLexer lexer = new vmexxLexer(ais);
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            vmexxParser parser = new vmexxParser(tokens);
            //parser.Program();
            parser.Rule();
        }
开发者ID:donreamey,项目名称:vmeex,代码行数:12,代码来源:Nire.cs


示例5: Main

        static void Main(string[] args)
        {
            using (var stardardInput = Console.OpenStandardInput())
            {
                ANTLRInputStream input = new ANTLRInputStream(stardardInput);
                ExprLexer lexer = new ExprLexer(input);
                CommonTokenStream tokens = new CommonTokenStream(lexer);
                ExprParser parser = new ExprParser(tokens);
                parser.prog();
            }

            Console.ReadKey();
        }
开发者ID:adbrowne,项目名称:abcm,代码行数:13,代码来源:Program.cs


示例6: TestSYMMIB_MIB_MIB

 public void TestSYMMIB_MIB_MIB()
 {
     var stream = new ANTLRInputStream(new MemoryStream(Resources.SYMMIB_MIB_MIB));
     var lexer = new SmiLexer(stream);
     var tokens = new CommonTokenStream(lexer);
     var parser = new SmiParser(tokens);
     var document = parser.GetDocument();
     Assert.AreEqual(1, document.Modules.Count);
     Assert.AreEqual("SYMMIB_MIB-MIB", document.Modules[0].Name);
     Assert.AreEqual(117, document.Modules[0].Constructs.Count);
     Assert.AreEqual(98, document.Modules[0].Entities.Count);
     var node = document.Modules[0].Entities[97];
     Assert.AreEqual("disableTrapAtt3", node.Name);
     Assert.AreEqual(3, node.Value);
     Assert.AreEqual("iNTELMIFTOMIBEntry", node.Parent);
 }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:16,代码来源:MibDocumentTestFixture.cs


示例7: TestSNMPv2_SMI

 public void TestSNMPv2_SMI()
 {
     var stream = new ANTLRInputStream(new MemoryStream(Resources.SNMPv2_SMI));
     var lexer = new SmiLexer(stream);
     var tokens = new CommonTokenStream(lexer);
     var parser = new SmiParser(tokens);
     var document = parser.GetDocument();
     Assert.AreEqual(1, document.Modules.Count);
     Assert.AreEqual("SNMPv2-SMI", document.Modules[0].Name);
     Assert.AreEqual(34, document.Modules[0].Constructs.Count);
     Assert.AreEqual(16, document.Modules[0].Entities.Count);
     var node = document.Modules[0].Entities[15];
     Assert.AreEqual("zeroDotZero", node.Name);
     Assert.AreEqual(0, node.Value);
     Assert.AreEqual("ccitt", node.Parent);
 }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:16,代码来源:MibDocumentTestFixture.cs


示例8: Interpreter

 public Interpreter(
     Stream stream,
     TemplateCache cache = null)
 {
     Cache = cache ?? new TemplateCache();
     var charStream = new ANTLRInputStream(stream);
     var lexer = TemplateLexer.Create(charStream);
     var tokenStream = new CommonTokenStream(lexer);
     var parser = new TemplateParser(tokenStream)
     {
         TraceDestination = Console.Out,
         Errors = _parserErrors
     };
     var docResult = parser.document();
     _ast = docResult.Tree;
 }
开发者ID:jeffpanici75,项目名称:FastTemplate,代码行数:16,代码来源:Interpreter.cs


示例9: Parse

 public static Regex Parse(string str, bool caseInsensitive=false)
 {
     using (var s = new MemoryStream())
     using (var wr = new StreamWriter(s))
     {
         wr.Write(str);
         wr.Flush();
         s.Position = 0;
         var input = new ANTLRInputStream(s);
         // Create an ExprLexer that feeds from that stream
         var lexer = new SearchExprLexer(input);
         // Create a stream of tokens fed by the lexer
         var tokens = new CommonTokenStream(lexer);
         // Create a parser that feeds off the token stream
         var parser = new SearchExprParser(tokens);
         return parser.Search(caseInsensitive);
     }
 }
开发者ID:wallymathieu,项目名称:nack,代码行数:18,代码来源:SearchExprParserPartial.cs


示例10: _Main

        private static void _Main(string[] args)
        {
            // input "x = 2*(3+3)"

            ICharStream input;
            if (args.Length > 0)
            {
                if (args[0].Equals("-i"))
                {
                    if (args.Length > 1)
                    {
                        input = new ANTLRFileStream(args[1]);
                    }
                    else
                    {
                        throw new Exception("No input file specified.");
                    }
                }
                else
                {
                    input = new ANTLRStringStream(args[0]);
                }
            }
            else
            {
                input = new ANTLRInputStream(Console.OpenStandardInput());
            }

            var lex = new VecMathLexer(input);
            var tokens = new CommonTokenStream(lex);
            var g = new VecMathParser(tokens);
            IAstRuleReturnScope<CommonTree> r = g.prog();
            CommonTree t = r.Tree;
            Console.WriteLine("Original tree:   " + t.ToStringTree());

            var simplify = new Simplify(new CommonTreeNodeStream(t));
            t = (CommonTree)simplify.Downup(t);

            var reduce = new Reduce(new CommonTreeNodeStream(t));
            t = (CommonTree)reduce.Downup(t);

            Console.WriteLine("Simplified tree: " + t.ToStringTree());
            Console.ReadKey();
        }
开发者ID:biddyweb,项目名称:azfone-ios,代码行数:44,代码来源:Program.cs


示例11: Parse

        /// <summary>
        ///   Переводит строковое представление формулы логики LTL в
        ///   эквивалентный экземпляр <see cref = "LTLFormula" />.
        /// </summary>
        /// <param name = "s">Строка.</param>
        /// <exception cref = "ArgumentNullException"><paramref name = "s" /> является <c>null</c>.</exception>
        /// <exception cref = "ArgumentException"><paramref name = "s" /> не содержит формулу.</exception>
        /// <returns>Формула логики LTL.</returns>
        public static LTLFormula Parse(string s)
        {
            if (s == null)
                throw new ArgumentNullException ("s");

            try {
                using (var memoryStream = new MemoryStream (Encoding.Default.GetBytes (s))) {
                    var stream = new ANTLRInputStream (memoryStream);
                    var parser = new LTLParserParser (new CommonTokenStream (new LTLParserLexer (stream)));
                    var result = parser.start ();

                    if (result == null)
                        throw new ArgumentException ();

                    return result;
                }
            }
            catch (Exception e) {
                throw new ArgumentException (e.Message);
            }
        }
开发者ID:victorsamun,项目名称:NSimulator,代码行数:29,代码来源:LTLFormula.cs


示例12: TestUDP_MIB

 public void TestUDP_MIB()
 {
     var m = new MemoryStream(Resources.UDP_MIB);
     var stream = new ANTLRInputStream(m);
     var lexer = new SmiLexer(stream);
     var tokens = new CommonTokenStream(lexer);
     var parser = new SmiParser(tokens);
     var file = parser.GetDocument();Assert.AreEqual(0, parser.Warnings.Count);
     Assert.AreEqual(1, file.Modules.Count);
     Assert.AreEqual("UDP-MIB", file.Modules[0].Name);
     Assert.AreEqual(31, file.Modules[0].Entities.Count);
     IEntity node = file.Modules[0].Entities[30];
     Assert.AreEqual("udpEndpointGroup", node.Name);
     Assert.AreEqual(4, node.Value);
     Assert.AreEqual("udpMIBGroups", node.Parent);
 }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:16,代码来源:MibDocumentTestFixture.cs


示例13: TestUCD_SNMP_MIB_OLD

 public void TestUCD_SNMP_MIB_OLD()
 {
     var m = new MemoryStream(Resources.UCD_SNMP_MIB_OLD);
     var stream = new ANTLRInputStream(m);
     var lexer = new SmiLexer(stream);
     var tokens = new CommonTokenStream(lexer);
     var parser = new SmiParser(tokens);
     var file = parser.GetDocument();Assert.AreEqual(0, parser.Warnings.Count);
     Assert.AreEqual(1, file.Modules.Count);
     Assert.AreEqual("UCD-SNMP-MIB-OLD", file.Modules[0].Name);
     Assert.AreEqual(35, file.Modules[0].Entities.Count);
     IEntity node = file.Modules[0].Entities[34];
     Assert.AreEqual("loadaveErrMessage", node.Name);
     Assert.AreEqual(101, node.Value);
     Assert.AreEqual("loadaves", node.Parent);
 }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:16,代码来源:MibDocumentTestFixture.cs


示例14: TestUCD_SNMP_MIB

 public void TestUCD_SNMP_MIB()
 {
     var m = new MemoryStream(Resources.UCD_SNMP_MIB1);
     var stream = new ANTLRInputStream(m);
     var lexer = new SmiLexer(stream);
     var tokens = new CommonTokenStream(lexer);
     var parser = new SmiParser(tokens);
     var file = parser.GetDocument();Assert.AreEqual(0, parser.Warnings.Count);
     Assert.AreEqual(1, file.Modules.Count);
     Assert.AreEqual("UCD-SNMP-MIB", file.Modules[0].Name);
     Assert.AreEqual(158, file.Modules[0].Entities.Count);
     IEntity node = file.Modules[0].Entities[157];
     Assert.AreEqual("logMatchRegExCompilation", node.Name);
     Assert.AreEqual(101, node.Value);
     Assert.AreEqual("logMatchEntry", node.Parent);
 }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:16,代码来源:MibDocumentTestFixture.cs


示例15: TestUCD_IPFWACC_MIB

 public void TestUCD_IPFWACC_MIB()
 {
     var m = new MemoryStream(Resources.UCD_IPFWACC_MIB1);
     var stream = new ANTLRInputStream(m);
     var lexer = new SmiLexer(stream);
     var tokens = new CommonTokenStream(lexer);
     var parser = new SmiParser(tokens);
     var file = parser.GetDocument();Assert.AreEqual(0, parser.Warnings.Count);
     Assert.AreEqual(1, file.Modules.Count);
     Assert.AreEqual("UCD-IPFWACC-MIB", file.Modules[0].Name);
     Assert.AreEqual(29, file.Modules[0].Entities.Count);
     IEntity node = file.Modules[0].Entities[28];
     Assert.AreEqual("ipFwAccPort10", node.Name);
     Assert.AreEqual(26, node.Value);
     Assert.AreEqual("ipFwAccEntry", node.Parent);
 }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:16,代码来源:MibDocumentTestFixture.cs


示例16: TestUCD_DLMOD_MIB

 public void TestUCD_DLMOD_MIB()
 {
     var m = new MemoryStream(Resources.UCD_DLMOD_MIB1);
     var stream = new ANTLRInputStream(m);
     var lexer = new SmiLexer(stream);
     var tokens = new CommonTokenStream(lexer);
     var parser = new SmiParser(tokens);
     var file = parser.GetDocument();Assert.AreEqual(0, parser.Warnings.Count);
     Assert.AreEqual(1, file.Modules.Count);
     Assert.AreEqual("UCD-DLMOD-MIB", file.Modules[0].Name);
     Assert.AreEqual(9, file.Modules[0].Entities.Count);
     IEntity node = file.Modules[0].Entities[8];
     Assert.AreEqual("dlmodStatus", node.Name);
     Assert.AreEqual(5, node.Value);
     Assert.AreEqual("dlmodEntry", node.Parent);
 }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:16,代码来源:MibDocumentTestFixture.cs


示例17: TestUCD_DISKIO_MIB

 public void TestUCD_DISKIO_MIB()
 {
     var m = new MemoryStream(Resources.UCD_DISKIO_MIB1);
     var stream = new ANTLRInputStream(m);
     var lexer = new SmiLexer(stream);
     var tokens = new CommonTokenStream(lexer);
     var parser = new SmiParser(tokens);
     var file = parser.GetDocument();Assert.AreEqual(0, parser.Warnings.Count);
     Assert.AreEqual(1, file.Modules.Count);
     Assert.AreEqual("UCD-DISKIO-MIB", file.Modules[0].Name);
     Assert.AreEqual(14, file.Modules[0].Entities.Count);
     IEntity node = file.Modules[0].Entities[13];
     Assert.AreEqual("diskIONWrittenX", node.Name);
     Assert.AreEqual(13, node.Value);
     Assert.AreEqual("diskIOEntry", node.Parent);
 }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:16,代码来源:MibDocumentTestFixture.cs


示例18: TestUCD_DEMO_MIB

 public void TestUCD_DEMO_MIB()
 {
     var m = new MemoryStream(Resources.UCD_DEMO_MIB1);
     var stream = new ANTLRInputStream(m);
     var lexer = new SmiLexer(stream);
     var tokens = new CommonTokenStream(lexer);
     var parser = new SmiParser(tokens);
     var file = parser.GetDocument();Assert.AreEqual(0, parser.Warnings.Count);
     Assert.AreEqual(1, file.Modules.Count);
     Assert.AreEqual("UCD-DEMO-MIB", file.Modules[0].Name);
     Assert.AreEqual(7, file.Modules[0].Entities.Count);
     IEntity node = file.Modules[0].Entities[6];
     Assert.AreEqual("ucdDemoPassphrase", node.Name);
     Assert.AreEqual(4, node.Value);
     Assert.AreEqual("ucdDemoPublic", node.Parent);
 }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:16,代码来源:MibDocumentTestFixture.cs


示例19: TestRFC1271_MIB

 public void TestRFC1271_MIB()
 {
     var m = new MemoryStream(Resources.RFC1271_MIB);
     var stream = new ANTLRInputStream(m);
     var lexer = new SmiLexer(stream);
     var tokens = new CommonTokenStream(lexer);
     var parser = new SmiParser(tokens);
     var file = parser.GetDocument();Assert.AreEqual(0, parser.Warnings.Count);
     Assert.AreEqual(1, file.Modules.Count);
     Assert.AreEqual("RFC1271-MIB", file.Modules[0].Name);
     Assert.AreEqual(213, file.Modules[0].Entities.Count);
     IEntity node = file.Modules[0].Entities[212];
     Assert.AreEqual("logDescription", node.Name);
     Assert.AreEqual(4, node.Value);
     Assert.AreEqual("logEntry", node.Parent);
 }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:16,代码来源:MibDocumentTestFixture.cs


示例20: Main

        static void Main(string[] args)
        {
            ICharStream input = null;

            if (args.Length > 0)
            {
                if (args[0] == "bytecompiler")
                {
                    input = new ANTLRInputStream(Console.OpenStandardInput());
                    ByteCompilerFrontend fe = new ByteCompilerFrontend();
                    fe.Listener = new DefaultLSLListener();
                    fe.Compile(input);

                    CompiledScript script = fe.Result;
                    if (script != null)
                    {
                        System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
                        watch.Start();
                        Interpreter i = new Interpreter(script, null);
                        i.TraceDestination = Console.Out;
                        while (i.ScriptState.RunState == RuntimeState.Status.Running)
                        {
                            i.Tick();
                        }

                        watch.Stop();
                        System.Console.WriteLine(watch.ElapsedMilliseconds/1000.0);
                    }
                }
                else
                {
                    foreach (string arg in args)
                    {
                        Console.WriteLine("Compiling: " + arg);

                        input = new ANTLRFileStream(arg);
                        CompilerFrontend fe = new CompilerFrontend();
                        fe.TraceDestination = Console.Out;
                        fe.Compile(input);
                    }
                }
            }
            else
            {
                ILSLListener listener = new DefaultLSLListener();
                LSLListenerTraceRedirectorMono redirector = new LSLListenerTraceRedirectorMono(listener);

                input = new ANTLRInputStream(Console.OpenStandardInput());
                CompilerFrontend fe = new CompilerFrontend();
                fe.TraceDestination = redirector;
                fe.Listener = listener;

                Console.WriteLine("** compilation output **");
                string byteCode = fe.Compile(input);

                
                if (! listener.HasErrors() && byteCode != null)
                {
                    input = new ANTLRStringStream(byteCode);
                    ByteCompilerFrontend bfe = new ByteCompilerFrontend();
                    bfe.TraceDestination = redirector;
                    bfe.Listener = listener;
                    bfe.Compile(input);

                    CompiledScript script = bfe.Result;
                    Console.WriteLine("** usage info **");
                    if (script != null) Console.WriteLine("Base memory: {0} bytes", script.CalcBaseMemorySize());
                    //SaveScript(script);

                    /*
                    if (script != null)
                    {
                        System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
                        watch.Start();
                        Interpreter i = new Interpreter(script, null);
                        i.TraceDestination = Console.Out;
                        while (i.ScriptState.RunState == RuntimeState.Status.Running)
                        {
                            i.Tick();
                        }

                        watch.Stop();
                        System.Console.WriteLine("Execution: {0} seconds", watch.ElapsedMilliseconds / 1000.0);
                        System.Console.WriteLine("Free Memory: {0} bytes", i.ScriptState.MemInfo.MemoryFree);
                    }
                     * */
                }

                
            }
        }
开发者ID:emperorstarfinder,项目名称:phlox,代码行数:91,代码来源:Program.cs



注:本文中的Antlr.Runtime.ANTLRInputStream类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Runtime.ANTLRStringStream类代码示例发布时间:2022-05-24
下一篇:
C# Css.CssParser类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap