File: lexical.tex

package info (click to toggle)
kaya 0.4.2-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,448 kB
  • ctags: 1,694
  • sloc: cpp: 9,536; haskell: 7,461; sh: 3,013; yacc: 910; makefile: 816; perl: 90
file content (182 lines) | stat: -rw-r--r-- 3,601 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
\section{Lexical Structure}

\subsection{Constants}

Constants available in \Kaya{} include integers, floating point
values, strings, characters and booleans, as shown in Figure \ref{consts}. 

\FFIG{
\begin{tabular}{rcl}
\MC{constant} & ::= & \MC{int} \\
           & $\mid$ & \MC{float} \\
           & $\mid$ & \MC{string} \\
           & $\mid$ & \MC{bool} \\
           & $\mid$ & \MC{char} \\
\\
\MC{int} & ::= & \oneplus{\MC{digit}} \\
\MC{float} & ::= & \oneplus{\MC{digit}} . \oneplus{\MC{digit}} \maybe{\MC{exp}}\\
\MC{string} & ::= & \CD{"}\zeroplus{\MC{ascii}}\CD{"} \\
\MC{char} & ::= & \CD{'}\MC{ascii}\CD{'} \\
\MC{boolean} & ::= & \CD{true} $\mid$ \CD{false} \\
\\
\MC{digit} & ::= & 0 $\mid$ 1 $\mid$ \ldots $\mid$ 9 \\
\MC{exp} & ::= & \CD{e+} \oneplus{\MC{digit}} \\
         & $\mid$ & \CD{e-} \oneplus{\MC{digit}} \\
         & $\mid$ & \CD{e} \oneplus{\MC{digit}} \\
\MC{ascii} & ::= & $\langle$any printable ASCII character$\rangle$ \\
           & $\mid$ & $\langle$an escape sequence$\rangle$ \\
\end{tabular}
}
{Constants}
{consts}

\subsection{Variables}

A variable name is any sequence of characters (other than a reserved
word, see section \ref{reserved}) beginning with a letter or
underscore, and containing only letters, underscores, digits or
apostrophes.

In the BNF, we refer to variable names as \MC{identifier}. Names which
must begin with an upper case letter are referred to as
\MC{uc\_identifier}. Names which must begin with a lower case letter
are referred to as \MC{lc\_identifier}.

\subsection{Operators}

The following tokens are operators:

\begin{tabular}{ccccccc}
\CD{+} &
\CD{-} &
\CD{*} &
\CD{/} &
\CD{\%} &
\CD{**} &
\CD{!} \\
\CD{++} &
\CD{--} &
\CD{+=} &
\CD{-=} &
\CD{*=} &
\CD{/=} \\
\CD{==} &
\CD{!=} &
\CD{<} &
\CD{>} &
\CD{<=} &
\CD{>=} \\
\CD{\&} &
\CD{|} &
\CD{\^} &
\CD{\&\&} &
\CD{||} &
\CD{<<} &
\CD{>>} \\

\end{tabular}

\subsection{Reserved Words}
\label{reserved}

The lexical analyser recognises the following as reserved words, and
hence they cannot be used as type or variable names:

\CD{Bool}, 
\CD{Char}, 
\CD{Exception}, 
\CD{File}, 
\CD{Float}, 
\CD{Int}, 
\CD{Ptr}, 
\CD{String}, 
\CD{Void}, 
\CD{abstract}, 
\CD{break}, 
\CD{case}, 
\CD{catch}, 
\CD{data}, 
\CD{default}, 
\CD{do},
\CD{else}, 
\CD{end}, 
\CD{false}, 
\CD{finally},
\CD{fnid}, 
\CD{foreign}, 
\CD{for}, 
\CD{globals}, 
\CD{if}, 
\CD{import}, 
\CD{include}, 
\CD{in}, 
\CD{lambda},
\CD{module}, 
\CD{of}, 
\CD{pass}, 
\CD{pure}, 
\CD{private},
\CD{public}, 
\CD{repeat}, 
\CD{return}, 
\CD{size}, 
\CD{throw}, 
\CD{trace}, 
\CD{true}, 
\CD{try}, 
\CD{type}, 
\CD{var}, 
\CD{while}.

\subsection{Delimiters}

The following tokens are used as delimiters:

\begin{tabular}{ccccccc}
\CD{\{} &
\CD{\}} &
\CD{(} &
\CD{)} &
\CD{[} &
\CD{]} \\
\CD{.} &
\CD{=} &
\CD{,} &
\CD{|} &
\CD{;} &
\CD{`} &
\CD{->} \\

\end{tabular}

\subsection{Comments}

A single line comment is introduced with \CD{//}, and continues to the
end of a line, e.g.:

\begin{verbatim}
pi = 3.0; // unreasonable approximation
\end{verbatim}

A multi line comment is introduced with \CD{/*} and continues until
\CD{*/}, e.g.:

\begin{verbatim}
/* We should probably use something more accurate than this,
   but I can't remember any more decimal places */
pi = 3.14;
\end{verbatim}

\subsection{Directives}

Directives (special instructions to the compiler) are prefixed with a
\CD{\%} sign. These may be implementation dependent; those required
by all implementations are:

\CD{imported},
\CD{include},
\CD{link},
\CD{VM}.

\noindent
An implementation is free to introduce others as required.