source: proto/RE/output/re_debug.py @ 3076

Last change on this file since 3076 was 3076, checked in by ksherdy, 6 years ago

Updated grammar to handle '$'. Added lower bound / upper bound attributes.

File size: 1.9 KB
Line 
1# -*- coding: utf-8 -*-
2#
3# prototype.py template
4#
5# Ken Herdy
6# April 20, 2010
7#
8#----------------------------------------------------------------------------
9#
10# (at)lex_strms - Lexical Item Streams.
11# (at)cc_code   - Character Class compiler equations.
12# (at)pbs_code  - Parallel bit stream equations.
13# (at)pbs_debug - Parallel bit stream debug statements.
14#
15#----------------------------------------------------------------------------
16
17import sys
18import bitutil
19
20u8data = ""
21lgth = 0
22
23class Basis_bits():
24        bit_0 = 0
25        bit_1 = 0
26        bit_2 = 0
27        bit_3 = 0 
28        bit_4 = 0
29        bit_5 = 0
30        bit_6 = 0
31        bit_7 = 0 
32 
33class Lex():
34
35        cc0 = (0)
36        cc1 = (0)
37        cc2 = (0)
38        cc3 = (0)
39        cc4 = (0)
40        LF = (0) 
41
42def Classify_bytes(basis_bits,lex):
43@cc_code
44        return lex
45
46def Demo(u8data, lex):
47
48        global lgth
49        lgth = len(u8data)
50        m0=0
51        m0=~0
52        m0 = bitutil.Advance((m0 & lex.cc0))
53        m0 = bitutil.Advance((m0 & lex.cc1))
54        m0 = bitutil.Advance((m0 & lex.cc2))
55        m0 = bitutil.Advance((m0 & lex.cc3))
56        m0 = bitutil.Advance((m0 & lex.cc4))
57        bitutil.print_aligned_streams([('       Input Data', u8data),
58        ('      lex.cc0', bitutil.bitstream2string(lex.cc0, lgth+1)),
59        ('      lex.cc1', bitutil.bitstream2string(lex.cc1, lgth+1)),
60        ('      lex.cc2', bitutil.bitstream2string(lex.cc2, lgth+1)),
61        ('      lex.cc3', bitutil.bitstream2string(lex.cc3, lgth+1)),
62        ('      lex.cc4', bitutil.bitstream2string(lex.cc4, lgth+1)),
63        ('      m0', bitutil.bitstream2string(m0, lgth+1))])
64        return
65
66if __name__ == "__main__":
67        import doctest
68        doctest.testmod()
69
70        if len(sys.argv) < 2:
71                sys.stderr.write("Usage: python " + __file__ + " <filename>" "\n")
72                sys.exit(2)
73
74        u8data = bitutil.readfile(sys.argv[1])
75        (bits, EOF_mask) = bitutil.transpose_streams(u8data)
76       
77        basis_bits = Basis_bits()
78        basis_bits.bit_0 = bits[0]
79        basis_bits.bit_1 = bits[1]
80        basis_bits.bit_2 = bits[2]
81        basis_bits.bit_3 = bits[3]
82        basis_bits.bit_4 = bits[4]
83        basis_bits.bit_5 = bits[5]
84        basis_bits.bit_6 = bits[6]
85        basis_bits.bit_7 = bits[7]
86       
87        lex = Lex()
88        Classify_bytes(basis_bits, lex)
89        Demo(u8data, lex)
Note: See TracBrowser for help on using the repository browser.