\chapter{Language fundamentals}

\section{Lexical elements}

\subsection{COBOL words}

\subsection{User-defined words}

\subsection{Reserved words}

\subsection{Literals}

\subsubsection{Alphanumeric literals}

\format{standard}
\begin{syntax}
  \begin{1=}
    \textquotesingle
    \begin{0-1}
      \character
    \end{0-1}\ldots
    \textquotesingle \\
    
    \textquotedbl
    \begin{0-1}
      \character
    \end{0-1}\ldots
    \textquotedbl
  \end{1=}
\end{syntax}

\format{hexadecimal}
\begin{syntax}
  \begin{1=}
    X\textquotesingle
    \begin{0-1}
      \hexcharacter
    \end{0-1}\ldots
    \textquotesingle \\
    
    X\textquotedbl
    \begin{0-1}
      \hexcharacter
    \end{0-1}\ldots
    \textquotedbl
  \end{1=}  
\end{syntax}

\format{null-terminated}
\begin{syntax}[\gnucobolcolour]
  \begin{1=}
    Z\textquotesingle
    \begin{0-1}
      \character
    \end{0-1}\ldots
    \textquotesingle \\
    
    Z\textquotedbl
    \begin{0-1}
      \character
    \end{0-1}\ldots
    \textquotedbl
  \end{1=}
\end{syntax}

\format{raw-C-string}
\begin{syntax}[\gnucobolcolour] % TO-DO: Check not ACUCOBOL extension.
  \begin{1=}
    L\textquotesingle
    \begin{0-1}
      \character
    \end{0-1}\ldots
    \textquotesingle \\
    
    L\textquotedbl
    \begin{0-1}
      \character
    \end{0-1}\ldots
    \textquotedbl
  \end{1=}
\end{syntax}

\subsubsection{Numeric literals}

\format{integer}
\begin{syntax}
  \begin{0-1}
    + \\
    -
  \end{0-1}
  \begin{1=}
    0 \\
    1 \\
    2 \\
    3 \\
    4 \\
    5 \\
    6 \\
    7 \\
    8 \\
    9
  \end{1=}\ldots
\end{syntax}

\format{fixed-point}
\begin{syntax}
  \begin{0-1}
    + \\
    -
  \end{0-1}
  \begin{0-1}
    0 \\
    1 \\
    2 \\
    3 \\
    4 \\
    5 \\
    6 \\
    7 \\
    8 \\
    9
  \end{0-1}\ldots
  \begin{1=}
    . \\
    ,
  \end{1=}
  \begin{1=}
    0 \\
    1 \\
    2 \\
    3 \\
    4 \\
    5 \\
    6 \\
    7 \\
    8 \\
    9
  \end{1=}\ldots
\end{syntax}

\format{floating-point}
\begin{syntax}
  \begin{0-1}
    + \\
    -
  \end{0-1}
  \begin{0-1}
    0 \\
    1 \\
    2 \\
    3 \\
    4 \\
    5 \\
    6 \\
    7 \\
    8 \\
    9
  \end{0-1}\ldots
  \begin{1=}
    . \\
    ,
  \end{1=}
  \begin{0-1}
    0 \\
    1 \\
    2 \\
    3 \\
    4 \\
    5 \\
    6 \\
    7 \\
    8 \\
    9
  \end{0-1}\ldots
  E
  \begin{0-1}
    + \\
    -
  \end{0-1}
  \begin{1=}
    0 \\
    1 \\
    2 \\
    3 \\
    4 \\
    5 \\
    6 \\
    7 \\
    8 \\
    9    
  \end{1=}\ldots
\end{syntax}

\format{binary}
\begin{syntax}[\miscextcolour]
  B\#
  \begin{1=}
    0 \\
    1
  \end{1=}\ldots
\end{syntax}

\format{octal}
\begin{syntax}[\miscextcolour]
  \begin{1=}
    O\# \\
    \%
  \end{1=}
  \begin{1=}
    0 \\
    1 \\
    2 \\
    3 \\
    4 \\
    5 \\
    6 \\
    7
  \end{1=}\ldots
\end{syntax}

\format{hexadecimal-number}
\begin{syntax}[\miscextcolour]
  \begin{1=}
    H\# \\
    X\#
  \end{1=}
  \begin{1=}
    0 \\
    1 \\
    2 \\
    3 \\
    4 \\
    5 \\
    6 \\
    7
  \end{1=}\ldots
\end{syntax}

\format{hexadecimal-string}
\begin{syntax}[\gnucobolcolour] % TO-DO: Check not ACUCOBOL extension.
  \begin{1=}
    H\textquotesingle
    \begin{0-1}
      \character
    \end{0-1}\ldots
    \textquotesingle \\
    
    H\textquotedbl
    \begin{0-1}
      \character
    \end{0-1}\ldots
    \textquotedbl
  \end{1=}
\end{syntax}

\subsubsection{Boolean literals}

\format{standard}
\begin{syntax}
  \begin{1=}
    B\textquotesingle
    \begin{0-1}
      \character
    \end{0-1}\ldots
    \textquotesingle \\
    
    B\textquotedbl
    \begin{0-1}
      \character
    \end{0-1}\ldots
    \textquotedbl
  \end{1=}
\end{syntax}

\format{hexadecimal}
\begin{syntax}
  \begin{1=}
    BX\textquotesingle
    \begin{0-1}
      \hexcharacter
    \end{0-1}\ldots
    \textquotesingle \\
    
    BX\textquotedbl
    \begin{0-1}
      \hexcharacter
    \end{0-1}\ldots
    \textquotedbl
  \end{1=}
\end{syntax}

\subsubsection{National literals}

\format{standard}
\begin{syntax}
  \begin{1=}
    N\textquotesingle
    \begin{0-1}
      \character
    \end{0-1}\ldots
    \textquotesingle \\
    
    N\textquotedbl
    \begin{0-1}
      \character
    \end{0-1}\ldots
    \textquotedbl \\

    \miscext{
      NC\textquotesingle
      \begin{0-1}
        \character
      \end{0-1}\ldots
      \textquotesingle
    }\\

    \miscext{
      NC\textquotedbl
      \begin{0-1}
        \character
      \end{0-1}\ldots
      \textquotedbl
    }
  \end{1=}
\end{syntax}

\format{hexadecimal}
\begin{syntax}
  \begin{1=}
    NX\textquotesingle
    \begin{0-1}
      \hexcharacter
    \end{0-1}\ldots
    \textquotesingle \\
    
    NX\textquotedbl
    \begin{0-1}
      \hexcharacter
    \end{0-1}\ldots
    \textquotedbl
  \end{1=}  
\end{syntax}

\subsubsection{Figurative constants}

\format{zero}
\begin{syntax}
  ALL
  \begin{1=}
    \key{ZERO} \\
    \key{ZEROES} \\
    \key{ZEROS}
  \end{1=}
\end{syntax}

\format{space}
\begin{syntax}
  ALL
  \begin{1=}
    \key{SPACE} \\
    \key{SPACES}
  \end{1=}
\end{syntax}

\format{high-value}
\begin{syntax}
  ALL
  \begin{1=}
    \key{HIGH-VALUE} \\
    \key{HIGH-VALUES}
  \end{1=}
\end{syntax}

\format{low-value}
\begin{syntax}
  ALL
  \begin{1=}
    \key{LOW-VALUE} \\
    \key{LOW-VALUES}
  \end{1=}
\end{syntax}

\format{quote}
\begin{syntax}
  ALL
  \begin{1=}
    \key{QUOTE} \\
    \key{QUOTES}
  \end{1=}
\end{syntax}

\format{null}
\begin{syntax}[\miscextcolour]
  ALL
  \begin{1=}
    \key{NULL} \\
    \key{NULLS}
  \end{1=}
\end{syntax}

\format{literal}
\begin{syntax}
  \key{ALL} \literal
\end{syntax}

\format{symbolic-character}
\begin{syntax}
  ALL \symboliccharacter
\end{syntax}

\section{References}

\section{Expressions}

\subsection{Arithmetic expressions}

Arithmetic expressions may contain the following operators:

\begin{table}[!h]
  \begin{tabular}[!h]{l l l}
    \toprule
    \textbf{Binary operators} & \textbf{Purpose} & \textbf{Precedence} \\
    + & addition & 1 \\
    -- & subtraction & 1\\
    * & multiplication & 2\\
    / & division & 2 \\
    ** & exponentiation & 3 \\
    \gnucobol{\^{}} & \gnucobol{exponentiation} & 3 \\ \midrule
    \textbf{Unary operators} \\
    + & no effect & 4 \\
    -- & multiplication by $-1$ & 4 \\ \bottomrule
  \end{tabular}
\end{table}

Binary operators must have a numeric item or expression to both their left and right. Unary operators must have a numeric item or expression to their right only.

Operators with greatest precedence are evaluated first. If an expression contains multiple operators of equal precedence, they are evaluated from left to right.

Arithmetic expressions may contain arithmetic expressions surrounded by parentheses. These nested expressions are evaluated first, before any of the operators of the outer expression.

\begin{table}[!h]
  \centering
  \begin{tabular}[!h]{c c c c c c}
    \toprule
    \multirow{2}{*}{\textbf{First symbol}} & \multicolumn{5}{c}{\textbf{Second symbol}} \\
    \cmidrule(lr){2-6}
                          & Identifier or literal & Binary operator & Unary operator & (     & ) \\ \midrule
    Identifier or literal &                       & \tick           &                &       & \tick \\
    Binary operator       & \tick                 &                 & \tick          & \tick & \\
    Unary operator        & \tick                 &                 &                & \tick & \\
    (                     & \tick                 &                 & \tick          & \tick & \\
    )                     &                       & \tick           &                &       & \tick \\
    \bottomrule
  \end{tabular}
\end{table}

\subsection{Concatenation expressions}

\begin{syntax}
  \begin{1=}
    \literal \\
    \metaelement{concatenation-expression-1}
  \end{1=}
  \& \literal
\end{syntax}

\subsection{Conditional expressions}

\begin{table}[!h]
  \begin{tabular}[!h]{l l l}
    \toprule
    \textbf{Binary operators} & \textbf{Purpose} & \textbf{Precedence} \\
    AND & logical and & 1 \\
    OR & logical or & 2 \\ \midrule
    \textbf{Unary operator} \\
    NOT & logical not & 3 \\ \bottomrule
  \end{tabular}
\end{table}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "grammar.tex"
%%% End:
