dikke update
[cc1516.git] / deliverables / report / pars.tex
index 56fe1f7..d64ec69 100644 (file)
@@ -139,3 +139,66 @@ parseFunDecl = liftM6 FunDecl
        (satTok CBraceOpenToken *> many parseVarDecl)
        (flatten <$> (many parseStmt <* satTok CBraceCloseToken))
 \end{lstlisting}
+
+\subsection{Sugars}
+Some syntactic sugars are procesessed in the lexing or parsing phase. Entering
+literal lists and strings is a tedious job because you can only glue them
+together with cons opererators. Thus we introduced a literal lists notation as
+visible in the grammar. Literal strings are lex as single tokens and expanded
+during parsing in to normal lists of characters. Literal lists are processed in
+the parsing phase and expanded to their similar form with the \texttt{Cons}
+operator. An example of this is shown in Listing~\ref{lst:litlist}
+
+\begin{lstlisting}[
+       language=SPLCode,
+       caption={Literal lists},
+       label={lst:litlist}]
+//Before transformation
+var a = "Hello world!";
+var b = [3, 1, 4, 1, 5];
+
+//After transformation
+var a = 'H':'e':'l':'l':'o':' ':'w':'o':'r':'l':'d':'!':[]
+var b = 3 : 1 : 4 : 1 : 5 : [];
+\end{lstlisting}
+
+Another sugar added is variable arguments printing. To enable the user to
+pretty print data the number of arguments of the \SI{print} function is not
+fixed and it is expanded at compiletime. With this sugar the programmer can
+print several different types in one line. Listing~\ref{lst:varprint} shows an
+example of the sugar. In the semantic analysis phase these statements are
+actually refined even more to represent the specific print function per type
+since the compiler allows printing of \SI{Int}, \SI{Bool}, \SI{Char} and
+\SI{[Char]}
+\begin{lstlisting}[
+       language=SPLCode,
+       caption={Variable arguments printing},
+       label={lst:varprint}]
+//Before transformation
+print("abc", 42, 'c', "da\n");
+
+//After transformation
+print('a':'b':'c':[]);
+print(42);
+print('c');
+print('d':'a':'\n':[]);
+\end{lstlisting}
+
+The last sugar processed in the parsing or lexing phase are the \SI{let}
+constructions. These constructions provide an easy way of defining global
+constants without real constants. While we do not allow global variables one
+might want to introduce global constants and with these constructs this can be
+done very easily. Listing~\ref{lst:letgl} shows the expansion of \SI{let}
+declarations.
+\begin{lstlisting}[
+       language=SPLCode,
+       caption={\SI{let} expansion},
+       label={lst:letgl}]
+//Before transformation
+let Int x = 42;
+
+//After transformation
+x() :: -> Int{
+       return 42;
+}
+\end{lstlisting}