statemachine: parser und noch ein paar kleiner fixes
[hwmod.git] / spec / sm / parser.tex
1 \documentclass{minimal}
2 \pagestyle{empty}
3
4 \usepackage{pstricks}
5 \usepackage{pst-node}
6
7 \begin{document}
8
9 \begin{psmatrix}[mnode=oval, colsep=1.91cm, rowsep=1cm]
10 [mnode=R,name=vars]{\shortstack[l]{bool s=F,first=T;\\int z:=0, c,\\\, strich:=0, punkt:=1;\\opcode
11 op,opn;}} &
12 [name=calc]{\shortstack{\textbf{calc}\\z:=z*10\\+(c-'0');}} &
13 [name=null]{\shortstack{\textbf{null}\\op:=DONE;}} \\
14 %%
15 [mnode=R,name=res]{sys\_res} &
16 [name=sign]{\shortstack{\textbf{sign}\\s:=true;}} &
17 [name=alu1]{
18         \shortstack{
19                 \textbf{ALU1}\\
20                 \shortstack[l]{
21                         if(first)\{\\
22                                 \, alu(ADD,z*s,strich);\\
23                                 \, first:=false;\\
24                         \} else\{\\
25                                 \, alu(opd,z*s,strich);\\
26                         \}\\
27                         do\_calc=1;\\
28                         opn=op;
29                 }
30         }
31 } \\
32 %%
33 [name=idle]{\shortstack{\textbf{idle}}} &
34 [name=read]{\shortstack{\textbf{read char}\\z:=0;\\s:=false;}} &
35 [name=alu2]{
36         \shortstack{
37                 \textbf{ALU2}\\
38                 \shortstack[l]{
39                         if(first)\{\\
40                                 \, alu(MUL,z*s,punkt);\\
41                                 \, first:=false;\\
42                         \} else\{\\
43                                 \, alu(opd,z*s,punkt);\\
44                         \}\\
45                         do\_calc=1;\\
46                         opn=op;
47                 }
48         }
49 } \\
50 %%
51 [mnode=R,name=void]{} &
52 [name=err]{\shortstack{\textbf{error}}} &
53 [name=done]{\shortstack{\textbf{done}}} \\
54 \end{psmatrix}
55
56 \psset{arrows=->, shortput=nab}
57
58 \ncline[linestyle=dotted]{res}{idle}
59 \ncline[linestyle=dotted]{void}{err}
60 \ncarc[arcangle=10]{done}{idle}
61 \ncarc[arcangle=0]{err}{idle}
62
63 \ncarc[arcangle=0]{idle}{read}\ncput*[npos=.50]{do\_it$\uparrow$}
64
65 \ncarc[arcangle=0]{read}{sign}\ncput*[npos=.50]{'-'}
66 \ncarc[arcangle=0]{sign}{calc}
67 \ncarc[arcangle=35]{read}{calc}\ncput*[npos=.35]{c = '0'\dots{}'9'}
68 \nccircle[angle=0]{calc}{.8cm}\ncput*{c = '0'\dots{}'9'}
69
70 \ncarc[arcangle=15]{calc}{alu1}\ncput*[npos=.50]{op = '+','-'}
71 \ncarc[arcangle=-5]{calc}{alu2}\ncput*[npos=.30]{op = '*','/'}
72
73 \ncarc[arcangle=0]{calc}{null}\ncput*[npos=.50]{'\textbackslash 0'}
74
75 \ncarc[arcangle=0]{null}{alu1}\ncput*[npos=.50]{opd in ['+','-']}
76 \ncarc[arcangle=48]{null}{alu2}\ncput*[npos=.80]{opd in ['*','/']}
77
78 \ncarc[arcangle=0]{alu1}{read}\ncput*[npos=.50]{calc\_done$\uparrow$}
79 \ncarc[arcangle=20]{alu2}{read}\ncput*[npos=.50]{calc\_done$\uparrow$}
80
81 \ncarc[arcangle=80]{alu1}{done}\ncput*[npos=.50]{op == DONE}
82 \ncarc[arcangle=-60]{alu2}{done}\ncput*[npos=.66]{op == DONE}
83 \end{document}