Context Navigation



Ignore:
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

Legend:

Unmodified
Added
Removed
  • docs/trunk/hacking-guide/tock-intro.tex

    r181 r182
    7777\subsection{A.Structured}
    7878
    79%TODO
    79The main item in the AST that I (Neil) found confusing at first was the Structured item. In case it
    80confuses anyone else I thought I would explain it here. Structured is the body of most occam constructs,
    81such as SEQ, PAR, ALT, CASE. Because occam allows the inter-mingling of processes and declarations,
    82and also replication on most of its constructs (SEQ, PAR, ALT, IF) Structured eliminates redundancy
    83by grouping this together. So for example, given this occam psuedo-code:
    84
    85\occamsettings\begin{lstlisting}
    86SEQ
    87 proc1
    88 proc2
    89\end{lstlisting}
    90
    91Here 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}
    95A.Seq m
    96 (A.Several m
    97 [A.OnlyP m proc1
    98 ,A.OnlyP m proc2
    99 ]
    100 )
    101\end{lstlisting}
    102
    103You can see the combination of Seq with Several and OnlyP to nest the processes. Here's another example
    104of some occam and corresponding Haskell:
    105
    106\occamsettings\begin{lstlisting}
    107SEQ
    108 proc1
    109 PAR
    110 proc2
    111 proc3
    112\end{lstlisting}
    113
    114\haskellsettings\begin{lstlisting}
    115A.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
    130Which no doubt looks quite nasty! But things work differently if you nest two blocks of the same type,
    131mainly because of the associativity of the various blocks in occam. Consider these two SEQ blocks:
    132
    133\occamsettings\begin{lstlisting}
    134SEQ
    135 proc1
    136 SEQ
    137 proc2
    138 proc3
    139\end{lstlisting}
    140
    141\haskellsettings\begin{lstlisting}
    142A.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
    154You can see that instead of creating a second \lstinline|A.Seq| inside the \lstinline|A.Several|, it
    155has instead simply nested another \lstinline|A.Several|. In fact, we could later flatten the two
    156nested \lstinline|A.Several|s into one if we wanted.
    157
    158Here is another example:
    159
    160\occamsettings\begin{lstlisting}
    161PAR
    162 proc1
    163 PAR i = 0 FOR 10
    164 proc2
    165\end{lstlisting}
    166
    167\haskellsettings\begin{lstlisting}
    168A.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
    176I have used `rep' as a short-hand for the replicator (which is not the focus here). Hopefully it is
    177now clear how Structured is used as a body for things. There is only one more aspect to explain,
    178which is definitions.
    179
    180%TODO explain definitions
    80181
    81182\subsection{Monadic Code}
Note: See TracChangeset for help on using the changeset viewer.

AltStyle によって変換されたページ (->オリジナル) /