source: docs/Working/icGrep/scripts/bitwisefig.py @ 4493

Last change on this file since 4493 was 4488, checked in by cameron, 5 years ago

Initial bitwise example, table placeholder

File size: 1.9 KB
Line 
1#
2#  bitwisefig.py
3
4
5import pablo
6
7import sys
8
9zero_ch = '.'
10
11
12class Basis_bits():     
13        bit_0 = 0
14        bit_1 = 0
15        bit_2 = 0
16        bit_3 = 0
17        bit_4 = 0
18        bit_5 = 0
19        bit_6 = 0
20        bit_7 = 0
21
22
23class Lex ():
24        az = 0
25        d = 0
26        e = 0
27
28def do_lex(basis_bits, lex):
29        temp1 = (basis_bits.bit_1 &~ basis_bits.bit_0)
30        temp2 = (basis_bits.bit_2 &~ basis_bits.bit_3)
31        temp3 = (temp1 & temp2)
32        temp4 = (basis_bits.bit_5 &~ basis_bits.bit_4)
33        temp5 = (basis_bits.bit_6 | basis_bits.bit_7)
34        temp6 = (temp4 &~ temp5)
35        lex.d = (temp3 & temp6)
36        temp7 = (basis_bits.bit_7 &~ basis_bits.bit_6)
37        temp8 = (temp4 & temp7)
38        lex.e = (temp3 & temp8)
39        temp9 = (temp1 & basis_bits.bit_2)
40        temp10 = (basis_bits.bit_6 & basis_bits.bit_7)
41        temp11 = (basis_bits.bit_5 | temp10)
42        temp12 = (basis_bits.bit_4 & temp11)
43        temp13 = (~temp12)
44        temp14 = (basis_bits.bit_4 | basis_bits.bit_5)
45        temp15 = (temp14 | temp5)
46        temp16 = ((basis_bits.bit_3 & temp13)|(~(basis_bits.bit_3) & temp15))
47        lex.az = (temp9 & temp16)
48
49
50
51def latex_streams1(chardata):
52        lgth = len(chardata)
53        basis_bits = Basis_bits()
54        lex = Lex()
55        pablo.EOF_mask = pablo.transpose_streams(chardata, basis_bits)
56        do_lex(basis_bits, lex)
57        M1 = pablo.Advance(lex.d)
58        M2 = pablo.MatchStar(M1, lex.az)
59        M3 = pablo.Advance(M2 & lex.e)
60        M4 = pablo.Advance(M3 & lex.d)
61        return pablo.latex_streams([('input data ', chardata), 
62              ('$M_1 = {\\text{Advance}}({\\text{\\tt [d]}})$', pablo.bitstream2string(M1, lgth, zero_ch)),
63              ('$M_2 = {\\text{MatchStar}}(M_1, {\\text{\\tt [a-z]}})$', pablo.bitstream2string(M2, lgth, zero_ch)),
64              ('$M_3 = {\\text{Advance}}(M_2 \wedge {\\text{\\tt [e]}})$', pablo.bitstream2string(M3, lgth, zero_ch)),
65              ('$M_4 = {\\text{Advance}}(M_3 \wedge {\\text{\\tt [d]}})$', pablo.bitstream2string(M4, lgth, zero_ch))])
66
67
68
69
70if __name__ == "__main__":
71        #data = r"""a4534q--b29z---az---a4q--bca22z--"""
72        data = r"""dead dreams defeated."""
73        print latex_streams1(data)
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
Note: See TracBrowser for help on using the repository browser.