当前位置: 首页>>代码示例>>C#>>正文


C# Lexer.Lex方法代码示例

本文整理汇总了C#中Lexer.Lex方法的典型用法代码示例。如果您正苦于以下问题:C# Lexer.Lex方法的具体用法?C# Lexer.Lex怎么用?C# Lexer.Lex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lexer的用法示例。


在下文中一共展示了Lexer.Lex方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

 public static void Main(string[] args)
 {
     while (true)
     {
         try
         {
             string s = Console.ReadLine();
             Lexer l = new Lexer();
             Parser p = new Parser(l.Lex(s));
             Ast.Chunk c = p.Parse();
             Compiler.Compiler cplr = new SharpLua.Compiler.Compiler();
             LuaFile proto = cplr.Compile(c, "<stdin>");
             Console.WriteLine("compiled!");
             FileStream fs = File.Open("out.sluac", FileMode.Create);
             foreach (char ch in proto.Compile())
             {
                 //Console.WriteLine(ch + " " + (int)ch);
                 fs.WriteByte((byte)ch);
             }
             fs.Close();
             Console.WriteLine("written to out.sluac!");
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.ToString());
         }
     }
     Console.Write("Press any key to continue . . . ");
     Console.ReadKey(true);
 }
开发者ID:chenzuo,项目名称:SharpLua,代码行数:30,代码来源:Program.cs

示例2: TestLexer

 public void TestLexer()
 {
     string xml = @"
     <MapReduce>
         <Map>
             <MapRule Type = 'MapRuleOnT1IfTrue' />
             <ForEach>
               <Rule Type = 'IninValueOnT3'/>
             </ForEach>
         </Map>
      <Reduce>
             <ReduceRule Type = 'ReduceRuleOnT1' />
             <ReduceRule Type = 'AssignRuleOnT1' />
         </Reduce>
     </MapReduce>";
     XDocument _xDoc = _xDoc = XDocument.Parse(xml);
     XElement source = _xDoc.Element("MapReduce");
     var lexer = new Lexer(source);
     var results = lexer.Lex().ToList();
     Assert.AreEqual(TokenType.MAPREDUCE, results[0].TokenType);
     Assert.AreEqual(TokenType.MAP, results[1].TokenType);
     Assert.AreEqual(TokenType.MAPRULE, results[2].TokenType);
     Assert.AreEqual(TokenType.FOREACH, results[3].TokenType);
     Assert.AreEqual(TokenType.RULE, results[4].TokenType);
     Assert.AreEqual(TokenType.EOF, results[5].TokenType);
     Assert.AreEqual(TokenType.EOF, results[6].TokenType);
     Assert.AreEqual(TokenType.REDUCE, results[7].TokenType);
     Assert.AreEqual(TokenType.REDUCERULE, results[8].TokenType);
     Assert.AreEqual(TokenType.REDUCERULE, results[9].TokenType);
     Assert.AreEqual(TokenType.EOF, results[10].TokenType);
     Assert.AreEqual(TokenType.EOF, results[11].TokenType);
 }
开发者ID:barbarossia,项目名称:ConsoleApplication2,代码行数:32,代码来源:UnitTest1.cs

示例3: TestIgnorCase

 public void TestIgnorCase()
 {
     string xml = @"
     <mapreduce>
         <map>
             <maprule type = 'mapruleont1iftrue' />
             <foreach>
               <rule type = 'ininvalueont3'/>
             </foreach>
         </map>
      <reduce>
             <reducerule type = 'reduceruleont1' />
             <reducerule type = 'assignruleont1' />
         </reduce>
     </mapreduce>";
     XDocument _xDoc = _xDoc = XDocument.Parse(xml);
     XElement source = _xDoc.Element("mapreduce");
     var lexer = new Lexer(source);
     var results = lexer.Lex().ToList();
     Assert.AreEqual(TokenType.MAPREDUCE, results[0].TokenType);
     Assert.AreEqual(TokenType.MAP, results[1].TokenType);
     Assert.AreEqual(TokenType.MAPRULE, results[2].TokenType);
     Assert.AreEqual(TokenType.FOREACH, results[3].TokenType);
     Assert.AreEqual(TokenType.RULE, results[4].TokenType);
     Assert.AreEqual(TokenType.EOF, results[5].TokenType);
     Assert.AreEqual(TokenType.EOF, results[6].TokenType);
     Assert.AreEqual(TokenType.REDUCE, results[7].TokenType);
     Assert.AreEqual(TokenType.REDUCERULE, results[8].TokenType);
     Assert.AreEqual(TokenType.REDUCERULE, results[9].TokenType);
     Assert.AreEqual(TokenType.EOF, results[10].TokenType);
     Assert.AreEqual(TokenType.EOF, results[11].TokenType);
 }
开发者ID:barbarossia,项目名称:ConsoleApplication2,代码行数:32,代码来源:UnitTest1.cs

示例4: Lex

    public bool Lex()
    {
	l = new Lexer(file);
	return l.Lex();
    }    
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:5,代码来源:clisp.cs


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