本文整理汇总了C#中Lexer.UnGet方法的典型用法代码示例。如果您正苦于以下问题:C# Lexer.UnGet方法的具体用法?C# Lexer.UnGet怎么用?C# Lexer.UnGet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lexer
的用法示例。
在下文中一共展示了Lexer.UnGet方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNextByte
private NumberLexToken GetNextByte(Lexer.Lexer lexer)
{
var token = lexer.Next();
if (token != null
&& token is NumberLexToken)
{
if ((token as NumberLexToken).IntValue() > 0xff
|| (token as NumberLexToken).IntValue() < 0x0)
{
throw new SyntaxException($"{token.Value()} is not the correct size of a byte");
}
}
else
{
lexer.UnGet(token);
token = new NumberLexToken("0x0");
}
return (NumberLexToken)token;
}
示例2: ParseInstruction
public void ParseInstruction(Lexer.Lexer lexer, bool buildingLabelTable = false)
{
var operation = lexer.Next();
lexer.UnGet(operation);
if (operation is AddressDataStatementLexToken)
{
ParseAddressDataStatement(lexer);
}
else if (operation is ByteDataStatementLexToken)
{
ParseByteDataStatement(lexer);
}
else if (operation is IfStatementLexToken)
{
ParseIfStatement(lexer, buildingLabelTable);
}
else if (operation is LabelDeclarationLexToken)
{
ParseLabelDeclaration(lexer, buildingLabelTable);
}
else if (operation is NewLineLexToken)
{
ParseNewLine(lexer);
}
else if (operation is OpCodeLexToken)
{
ParseOperation(lexer, buildingLabelTable);
}
else if (operation is WordDataStatementLexToken)
{
ParseWordDataStatement(lexer);
}
else
{
throw new SyntaxException($"Unknown instruction: {operation.Value()} on line {LineNumber}");
}
}
示例3: ParseWordDataStatement
public void ParseWordDataStatement(Lexer.Lexer lexer)
{
var token = lexer.Next();
if (token != null
&& token is WordDataStatementLexToken)
{
var a1 = lexer.Next();
while (a1 != null
&& a1 is NumberLexToken
&& (a1 as NumberLexToken).IntValue() != 0)
{
var encoded = Convert.ToUInt32(a1.Value(), 16);
WriteInstructionToKernel(encoded);
a1 = lexer.Next();
}
lexer.UnGet(a1);
}
}
示例4: ParseByteDataStatement
public void ParseByteDataStatement(Lexer.Lexer lexer)
{
var token = lexer.Next();
if (token != null
&& token is ByteDataStatementLexToken)
{
var a1 = lexer.Next();
while (a1 != null
&& a1 is NumberLexToken
//&& (a1 as NumberLexToken).IntValue() != 0
)
{
if ((a1 as NumberLexToken).IntValue() > 0xff
|| (a1 as NumberLexToken).IntValue() < 0x0)
{
throw new SyntaxException($"{a1.Value()} is not the correct size of a byte");
}
var a2 = GetNextByte(lexer);
var a3 = GetNextByte(lexer);
var a4 = GetNextByte(lexer);
var data = $"{a4.Value().Substring(2).PadLeft(2, '0')}{a3.Value().Substring(2).PadLeft(2, '0')}{a2.Value().Substring(2).PadLeft(2, '0')}{a1.Value().Substring(2).PadLeft(2, '0')}";
var encoded = Convert.ToUInt32(data, 16);
WriteInstructionToKernel(encoded, $"{token.Value()}: {a1.Value()}, {a2.Value()}, {a3.Value()}, {a4.Value()}");
a1 = lexer.Next();
}
lexer.UnGet(a1);
}
}