本文整理汇总了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);
}
示例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);
}
示例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);
}
示例4: Lex
public bool Lex()
{
l = new Lexer(file);
return l.Lex();
}