223 lines
8.5 KiB
TeX
223 lines
8.5 KiB
TeX
\batchmode
|
|
%This Latex file is machine-generated by the BNF-converter
|
|
|
|
\documentclass[a4paper,11pt]{article}
|
|
\author{BNF-converter}
|
|
\title{The Language Javalette}
|
|
\setlength{\parindent}{0mm}
|
|
\setlength{\parskip}{1mm}
|
|
\begin{document}
|
|
|
|
\maketitle
|
|
|
|
\newcommand{\emptyP}{\mbox{$\epsilon$}}
|
|
\newcommand{\terminal}[1]{\mbox{{\texttt {#1}}}}
|
|
\newcommand{\nonterminal}[1]{\mbox{$\langle \mbox{{\sl #1 }} \! \rangle$}}
|
|
\newcommand{\arrow}{\mbox{::=}}
|
|
\newcommand{\delimit}{\mbox{$|$}}
|
|
\newcommand{\reserved}[1]{\mbox{{\texttt {#1}}}}
|
|
\newcommand{\literal}[1]{\mbox{{\texttt {#1}}}}
|
|
\newcommand{\symb}[1]{\mbox{{\texttt {#1}}}}
|
|
|
|
This document was automatically generated by the {\em BNF-Converter}. It was generated together with the lexer, the parser, and the abstract syntax module, which guarantees that the document matches with the implementation of the language (provided no hand-hacking has taken place).
|
|
|
|
\section*{The lexical structure of Javalette}
|
|
\subsection*{Identifiers}
|
|
Identifiers \nonterminal{Ident} are unquoted strings beginning with a letter,
|
|
followed by any combination of letters, digits, and the characters {\tt \_ '},
|
|
reserved words excluded.
|
|
|
|
|
|
\subsection*{Literals}
|
|
Integer literals \nonterminal{Int}\ are nonempty sequences of digits.
|
|
|
|
|
|
Double-precision float literals \nonterminal{Double}\ have the structure
|
|
indicated by the regular expression $\nonterminal{digit}+ \mbox{{\it `.'}} \nonterminal{digit}+ (\mbox{{\it `e'}} \mbox{{\it `-'}}? \nonterminal{digit}+)?$ i.e.\
|
|
two sequences of digits separated by a decimal point, optionally
|
|
followed by an unsigned or negative exponent.
|
|
|
|
|
|
String literals \nonterminal{String}\ have the form
|
|
\terminal{"}$x$\terminal{"}, where $x$ is any sequence of any characters
|
|
except \terminal{"}\ unless preceded by \verb6\6.
|
|
|
|
|
|
|
|
|
|
\subsection*{Reserved words and symbols}
|
|
The set of reserved words is the set of terminals appearing in the grammar. Those reserved words that consist of non-letter characters are called symbols, and they are treated in a different way from those that are similar to identifiers. The lexer follows rules familiar from languages like Haskell, C, and Java, including longest match and spacing conventions.
|
|
|
|
The reserved words used in Javalette are the following: \\
|
|
|
|
\begin{tabular}{lll}
|
|
{\reserved{boolean}} &{\reserved{double}} &{\reserved{else}} \\
|
|
{\reserved{false}} &{\reserved{if}} &{\reserved{int}} \\
|
|
{\reserved{return}} &{\reserved{true}} &{\reserved{void}} \\
|
|
{\reserved{while}} & & \\
|
|
\end{tabular}\\
|
|
|
|
The symbols used in Javalette are the following: \\
|
|
|
|
\begin{tabular}{lll}
|
|
{\symb{(}} &{\symb{)}} &{\symb{,}} \\
|
|
{\symb{\{}} &{\symb{\}}} &{\symb{;}} \\
|
|
{\symb{{$=$}}} &{\symb{{$+$}{$+$}}} &{\symb{{$-$}{$-$}}} \\
|
|
{\symb{{$-$}}} &{\symb{!}} &{\symb{\&\&}} \\
|
|
{\symb{{$|$}{$|$}}} &{\symb{{$<$}}} &{\symb{{$>$}}} \\
|
|
{\symb{{$+$}}} &{\symb{*}} &{\symb{/}} \\
|
|
{\symb{\%}} &{\symb{{$<$}{$=$}}} &{\symb{{$>$}{$=$}}} \\
|
|
{\symb{{$=$}{$=$}}} &{\symb{!{$=$}}} & \\
|
|
\end{tabular}\\
|
|
|
|
\subsection*{Comments}
|
|
Single-line comments begin with {\symb{\#}}, {\symb{//}}. \\Multiple-line comments are enclosed with {\symb{/*}} and {\symb{*/}}.
|
|
|
|
\section*{The syntactic structure of Javalette}
|
|
Non-terminals are enclosed between $\langle$ and $\rangle$.
|
|
The symbols {\arrow} (production), {\delimit} (union)
|
|
and {\emptyP} (empty rule) belong to the BNF notation.
|
|
All other symbols are terminals.\\
|
|
|
|
\begin{tabular}{lll}
|
|
{\nonterminal{Program}} & {\arrow} &{\nonterminal{ListTopDef}} \\
|
|
\end{tabular}\\
|
|
|
|
\begin{tabular}{lll}
|
|
{\nonterminal{TopDef}} & {\arrow} &{\nonterminal{Type}} {\nonterminal{Ident}} {\terminal{(}} {\nonterminal{ListArg}} {\terminal{)}} {\nonterminal{Block}} \\
|
|
\end{tabular}\\
|
|
|
|
\begin{tabular}{lll}
|
|
{\nonterminal{ListTopDef}} & {\arrow} &{\nonterminal{TopDef}} \\
|
|
& {\delimit} &{\nonterminal{TopDef}} {\nonterminal{ListTopDef}} \\
|
|
\end{tabular}\\
|
|
|
|
\begin{tabular}{lll}
|
|
{\nonterminal{Arg}} & {\arrow} &{\nonterminal{Type}} {\nonterminal{Ident}} \\
|
|
\end{tabular}\\
|
|
|
|
\begin{tabular}{lll}
|
|
{\nonterminal{ListArg}} & {\arrow} &{\emptyP} \\
|
|
& {\delimit} &{\nonterminal{Arg}} \\
|
|
& {\delimit} &{\nonterminal{Arg}} {\terminal{,}} {\nonterminal{ListArg}} \\
|
|
\end{tabular}\\
|
|
|
|
\begin{tabular}{lll}
|
|
{\nonterminal{Block}} & {\arrow} &{\terminal{\{}} {\nonterminal{ListStmt}} {\terminal{\}}} \\
|
|
\end{tabular}\\
|
|
|
|
\begin{tabular}{lll}
|
|
{\nonterminal{ListStmt}} & {\arrow} &{\emptyP} \\
|
|
& {\delimit} &{\nonterminal{Stmt}} {\nonterminal{ListStmt}} \\
|
|
\end{tabular}\\
|
|
|
|
\begin{tabular}{lll}
|
|
{\nonterminal{Stmt}} & {\arrow} &{\terminal{;}} \\
|
|
& {\delimit} &{\nonterminal{Block}} \\
|
|
& {\delimit} &{\nonterminal{Type}} {\nonterminal{ListItem}} {\terminal{;}} \\
|
|
& {\delimit} &{\nonterminal{Ident}} {\terminal{{$=$}}} {\nonterminal{Expr}} {\terminal{;}} \\
|
|
& {\delimit} &{\nonterminal{Ident}} {\terminal{{$+$}{$+$}}} {\terminal{;}} \\
|
|
& {\delimit} &{\nonterminal{Ident}} {\terminal{{$-$}{$-$}}} {\terminal{;}} \\
|
|
& {\delimit} &{\terminal{return}} {\nonterminal{Expr}} {\terminal{;}} \\
|
|
& {\delimit} &{\terminal{return}} {\terminal{;}} \\
|
|
& {\delimit} &{\terminal{if}} {\terminal{(}} {\nonterminal{Expr}} {\terminal{)}} {\nonterminal{Stmt}} \\
|
|
& {\delimit} &{\terminal{if}} {\terminal{(}} {\nonterminal{Expr}} {\terminal{)}} {\nonterminal{Stmt}} {\terminal{else}} {\nonterminal{Stmt}} \\
|
|
& {\delimit} &{\terminal{while}} {\terminal{(}} {\nonterminal{Expr}} {\terminal{)}} {\nonterminal{Stmt}} \\
|
|
& {\delimit} &{\nonterminal{Expr}} {\terminal{;}} \\
|
|
\end{tabular}\\
|
|
|
|
\begin{tabular}{lll}
|
|
{\nonterminal{Item}} & {\arrow} &{\nonterminal{Ident}} \\
|
|
& {\delimit} &{\nonterminal{Ident}} {\terminal{{$=$}}} {\nonterminal{Expr}} \\
|
|
\end{tabular}\\
|
|
|
|
\begin{tabular}{lll}
|
|
{\nonterminal{ListItem}} & {\arrow} &{\nonterminal{Item}} \\
|
|
& {\delimit} &{\nonterminal{Item}} {\terminal{,}} {\nonterminal{ListItem}} \\
|
|
\end{tabular}\\
|
|
|
|
\begin{tabular}{lll}
|
|
{\nonterminal{Type}} & {\arrow} &{\terminal{int}} \\
|
|
& {\delimit} &{\terminal{double}} \\
|
|
& {\delimit} &{\terminal{boolean}} \\
|
|
& {\delimit} &{\terminal{void}} \\
|
|
\end{tabular}\\
|
|
|
|
\begin{tabular}{lll}
|
|
{\nonterminal{ListType}} & {\arrow} &{\emptyP} \\
|
|
& {\delimit} &{\nonterminal{Type}} \\
|
|
& {\delimit} &{\nonterminal{Type}} {\terminal{,}} {\nonterminal{ListType}} \\
|
|
\end{tabular}\\
|
|
|
|
\begin{tabular}{lll}
|
|
{\nonterminal{Expr6}} & {\arrow} &{\nonterminal{Ident}} \\
|
|
& {\delimit} &{\nonterminal{Integer}} \\
|
|
& {\delimit} &{\nonterminal{Double}} \\
|
|
& {\delimit} &{\terminal{true}} \\
|
|
& {\delimit} &{\terminal{false}} \\
|
|
& {\delimit} &{\nonterminal{Ident}} {\terminal{(}} {\nonterminal{ListExpr}} {\terminal{)}} \\
|
|
& {\delimit} &{\nonterminal{String}} \\
|
|
& {\delimit} &{\terminal{(}} {\nonterminal{Expr}} {\terminal{)}} \\
|
|
\end{tabular}\\
|
|
|
|
\begin{tabular}{lll}
|
|
{\nonterminal{Expr5}} & {\arrow} &{\terminal{{$-$}}} {\nonterminal{Expr6}} \\
|
|
& {\delimit} &{\terminal{!}} {\nonterminal{Expr6}} \\
|
|
& {\delimit} &{\nonterminal{Expr6}} \\
|
|
\end{tabular}\\
|
|
|
|
\begin{tabular}{lll}
|
|
{\nonterminal{Expr4}} & {\arrow} &{\nonterminal{Expr4}} {\nonterminal{MulOp}} {\nonterminal{Expr5}} \\
|
|
& {\delimit} &{\nonterminal{Expr5}} \\
|
|
\end{tabular}\\
|
|
|
|
\begin{tabular}{lll}
|
|
{\nonterminal{Expr3}} & {\arrow} &{\nonterminal{Expr3}} {\nonterminal{AddOp}} {\nonterminal{Expr4}} \\
|
|
& {\delimit} &{\nonterminal{Expr4}} \\
|
|
\end{tabular}\\
|
|
|
|
\begin{tabular}{lll}
|
|
{\nonterminal{Expr2}} & {\arrow} &{\nonterminal{Expr2}} {\nonterminal{RelOp}} {\nonterminal{Expr3}} \\
|
|
& {\delimit} &{\nonterminal{Expr3}} \\
|
|
\end{tabular}\\
|
|
|
|
\begin{tabular}{lll}
|
|
{\nonterminal{Expr1}} & {\arrow} &{\nonterminal{Expr2}} {\terminal{\&\&}} {\nonterminal{Expr1}} \\
|
|
& {\delimit} &{\nonterminal{Expr2}} \\
|
|
\end{tabular}\\
|
|
|
|
\begin{tabular}{lll}
|
|
{\nonterminal{Expr}} & {\arrow} &{\nonterminal{Expr1}} {\terminal{{$|$}{$|$}}} {\nonterminal{Expr}} \\
|
|
& {\delimit} &{\nonterminal{Expr1}} \\
|
|
\end{tabular}\\
|
|
|
|
\begin{tabular}{lll}
|
|
{\nonterminal{ListExpr}} & {\arrow} &{\emptyP} \\
|
|
& {\delimit} &{\nonterminal{Expr}} \\
|
|
& {\delimit} &{\nonterminal{Expr}} {\terminal{,}} {\nonterminal{ListExpr}} \\
|
|
\end{tabular}\\
|
|
|
|
\begin{tabular}{lll}
|
|
{\nonterminal{AddOp}} & {\arrow} &{\terminal{{$+$}}} \\
|
|
& {\delimit} &{\terminal{{$-$}}} \\
|
|
\end{tabular}\\
|
|
|
|
\begin{tabular}{lll}
|
|
{\nonterminal{MulOp}} & {\arrow} &{\terminal{*}} \\
|
|
& {\delimit} &{\terminal{/}} \\
|
|
& {\delimit} &{\terminal{\%}} \\
|
|
\end{tabular}\\
|
|
|
|
\begin{tabular}{lll}
|
|
{\nonterminal{RelOp}} & {\arrow} &{\terminal{{$<$}}} \\
|
|
& {\delimit} &{\terminal{{$<$}{$=$}}} \\
|
|
& {\delimit} &{\terminal{{$>$}}} \\
|
|
& {\delimit} &{\terminal{{$>$}{$=$}}} \\
|
|
& {\delimit} &{\terminal{{$=$}{$=$}}} \\
|
|
& {\delimit} &{\terminal{!{$=$}}} \\
|
|
\end{tabular}\\
|
|
|
|
|
|
|
|
\end{document}
|
|
|