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


C# Lexer.UnGet方法代码示例

本文整理汇总了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;
 }
开发者ID:brollins90,项目名称:SimpleAssembler,代码行数:19,代码来源:Parser.cs

示例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}");
            }
        }
开发者ID:brollins90,项目名称:SimpleAssembler,代码行数:38,代码来源:Parser.cs

示例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);
            }
        }
开发者ID:brollins90,项目名称:SimpleAssembler,代码行数:19,代码来源:Parser.cs

示例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);
            }
        }
开发者ID:brollins90,项目名称:SimpleAssembler,代码行数:30,代码来源:Parser.cs


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