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

Python compiler.lexical函数代码示例

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

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



在下文中一共展示了lexical函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __init__

 def __init__(self, testname):
     HexTestCase.__init__(self, testname)
     f = open('fixtures/movingsprite/movingsprite.asm')
     code = f.read()
     f.close()
     tokens = lexical(code)
     self.ast = syntax(tokens)
开发者ID:BmanisKing,项目名称:Mine,代码行数:7,代码来源:movingsprite_test.py


示例2: test_several_lists_with_labels

    def test_several_lists_with_labels(self):
        code = '''
            .org $E000

            palette:
              .db $0F,$01,$02,$03,$04,$05,$06,$07,$08,$09,$0A,$0B,$0C,$0D,$0E,$0F
              .db $0F,$30,$31,$32,$33,$35,$36,$37,$38,$39,$3A,$3B,$3C,$3D,$3E,$0F

            sprites:
              .db $80, $00, $03, $80; Y pos, tile id, attributes, X pos
              '''

        tokens = lexical(code)
        ast = syntax(tokens)
        self.assertEquals(4, len(ast))
        self.assertEquals('S_DIRECTIVE', ast[0]['type'])
        self.assertEquals('.org', ast[0]['children'][0]['value'])
        self.assertEquals('S_DIRECTIVE', ast[1]['type'])
        self.assertEquals('.db', ast[1]['children'][0]['value'])
        self.assertEquals(['palette'], ast[1]['labels'])

        self.assertEquals('S_DIRECTIVE', ast[2]['type'])
        self.assertEquals('.db', ast[2]['children'][0]['value'])

        self.assertEquals('S_DIRECTIVE', ast[3]['type'])
        self.assertEquals('.db', ast[3]['children'][0]['value'])
        self.assertEquals(['sprites'], ast[3]['labels'])

        labels = get_labels(ast)
        expected = {'palette': 0xE000, 'sprites': 0xE000 + 32}

        self.assertEquals(expected, labels)
开发者ID:gabriel-ozeas,项目名称:pyNES,代码行数:32,代码来源:compiler_test.py


示例3: test_compile_list

    def test_compile_list(self):
        code = '''
            palette:
              .db $0F,$01,$02,$03,$04,$05,$06,$07,$08,$09,$0A,$0B,$0C,$0D,$0E,$0F
              .db $0F,$30,$31,$32,$33,$35,$36,$37,$38,$39,$3A,$3B,$3C,$3D,$3E,$0F
        '''
        tokens = lexical(code)
        ast = syntax(tokens)
        self.assertEquals(2, len(ast))

        self.assertEquals('S_DIRECTIVE', ast[0]['type'])
        self.assertEquals('.db', ast[0]['children'][0]['value'])
        self.assertEquals( 32, len(ast[0]['children']))
        palette1 = [0x0f, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
            0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]
        for i in range(len(palette1)):
            h = '$%02X' % palette1[i]
            self.assertEquals(h, ast[0]['children'][i * 2 + 1]['value'])
            self.assertEquals('S_DIRECTIVE', ast[1]['type'])

        self.assertEquals('S_DIRECTIVE', ast[1]['type'])
        self.assertEquals('.db', ast[0]['children'][0]['value'])
        self.assertEquals( 32, len(ast[1]['children']))
        palette2 = [0x0f, 0x30, 0x31, 0x32, 0x33, 0x35, 0x36, 0x37, 0x38, 0x39,
            0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x0f]
        for i in range(len(palette2)):
            h = '$%02X' % palette2[i]
            self.assertEquals(h, ast[1]['children'][i * 2 + 1]['value'])
开发者ID:gabriel-ozeas,项目名称:pyNES,代码行数:28,代码来源:compiler_test.py


示例4: test_bank_0

 def test_bank_0(self):
     tokens = list(lexical('.bank 0'))
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_DIRECTIVE', tokens[0]['type'])
     self.assertEquals('T_DECIMAL_ARGUMENT', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_DIRECTIVE', ast[0]['type'])
开发者ID:BmanisKing,项目名称:Mine,代码行数:8,代码来源:directive_test.py


示例5: test_ines_functions

 def test_ines_functions(self):
     example = """
         .inesprg 1   ; 1x 16KB PRG code
         .ineschr 1   ; 1x  8KB CHR data
         .inesmap 0   ; mapper 0 = NROM, no bank swapping
         .inesmir 1   ; VERT mirroring for HORIZ scrolling
         """
     tokens = lexical(example)
开发者ID:gabriel-ozeas,项目名称:pyNES,代码行数:8,代码来源:scrolling_test.py


示例6: test_org_fffa

 def test_org_fffa(self):
     tokens = list(lexical('.org $FFFA'))
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_DIRECTIVE', tokens[0]['type'])
     self.assertEquals('T_ADDRESS', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_DIRECTIVE', ast[0]['type'])
开发者ID:BmanisKing,项目名称:Mine,代码行数:8,代码来源:directive_test.py


示例7: test_example_5_14

    def test_example_5_14(self):
        example_5_14 = '''
        ; Example 5-14.  Simple 16-bit square root.
        ;
        ; Returns the 8-bit square root in $20 of the
        ; 16-bit number in $20 (low) and $21 (high). The
        ; remainder is in location $21.

        sqrt16: LDY #$01     ; lsby of first odd number = 1
                STY $22
                DEY
                STY $23      ; msby of first odd number (sqrt = 0)
        again:  SEC
                LDA $20      ; save remainder in X register
                TAX          ; subtract odd lo from integer lo
                SBC $22
                STA $20
                LDA $21      ; subtract odd hi from integer hi
                SBC $23
                STA $21      ; is subtract result negative?
                BCC nomore   ; no. increment square root
                INY
                LDA $22      ; calculate next odd number
                ADC #$01
                STA $22
                BCC again
                INC $23
                JMP again
        nomore: STY $20      ; all done, store square root
                STX $21      ; and remainder
                RTS
        '''
        tokens = lexical(example_5_14)
        self.assertEquals(74, len(tokens))
        
        self.assertEquals('T_ENDLINE', tokens[0]['type'])
        self.assertEquals('T_ENDLINE', tokens[1]['type'])
        self.assertEquals('T_ENDLINE', tokens[2]['type'])
        self.assertEquals('T_ENDLINE', tokens[3]['type'])
        self.assertEquals('T_ENDLINE', tokens[4]['type'])
        self.assertEquals('T_ENDLINE', tokens[5]['type'])
        self.assertEquals('T_ENDLINE', tokens[6]['type'])

        self.assertEquals('T_LABEL', tokens[7]['type'])
        self.assertEquals('T_INSTRUCTION', tokens[8]['type'])
        self.assertEquals('T_HEX_NUMBER', tokens[9]['type'])
        self.assertEquals('T_ENDLINE', tokens[10]['type'])

        self.assertEquals('T_INSTRUCTION', tokens[11]['type'])
        self.assertEquals('T_ADDRESS', tokens[12]['type'])
        self.assertEquals('T_ENDLINE', tokens[13]['type'])

        self.assertEquals('T_INSTRUCTION', tokens[14]['type'])
        self.assertEquals('T_ENDLINE', tokens[15]['type'])

        self.assertEquals('T_INSTRUCTION', tokens[16]['type'])
        self.assertEquals('T_ADDRESS', tokens[17]['type'])
        self.assertEquals('T_ENDLINE', tokens[18]['type'])
开发者ID:acs022,项目名称:pyNES,代码行数:58,代码来源:guide_test.py


示例8: test_sei_sngl

 def test_sei_sngl(self):
     tokens = list(lexical("SEI"))
     self.assertEquals(1, len(tokens))
     self.assertEquals("T_INSTRUCTION", tokens[0]["type"])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals("S_IMPLIED", ast[0]["type"])
     code = semantic(ast)
     self.assertEquals(code, [0x78])
开发者ID:BmanisKing,项目名称:Mine,代码行数:9,代码来源:sei_test.py


示例9: test_asm_compiler_scrolling_5

 def test_asm_compiler_scrolling_5(self):
     cart = Cartridge()
     cart.path = "fixtures/nesasm/scrolling/"
     f = open("fixtures/nesasm/scrolling/scrolling5.asm")
     code = f.read()
     f.close()
     tokens = lexical(code)
     ast = syntax(tokens)
     opcodes = semantic(ast, cart=cart)
开发者ID:gabriel-ozeas,项目名称:pyNES,代码行数:9,代码来源:scrolling_test.py


示例10: test_sed_sngl

 def test_sed_sngl(self):
     tokens = list(lexical('SED'))
     self.assertEquals(1, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_IMPLIED', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0xf8])
开发者ID:BmanisKing,项目名称:Mine,代码行数:9,代码来源:sed_test.py


示例11: test_rts_sngl

 def test_rts_sngl(self):
     tokens = lexical("RTS")
     self.assertEquals(1, len(tokens))
     self.assertEquals("T_INSTRUCTION", tokens[0]["type"])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals("S_IMPLIED", ast[0]["type"])
     code = semantic(ast)
     self.assertEquals(code, [0x60])
开发者ID:ickybodclay,项目名称:pyNES,代码行数:9,代码来源:rts_test.py


示例12: test_org_c000

 def test_org_c000(self):
     tokens = lexical('.org $C000')
     self.assertEquals(2 , len(tokens))
     self.assertEquals('T_DIRECTIVE', tokens[0]['type'])
     self.assertEquals('T_ADDRESS', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1 , len(ast))
     self.assertEquals('S_DIRECTIVE', ast[0]['type'])
     code = semantic(ast)
开发者ID:acs022,项目名称:pyNES,代码行数:9,代码来源:directive_test.py


示例13: test_cmp_imm

 def test_cmp_imm(self):
     tokens = list(lexical('CMP #$10'))
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_HEX_NUMBER', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_IMMEDIATE', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0xc9, 0x10])
开发者ID:BmanisKing,项目名称:Mine,代码行数:10,代码来源:cmp_test.py


示例14: test_bit_zp

 def test_bit_zp(self):
     tokens = lexical("BIT $00")
     self.assertEquals(2, len(tokens))
     self.assertEquals("T_INSTRUCTION", tokens[0]["type"])
     self.assertEquals("T_ADDRESS", tokens[1]["type"])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals("S_ZEROPAGE", ast[0]["type"])
     code = semantic(ast)
     self.assertEquals(code, [0x24, 0x00])
开发者ID:ickybodclay,项目名称:pyNES,代码行数:10,代码来源:bit_test.py


示例15: test_lsr_acc

 def test_lsr_acc(self):
     tokens = lexical("LSR A")
     self.assertEquals(2, len(tokens))
     self.assertEquals("T_INSTRUCTION", tokens[0]["type"])
     self.assertEquals("T_ACCUMULATOR", tokens[1]["type"])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals("S_ACCUMULATOR", ast[0]["type"])
     code = semantic(ast)
     self.assertEquals(code, [0x4A])
开发者ID:ickybodclay,项目名称:pyNES,代码行数:10,代码来源:lsr_test.py


示例16: test_lsr_imm_with_decimal

 def test_lsr_imm_with_decimal(self):
     tokens = lexical("LSR #10")
     self.assertEquals(2, len(tokens))
     self.assertEquals("T_INSTRUCTION", tokens[0]["type"])
     self.assertEquals("T_DECIMAL_NUMBER", tokens[1]["type"])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals("S_IMMEDIATE", ast[0]["type"])
     code = semantic(ast)
     self.assertEquals(code, [0x4A, 0x0A])
开发者ID:ickybodclay,项目名称:pyNES,代码行数:10,代码来源:lsr_test.py


示例17: test_lsr_acc

 def test_lsr_acc(self):
     tokens = list(lexical('LSR A'))
     self.assertEquals(2, len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_ACCUMULATOR', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals('S_ACCUMULATOR', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x4a])
开发者ID:BmanisKing,项目名称:Mine,代码行数:10,代码来源:lsr_test.py


示例18: test_lsr_imm_with_binary

 def test_lsr_imm_with_binary(self):
     tokens = lexical("LSR #%00000100")
     self.assertEquals(2, len(tokens))
     self.assertEquals("T_INSTRUCTION", tokens[0]["type"])
     self.assertEquals("T_BINARY_NUMBER", tokens[1]["type"])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals("S_IMMEDIATE", ast[0]["type"])
     code = semantic(ast)
     self.assertEquals(code, [0x4A, 0x04])
开发者ID:ickybodclay,项目名称:pyNES,代码行数:10,代码来源:lsr_test.py


示例19: test_bne_rel

 def test_bne_rel(self):
     tokens = lexical("BNE $10")
     self.assertEquals(2, len(tokens))
     self.assertEquals("T_INSTRUCTION", tokens[0]["type"])
     self.assertEquals("T_ADDRESS", tokens[1]["type"])
     ast = syntax(tokens)
     self.assertEquals(1, len(ast))
     self.assertEquals("S_RELATIVE", ast[0]["type"])
     code = semantic(ast)
     self.assertEquals(code, [0xD0, 0x0E])
开发者ID:ickybodclay,项目名称:pyNES,代码行数:10,代码来源:bne_test.py


示例20: test_bpl_rel

 def test_bpl_rel(self):
     tokens = lexical('BPL $10')
     self.assertEquals(2 , len(tokens))
     self.assertEquals('T_INSTRUCTION', tokens[0]['type'])
     self.assertEquals('T_ADDRESS', tokens[1]['type'])
     ast = syntax(tokens)
     self.assertEquals(1 , len(ast))
     self.assertEquals('S_RELATIVE', ast[0]['type'])
     code = semantic(ast)
     self.assertEquals(code, [0x10, 0x0e])
开发者ID:acs022,项目名称:pyNES,代码行数:10,代码来源:bpl_test.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python compiler.semantic函数代码示例发布时间:2022-05-27
下一篇:
Python pynebula.lookup函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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