Changeset 182
- Timestamp:
- Jan 24, 2008, 3:39:13 PM (18 years ago)
- Author:
- neil.c.c.brown
- Message:
-
Added most of the section explaining how A.Structured works
- File:
-
- 1 edited
- docs/trunk/hacking-guide/tock-intro.tex (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
docs/trunk/hacking-guide/tock-intro.tex
r181 r182 77 77 \subsection{A.Structured} 78 78 79 %TODO 79 The main item in the AST that I (Neil) found confusing at first was the Structured item. In case it 80 confuses anyone else I thought I would explain it here. Structured is the body of most occam constructs, 81 such as SEQ, PAR, ALT, CASE. Because occam allows the inter-mingling of processes and declarations, 82 and also replication on most of its constructs (SEQ, PAR, ALT, IF) Structured eliminates redundancy 83 by grouping this together. So for example, given this occam psuedo-code: 84 85 \occamsettings\begin{lstlisting} 86 SEQ 87 proc1 88 proc2 89 \end{lstlisting} 90 91 Here is how it would be represented in the AST (Taking proc1 and proc2 to be of type Process, and using 92 `m' for all meta-tags): 93 94 \haskellsettings\begin{lstlisting} 95 A.Seq m 96 (A.Several m 97 [A.OnlyP m proc1 98 ,A.OnlyP m proc2 99 ] 100 ) 101 \end{lstlisting} 102 103 You can see the combination of Seq with Several and OnlyP to nest the processes. Here's another example 104 of some occam and corresponding Haskell: 105 106 \occamsettings\begin{lstlisting} 107 SEQ 108 proc1 109 PAR 110 proc2 111 proc3 112 \end{lstlisting} 113 114 \haskellsettings\begin{lstlisting} 115 A.Seq m 116 (A.Several m 117 [A.OnlyP m proc1 118 ,A.OnlyP m 119 (A.Par m A.PlainPar 120 (A.Several m 121 [A.OnlyP m proc2 122 ,A.OnlyP m proc3 123 ] 124 ) 125 ) 126 ] 127 ) 128 \end{lstlisting} 129 130 Which no doubt looks quite nasty! But things work differently if you nest two blocks of the same type, 131 mainly because of the associativity of the various blocks in occam. Consider these two SEQ blocks: 132 133 \occamsettings\begin{lstlisting} 134 SEQ 135 proc1 136 SEQ 137 proc2 138 proc3 139 \end{lstlisting} 140 141 \haskellsettings\begin{lstlisting} 142 A.Seq m 143 (A.Several m 144 [A.OnlyP m proc1 145 , (A.Several m 146 [A.OnlyP m proc2 147 ,A.OnlyP m proc3 148 ] 149 ) 150 ] 151 ) 152 \end{lstlisting} 153 154 You can see that instead of creating a second \lstinline|A.Seq| inside the \lstinline|A.Several|, it 155 has instead simply nested another \lstinline|A.Several|. In fact, we could later flatten the two 156 nested \lstinline|A.Several|s into one if we wanted. 157 158 Here is another example: 159 160 \occamsettings\begin{lstlisting} 161 PAR 162 proc1 163 PAR i = 0 FOR 10 164 proc2 165 \end{lstlisting} 166 167 \haskellsettings\begin{lstlisting} 168 A.Par m A.PlainPar 169 (A.Several m 170 [A.OnlyP m proc1 171 ,A.Rep m rep (A.OnlyP m proc2) 172 ] 173 ) 174 \end{lstlisting} 175 176 I have used `rep' as a short-hand for the replicator (which is not the focus here). Hopefully it is 177 now clear how Structured is used as a body for things. There is only one more aspect to explain, 178 which is definitions. 179 180 %TODO explain definitions 80 181 81 182 \subsection{Monadic Code}
Note:
See TracChangeset
for help on using the changeset viewer.