最近有空吧代码读取的部分做了,第一次给这个写真正意义上的程序(在vga上显示一个句号)
顺便做了一个编译器
以下为图片
<span style="color:rgb(169, 183, 198);">plist = [<span style="color:#6a8759;">"NON"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"ACP"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"AMR"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"STL"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"STR"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"LDM"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"BLLD"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"BHLD"</span><span style="color:#cc7832;">,<br></span><span style="color:#cc7832;"> </span><span style="color:#6a8759;">"AILD"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"MLD"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"STC"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"CLC"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"REC"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"NF"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"CAI"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"CLD"</span><span style="color:#cc7832;">,<br></span><span style="color:#cc7832;"> </span><span style="color:#6a8759;">"PCLLD"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"PCMLD"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"PCHLD"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"INTE"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"RD"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"WT"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"INTU"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"GED"</span><span style="color:#cc7832;">,<br></span><span style="color:#cc7832;"> </span><span style="color:#6a8759;">"JMP"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"HLT"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"JC"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"JNC"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"JZ"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"JNZ"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"JV"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"JNV"</span><span style="color:#cc7832;">,<br></span><span style="color:#cc7832;"> </span><span style="color:#6a8759;">"RET"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"RESTC"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"LDCL"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"LDCH"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"FINT3"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"MMULD"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"CLD"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"DLD"</span><span style="color:#cc7832;">,<br></span><span style="color:#cc7832;"> </span><span style="color:#6a8759;">""</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">""</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">""</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">""</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">""</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">""</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">""</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">""</span><span style="color:#cc7832;">,<br></span><span style="color:#cc7832;"> </span><span style="color:#6a8759;">""</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">""</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">""</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">""</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">""</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">""</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">""</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">""</span><span style="color:#cc7832;">,<br></span><span style="color:#cc7832;"> </span><span style="color:#6a8759;">"SAM"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"IVS"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"WVGA"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"YP"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"LXB"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"LX"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"LYB"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"LY"</span>]<br>olist = [<span style="color:#6a8759;">"BUSO"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"PCLO"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"PCMO"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"PCHO"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"UO"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"DO"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"AOO"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"ACO"</span><span style="color:#cc7832;">,<br></span><span style="color:#cc7832;"> </span><span style="color:#6a8759;">"CO"</span><span style="color:#cc7832;">, </span><span style="color:#6a8759;">"DO"</span>]<br>m = <span style="color:#6897bb;">0<br></span>fpath = </span><font color="#6a8759">input()</font><span style="color:rgb(106, 135, 89);"><br></span><span style="color:rgb(204, 120, 50);">with </span><font color="#a9b7c6">open(fpath</font><span style="color:rgb(204, 120, 50);">, </span><span style="color:rgb(106, 135, 89);">"r"</span><font color="#a9b7c6">) </font><span style="color:rgb(204, 120, 50);">as </span><font color="#a9b7c6">file:<br> lines = file.readlines()<br> </font><span style="color:rgb(204, 120, 50);">for </span><font color="#a9b7c6">i </font><span style="color:rgb(204, 120, 50);">in </span><font color="#a9b7c6">range(len(lines)):<br> lines[i] = lines[i].split()<br><br></font><span style="color:rgb(204, 120, 50);">def </span><font color="#a9b7c6">findins(ins):<br> </font><span style="color:rgb(204, 120, 50);">global </span><font color="#a9b7c6">plist<br> </font><span style="color:rgb(204, 120, 50);">global </span><font color="#a9b7c6">m<br> </font><span style="color:rgb(204, 120, 50);">try</span><font color="#a9b7c6">:<br> i = plist.index(ins)<br> m = </font><span style="color:rgb(104, 151, 187);">0<br></span><span style="color:rgb(104, 151, 187);"> </span><span style="color:rgb(204, 120, 50);">except </span><font color="#a9b7c6">ValueError:<br> i = olist.index(ins)<br> m = </font><span style="color:rgb(104, 151, 187);">1<br></span><span style="color:rgb(104, 151, 187);"> </span><span style="color:rgb(204, 120, 50);">return </span><font color="#a9b7c6">i<br></font><span style="color:rgb(204, 120, 50);">def </span><font color="#a9b7c6">delline(line):<br> outline = </font><span style="color:rgb(106, 135, 89);">""<br></span><span style="color:rgb(106, 135, 89);"><br></span><span style="color:rgb(106, 135, 89);"> </span><font color="#a9b7c6">ins = hex(findins(line[</font><span style="color:rgb(104, 151, 187);">0</span><font color="#a9b7c6">])).replace(</font><span style="color:rgb(106, 135, 89);">"0x"</span><span style="color:rgb(204, 120, 50);">, </span><span style="color:rgb(106, 135, 89);">""</span><font color="#a9b7c6">)<br><br> </font><span style="color:rgb(204, 120, 50);">if </span><font color="#a9b7c6">len(line) == </font><span style="color:rgb(104, 151, 187);">2</span><font color="#a9b7c6">:<br> ins = gethex(ins</font><span style="color:rgb(204, 120, 50);">, </span><font color="#a9b7c6">m</font><span style="color:rgb(204, 120, 50);">, </span><span style="color:rgb(104, 151, 187);">1</span><font color="#a9b7c6">)<br> outline += (ins + </font><span style="color:rgb(106, 135, 89);">","</span><font color="#a9b7c6">)<br> num = hex(int(line[</font><span style="color:rgb(104, 151, 187);">1</span><font color="#a9b7c6">])).replace(</font><span style="color:rgb(106, 135, 89);">"0x"</span><span style="color:rgb(204, 120, 50);">, </span><span style="color:rgb(106, 135, 89);">""</span><font color="#a9b7c6">)<br> </font><span style="color:rgb(204, 120, 50);">if </span><font color="#a9b7c6">len(num) == </font><span style="color:rgb(104, 151, 187);">1</span><font color="#a9b7c6">:<br> num = </font><span style="color:rgb(106, 135, 89);">"0"</span><font color="#a9b7c6">+num<br> outline += (num + </font><span style="color:rgb(106, 135, 89);">","</span><font color="#a9b7c6">)<br><br> </font><span style="color:rgb(204, 120, 50);">else</span><font color="#a9b7c6">:<br> ins = gethex(ins</font><span style="color:rgb(204, 120, 50);">, </span><font color="#a9b7c6">m</font><span style="color:rgb(204, 120, 50);">, </span><span style="color:rgb(104, 151, 187);">0</span><font color="#a9b7c6">)<br> outline += (ins + </font><span style="color:rgb(106, 135, 89);">","</span><font color="#a9b7c6">)<br> </font><span style="color:rgb(204, 120, 50);">if </span><font color="#a9b7c6">len(line) == </font><span style="color:rgb(104, 151, 187);">2</span><font color="#a9b7c6">:<br> print(line[</font><span style="color:rgb(104, 151, 187);">0</span><font color="#a9b7c6">] +</font><span style="color:rgb(106, 135, 89);">" " </span><font color="#a9b7c6">+ line[</font><span style="color:rgb(104, 151, 187);">1</span><font color="#a9b7c6">] +</font><span style="color:rgb(106, 135, 89);">" -> " </span><font color="#a9b7c6">+ outline)<br> </font><span style="color:rgb(204, 120, 50);">elif </span><font color="#a9b7c6">len (line) == </font><span style="color:rgb(104, 151, 187);">1</span><font color="#a9b7c6">:<br> print(line[</font><span style="color:rgb(104, 151, 187);">0</span><font color="#a9b7c6">] + </font><span style="color:rgb(106, 135, 89);">" -> " </span><font color="#a9b7c6">+ outline)<br> </font><span style="color:rgb(204, 120, 50);">return </span><font color="#a9b7c6">outline<br></font><span style="color:rgb(204, 120, 50);">def </span><font color="#a9b7c6">gethex(ins</font><span style="color:rgb(204, 120, 50);">, </span><font color="#a9b7c6">m</font><span style="color:rgb(204, 120, 50);">, </span><font color="#a9b7c6">n):<br> </font><span style="color:rgb(204, 120, 50);">if </span><font color="#a9b7c6">len(ins) == </font><span style="color:rgb(104, 151, 187);">1</span><font color="#a9b7c6">:<br> ins = </font><span style="color:rgb(106, 135, 89);">"0"</span><font color="#a9b7c6">+ins<br> ins = hex(int(ins[</font><span style="color:rgb(104, 151, 187);">0</span><font color="#a9b7c6">])+</font><span style="color:rgb(104, 151, 187);">8</span><font color="#a9b7c6">*n+</font><span style="color:rgb(104, 151, 187);">4</span><font color="#a9b7c6">*m).replace(</font><span style="color:rgb(106, 135, 89);">"0x"</span><span style="color:rgb(204, 120, 50);">, </span><span style="color:rgb(106, 135, 89);">""</span><font color="#a9b7c6">)+ins[</font><span style="color:rgb(104, 151, 187);">1</span><font color="#a9b7c6">:</font><span style="color:rgb(104, 151, 187);">2</span><font color="#a9b7c6">]<br> </font><span style="color:rgb(204, 120, 50);">return </span><font color="#a9b7c6">ins<br><br>outlines = </font><span style="color:rgb(106, 135, 89);">""<br></span><span style="color:rgb(204, 120, 50);">for </span><font color="#a9b7c6">line </font><span style="color:rgb(204, 120, 50);">in </span><font color="#a9b7c6">lines:<br> </font><span style="color:rgb(204, 120, 50);">if </span><font color="#a9b7c6">len(line) != </font><span style="color:rgb(104, 151, 187);">0</span><font color="#a9b7c6">:<br> outlines += delline(line)<br>print(outlines[</font><span style="color:rgb(104, 151, 187);">0</span><font color="#a9b7c6">:len(outlines)-</font><span style="color:rgb(104, 151, 187);">1</span><font color="#a9b7c6">])<br>print(outlines.replace(</font><span style="color:rgb(106, 135, 89);">","</span><span style="color:rgb(204, 120, 50);">, </span><span style="color:rgb(106, 135, 89);">" "</span><font color="#a9b7c6">))<br><br>NON<br>NON 127<br>LXB<br>LX 119<br>LYB<br>LY<br>NON 255<br>WVGA <br>WVGA 126 <br>LXB<br>LX 120<br>LYB <br>LY 255<br>WVGA 129<br>LXB<br>LX 255<br>WVGA 126 <br>LXB<br>LX 121<br>LYB <br>LY 255<br>WVGA 129<br>LXB<br>LX 255<br>WVGA 127<br>LXB <br>LX 122<br>LYB<br>LY 255<br>WVGA<br>WVGA<br>IVS<br>JMP<br></font>
电路文件(瞎取的):
图片:
时段 | 个数 |
---|---|
{{f.startingTime}}点 - {{f.endTime}}点 | {{f.fileCount}} |