%% File generated by the BNF Converter. \batchmode \documentclass[a4paper,11pt]{article} \usepackage[T1]{fontenc} \usepackage[utf8x]{inputenc} \setlength{\parindent}{0mm} \setlength{\parskip}{1mm} \title{The Language Cpp} \author{BNF-converter} \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}. \section*{The lexical structure of Cpp} \subsection*{Literals} 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. Integer literals \nonterminal{Int}\ are nonempty sequences of digits. 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. Id literals are recognized by the regular expression \(({\nonterminal{lower}} \mid {\nonterminal{upper}}) ({\nonterminal{lower}} \mid {\nonterminal{upper}} \mid {\nonterminal{digit}} \mid \mbox{`\_'})*\) \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 Cpp are the following: \\ \begin{tabular}{lll} {\reserved{bool}} & {\reserved{double}} & {\reserved{else}} \\ {\reserved{false}} & {\reserved{if}} & {\reserved{int}} \\ {\reserved{return}} & {\reserved{string}} & {\reserved{true}} \\ {\reserved{void}} & {\reserved{while}} & \\ \end{tabular} \\ The symbols used in Cpp 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{\}}} \\ \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 Cpp} 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{Arg}} & {\arrow} &{\nonterminal{Type}} {\nonterminal{Id}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{Def}} & {\arrow} &{\nonterminal{Type}} {\nonterminal{Id}} {\terminal{(}} {\nonterminal{ListArg}} {\terminal{)}} {\terminal{\{}} {\nonterminal{ListStm}} {\terminal{\}}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{Exp}} & {\arrow} &{\nonterminal{Exp1}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{Program}} & {\arrow} &{\nonterminal{ListDef}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{Stm}} & {\arrow} &{\terminal{\{}} {\nonterminal{ListStm}} {\terminal{\}}} \\ & {\delimit} &{\nonterminal{Type}} {\nonterminal{ListId}} {\terminal{;}} \\ & {\delimit} &{\nonterminal{Exp}} {\terminal{;}} \\ & {\delimit} &{\terminal{if}} {\terminal{(}} {\nonterminal{Exp}} {\terminal{)}} {\nonterminal{Stm}} {\terminal{else}} {\nonterminal{Stm}} \\ & {\delimit} &{\nonterminal{Type}} {\nonterminal{Id}} {\terminal{{$=$}}} {\nonterminal{Exp}} {\terminal{;}} \\ & {\delimit} &{\terminal{return}} {\nonterminal{Exp}} {\terminal{;}} \\ & {\delimit} &{\terminal{return}} {\terminal{;}} \\ & {\delimit} &{\terminal{while}} {\terminal{(}} {\nonterminal{Exp}} {\terminal{)}} {\nonterminal{Stm}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{Type}} & {\arrow} &{\terminal{bool}} \\ & {\delimit} &{\terminal{double}} \\ & {\delimit} &{\terminal{int}} \\ & {\delimit} &{\terminal{string}} \\ & {\delimit} &{\terminal{void}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{ListId}} & {\arrow} &{\nonterminal{Id}} \\ & {\delimit} &{\nonterminal{Id}} {\terminal{,}} {\nonterminal{ListId}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{ListArg}} & {\arrow} &{\emptyP} \\ & {\delimit} &{\nonterminal{Arg}} \\ & {\delimit} &{\nonterminal{Arg}} {\terminal{,}} {\nonterminal{ListArg}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{ListDef}} & {\arrow} &{\emptyP} \\ & {\delimit} &{\nonterminal{Def}} {\nonterminal{ListDef}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{ListExp}} & {\arrow} &{\emptyP} \\ & {\delimit} &{\nonterminal{Exp}} \\ & {\delimit} &{\nonterminal{Exp}} {\terminal{,}} {\nonterminal{ListExp}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{ListStm}} & {\arrow} &{\emptyP} \\ & {\delimit} &{\nonterminal{Stm}} {\nonterminal{ListStm}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{Exp1}} & {\arrow} &{\nonterminal{Exp2}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{Exp2}} & {\arrow} &{\nonterminal{Exp3}} {\terminal{{$=$}}} {\nonterminal{Exp2}} \\ & {\delimit} &{\nonterminal{Exp3}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{Exp3}} & {\arrow} &{\nonterminal{Exp3}} {\terminal{{$|$}{$|$}}} {\nonterminal{Exp4}} \\ & {\delimit} &{\nonterminal{Exp4}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{Exp4}} & {\arrow} &{\nonterminal{Exp4}} {\terminal{\&\&}} {\nonterminal{Exp5}} \\ & {\delimit} &{\nonterminal{Exp5}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{Exp5}} & {\arrow} &{\nonterminal{Exp6}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{Exp6}} & {\arrow} &{\nonterminal{Exp7}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{Exp7}} & {\arrow} &{\nonterminal{Exp8}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{Exp8}} & {\arrow} &{\nonterminal{Exp8}} {\terminal{{$=$}{$=$}}} {\nonterminal{Exp9}} \\ & {\delimit} &{\nonterminal{Exp8}} {\terminal{!{$=$}}} {\nonterminal{Exp9}} \\ & {\delimit} &{\nonterminal{Exp9}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{Exp9}} & {\arrow} &{\nonterminal{Exp9}} {\terminal{{$>$}}} {\nonterminal{Exp10}} \\ & {\delimit} &{\nonterminal{Exp9}} {\terminal{{$>$}{$=$}}} {\nonterminal{Exp10}} \\ & {\delimit} &{\nonterminal{Exp9}} {\terminal{{$<$}}} {\nonterminal{Exp10}} \\ & {\delimit} &{\nonterminal{Exp9}} {\terminal{{$<$}{$=$}}} {\nonterminal{Exp10}} \\ & {\delimit} &{\nonterminal{Exp10}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{Exp10}} & {\arrow} &{\nonterminal{Exp11}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{Exp11}} & {\arrow} &{\nonterminal{Exp11}} {\terminal{{$-$}}} {\nonterminal{Exp12}} \\ & {\delimit} &{\nonterminal{Exp11}} {\terminal{{$+$}}} {\nonterminal{Exp12}} \\ & {\delimit} &{\nonterminal{Exp12}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{Exp12}} & {\arrow} &{\nonterminal{Exp12}} {\terminal{/}} {\nonterminal{Exp13}} \\ & {\delimit} &{\nonterminal{Exp12}} {\terminal{*}} {\nonterminal{Exp13}} \\ & {\delimit} &{\nonterminal{Exp13}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{Exp13}} & {\arrow} &{\terminal{{$-$}{$-$}}} {\nonterminal{Exp14}} \\ & {\delimit} &{\terminal{{$+$}{$+$}}} {\nonterminal{Exp14}} \\ & {\delimit} &{\nonterminal{Exp14}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{Exp14}} & {\arrow} &{\nonterminal{Exp15}} {\terminal{{$-$}{$-$}}} \\ & {\delimit} &{\nonterminal{Exp15}} {\terminal{{$+$}{$+$}}} \\ & {\delimit} &{\nonterminal{Exp15}} \\ \end{tabular} \\ \begin{tabular}{lll} {\nonterminal{Exp15}} & {\arrow} &{\nonterminal{Id}} {\terminal{(}} {\nonterminal{ListExp}} {\terminal{)}} \\ & {\delimit} &{\nonterminal{Double}} \\ & {\delimit} &{\terminal{false}} \\ & {\delimit} &{\nonterminal{Id}} \\ & {\delimit} &{\nonterminal{Integer}} \\ & {\delimit} &{\nonterminal{String}} \\ & {\delimit} &{\terminal{true}} \\ & {\delimit} &{\terminal{(}} {\nonterminal{Exp}} {\terminal{:}} {\nonterminal{Type}} {\terminal{)}} \\ & {\delimit} &{\terminal{(}} {\nonterminal{Exp}} {\terminal{)}} \\ \end{tabular} \\ \end{document}