1 \documentclass{article} |
1 \documentclass{article} |
2 \usepackage{hyperref} |
2 \usepackage{../style} |
3 \usepackage{amssymb} |
|
4 \usepackage{amsmath} |
|
5 \usepackage[T1]{fontenc} |
|
6 \usepackage{tikz} |
|
7 \usetikzlibrary{arrows} |
|
8 \usetikzlibrary{automata} |
|
9 \usetikzlibrary{shapes} |
|
10 \usetikzlibrary{shadows} |
|
11 \usetikzlibrary{positioning} |
|
12 \usetikzlibrary{calc} |
|
13 \usetikzlibrary{fit} |
|
14 \usetikzlibrary{backgrounds} |
|
15 \usepackage{../langs} |
3 \usepackage{../langs} |
16 |
4 \usepackage{../graphics} |
17 \newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% |
5 |
18 |
|
19 |
|
20 \newcommand\grid[1]{% |
|
21 \begin{tikzpicture}[baseline=(char.base)] |
|
22 \path[use as bounding box] |
|
23 (0,0) rectangle (1em,1em); |
|
24 \draw[red!50, fill=red!20] |
|
25 (0,0) rectangle (1em,1em); |
|
26 \node[inner sep=1pt,anchor=base west] |
|
27 (char) at (0em,\gridraiseamount) {#1}; |
|
28 \end{tikzpicture}} |
|
29 \newcommand\gridraiseamount{0.12em} |
|
30 |
|
31 \makeatletter |
|
32 \newcommand\Grid[1]{% |
|
33 \@tfor\z:=#1\do{\grid{\z}}} |
|
34 \makeatother |
|
35 |
|
36 \newcommand\Vspace[1][.3em]{% |
|
37 \mbox{\kern.06em\vrule height.3ex}% |
|
38 \vbox{\hrule width#1}% |
|
39 \hbox{\vrule height.3ex}} |
|
40 |
|
41 \def\VS{\Vspace[0.6em]} |
|
42 |
|
43 \begin{document} |
6 \begin{document} |
44 |
7 |
45 \section*{Handout 5} |
8 \section*{Handout 5 (Lexing)} |
46 |
9 |
47 Whenever you want to design a new programming language or implement a compiler for an |
10 Whenever you want to design a new programming language or |
48 existing language, the first task is to fix the basic ``words'' of the language. For example what are the |
11 implement a compiler for an existing language, the first task |
49 keywords, or reserved words, of the language, what are permitted identifiers, numbers, expressions and so |
12 is to fix the basic ``words'' of the language. For example |
50 on. One convenient way to do this is, of |
13 what are the keywords, or reserved words, of the language, |
51 course, by using regular expressions. |
14 what are permitted identifiers, numbers, expressions and so |
52 |
15 on. One convenient way to do this is, of course, by using |
53 In this course we want to take a closer look at the |
16 regular expressions. |
54 WHILE programming language. This is a simple imperative programming language consisting of arithmetic |
17 |
55 expressions, assignments, if-statements and loops. For example the Fibonacci program can be |
18 In this course we want to take a closer look at the WHILE |
56 written in this language as follows: |
19 programming language. This is a simple imperative programming |
|
20 language consisting of arithmetic expressions, assignments, |
|
21 if-statements and loops. For example the Fibonacci program can |
|
22 be written in this language as follows: |
57 |
23 |
58 \begin{center} |
24 \begin{center} |
59 \mbox{\lstinputlisting[language=while]{../progs/fib.while}} |
25 \mbox{\lstinputlisting[language=while]{../progs/fib.while}} |
60 \end{center} |
26 \end{center} |
61 |
27 |