From 6c6171685fbcc7b7ba4bf1e16973f32de2b887d7 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Thu, 9 Jun 2016 12:21:53 +0200 Subject: [PATCH] update intro en spl --- deliverables/report/Makefile | 2 +- deliverables/report/ext.tex | 2 +- deliverables/report/gen.tex | 2 +- deliverables/report/intro.tex | 67 ++++++++++++++++++++++++++++++++++ deliverables/report/pars.tex | 2 +- deliverables/report/report.tex | 34 +++++------------ deliverables/report/sem.tex | 2 +- spl.icl | 2 - 8 files changed, 81 insertions(+), 32 deletions(-) create mode 100644 deliverables/report/intro.tex diff --git a/deliverables/report/Makefile b/deliverables/report/Makefile index b0df60a..875fa2b 100644 --- a/deliverables/report/Makefile +++ b/deliverables/report/Makefile @@ -6,7 +6,7 @@ DOCUMENT:=report all: $(DOCUMENT).pdf -%.pdf: %.tex ext.tex gen.tex pars.tex sem.tex +%.pdf: %.tex ext.tex gen.tex pars.tex sem.tex intro.tex $(LATEX) $(LATEXFLAGS) $< $(LATEX) $(LATEXFLAGS) $< diff --git a/deliverables/report/ext.tex b/deliverables/report/ext.tex index 0491bc7..70ae2f6 100644 --- a/deliverables/report/ext.tex +++ b/deliverables/report/ext.tex @@ -1,4 +1,4 @@ -\section{Extensions} +\section{Extensions}\label{sec:ext} \subsection{Higher order functions} The nature of the type checking algorithm already included type checking and inferring the type of higher order functions. Since we allow constants there is diff --git a/deliverables/report/gen.tex b/deliverables/report/gen.tex index 5496982..0edfd92 100644 --- a/deliverables/report/gen.tex +++ b/deliverables/report/gen.tex @@ -1,4 +1,4 @@ -\section{Code generation} +\section{Code generation}\label{sec:gen} %our full names and student numbers. %{ %The chapters from the previous exercise. diff --git a/deliverables/report/intro.tex b/deliverables/report/intro.tex new file mode 100644 index 0000000..c333738 --- /dev/null +++ b/deliverables/report/intro.tex @@ -0,0 +1,67 @@ +\section{Introduction} +\subsection{\SPLC} +\SPLC{} is a program written in the purely functional lazy programming language +Clean\footnote{\url{http://clean.cs.ru.nl/Clean}}. \SPLC{} has a standardized +UNIX like command line interface and functions as a filter in a way that it +processes standard input in standard output. Default command line argument such +as \texttt{--version} and \texttt{--help} provide the expected output. To +illustrate all the command line interface options the output of \texttt{spl +--help} is given in Listing~\ref{lst:splchelp}. + +\begin{lstlisting}[ + label={lst:splchelp}, + caption={\texttt{./spl -h}}] +Usage: spl [OPTION] [FILE] + +Options: + --help Show this help + --version Show the version + --[no-]lex Lexer output(default: disabled) + --[no-]parse Parser output(default: disabled) + --[no-]sem Semantic analysis output(default: disabled) + --[no-]code Code generation output(default: enabled) +\end{lstlisting} + +\subsection{Outline} +\SPLC{} has several phases that each can produce their own output. Via command +line flags the user can enable or disable the printing of the output of +specific phases. The output for the code generation is enabled by default and +the output for the other phases are disabled by default. + +The first and second step are lexing and parsing, which are both explained in +Section~\ref{sec:pars}. When one enables only the parsing the program will show +the pretty printed parsed source which is valid \SPL{} code. A simple selftest +can thus be done by feeding the pretty printed output back into \SPLC{}. This +is show in Listing~\ref{lst:splcex}. + +The third phase is the semantic analysis phase. In this phase the types are +inferred where necessary and they are checked. There are also some trivial +sanity checks executed to make sure the program is a valid one. When one +enables the printing of the third phase you are shown the pretty printed source +code with all types inferred and the internal dictionary used for typechecking. +This phase is elaborated upon in Section~\ref{sec:sem}. + +The last and fourth phase is the code generation phase. \SPLC{} generates +\SSM\footnote{\url{http://www.staff.science.uu.nl/~dijks106/SSM/}} +assembly. \SSM{} assembly is a educational assembly language designed for +compiler construction courses and provides the programmer with handy tools such +as an emulator, breakpoints and a couple of higher level assembly instructions. +Details on code generation is explained in Section~\ref{sec:gen}. Since \SPLC{} +acts as a filter and the \SSM{} emulator does too one can chain the commands +together with standard pipes as shown in Listing~\ref{lst:splcex}. + +In the Section~\ref{sec:ext} it is explained what extra features \SPLC{} +contains. Some syntactic sugars have been added in combination with support for +higher order functions. + +\begin{lstlisting}[ + label={lst:splcex}, + caption={Example \SPLC{} run}, + language=sh] +# Run a program +spl input.spl | java -jar ssm.jar --stdin --cli +# Selftest parser +diff -q \ + <(spl --parse --no-code input.spl) \ + <(spl --parse --no-code input.spl | spl --parse --no-code) +\end{lstlisting} diff --git a/deliverables/report/pars.tex b/deliverables/report/pars.tex index 8a2029c..f67b82a 100644 --- a/deliverables/report/pars.tex +++ b/deliverables/report/pars.tex @@ -1,4 +1,4 @@ -\section{Lexing \& parsing} +\section{Lexing \& parsing}\label{sec:pars} \subsection{Yard} \subsection{Lexing} diff --git a/deliverables/report/report.tex b/deliverables/report/report.tex index 42e494f..5131eb0 100644 --- a/deliverables/report/report.tex +++ b/deliverables/report/report.tex @@ -1,17 +1,19 @@ -\documentclass[titlepage]{article} +\documentclass{article} \usepackage{listings} \usepackage{clean} \usepackage{spl} +\usepackage{hyperref} \usepackage[a4paper]{geometry} -\title{SPLC} +\title{Compiler Construction: SPL Compiler} \author{Pim Jager\and Mart Lubbers} \date{\today} \lstset{% basicstyle=\ttfamily\footnotesize, - breaklines + breaklines, + captionpos=b } \newcommand{\SPLC}{\texttt{SPLC}} @@ -20,28 +22,10 @@ \begin{document} \maketitle -\section{Introduction} -\SPLC{} is a program that, in several phases, generates \SSM{} -assembly for a given \SPL{} program. \SPLC{} is a program that acts as a -filter. The tool reads the standard input and the output is printed on standard -output. By default only the generated assembly code is outputted. But if the -user wants to inspect outputs of intermediate phases it can be done so by -setting command line flags. Listing~\ref{lst:splchelp} shows the output for -\texttt{spl -h}. There is also a \emph{manpage} that shows the same info. - -\begin{lstlisting}[label={lst:splchelp},caption={\texttt{./spl -h}}] -Usage: spl [OPTION] [FILE] - ::= -Compile spl code from FILE or stdin - -Options: - --help Show this help - --version Show the version - --[no-]lex Lexer output(default: disabled) - --[no-]parse Parser output(default: disabled) - --[no-]sem Semantic analysis output(default: disabled) - --[no-]code Code generation output(default: enabled) -\end{lstlisting} +\tableofcontents +\newpage + +\input{intro.tex} \input{pars.tex} diff --git a/deliverables/report/sem.tex b/deliverables/report/sem.tex index 466ac2d..c6003b4 100644 --- a/deliverables/report/sem.tex +++ b/deliverables/report/sem.tex @@ -1,4 +1,4 @@ -\section{Semantic analysis} +\section{Semantic analysis}\label{sec:sem} %The grammar used to parse %SPL %, if it is di erent from the given grammar. diff --git a/spl.icl b/spl.icl index 6c75e68..0e22a1e 100644 --- a/spl.icl +++ b/spl.icl @@ -62,8 +62,6 @@ Start w | args.help # stdin = stdin <<< "Usage: " <<< args.program <<< " [OPTION] [FILE]\n" - <<< " ::= \n" - <<< "Lex parse and either FILE or stdin\n" <<< "\n" <<< "Options:\n" <<< " --help Show this help\n" -- 2.20.1