next up previous
Next: Statements Up: The Abstract Syntax Tree Previous: The Abstract Syntax Tree

Declarations

The declaration part of a Pascal block (Figure 2)

Figure 2: The structure of a declaration part
\begin{figure}\begin{flushleft}
\textit{Declarations}\textnormal{[2]}:
\begin{qu...
...o is invoked in definition \htmlref{1}{fwmacro:1}.}
\end{flushleft}
\end{figure}
defines labels, constants, types, variables, and routines (procedures or functions) respectively. Individual declarations must occur in the order given in the previous sentence. As far as the semantics of the language are concerned, however, that order is actually immaterial. Because the attribute grammar is concerned with semantics, it simply states that the declaration part of a block contains some number of declarations of various kinds.

Pascal constants (Figure 3)

Figure 3: The structure of a constant
\begin{figure}\begin{flushleft}
\textit{Declarations}\textnormal{[3]}:
\begin{qu...
...o is invoked in definition \htmlref{1}{fwmacro:1}.}
\end{flushleft}
\end{figure}
may specify (signed) numbers, characters, or strings. Constants may also be named, and the names used in place of the value. There is no syntactic difference between a character constant and a string constant; if the constant specifies a single character then its type is char, otherwise it has a string type. By introducing the litr rule, we provide a place to to check the length of the character string and establish the appropriate type.

Types (Figure 4)

Figure 4: The structure of a type definition
\begin{figure}\begin{flushleft}
\textit{Declarations}\textnormal{[4]}:
\begin{qu...
...o is invoked in definition \htmlref{1}{fwmacro:1}.}
\end{flushleft}
\end{figure}
can be represented by identifiers or by constructors describing the structure of the type. Most constructors have very similar semantics, and can therefore be represented by a single nonterminal (TypeDenoter). Record types have a complex inner structure that requires additional information. Therefore it is convenient to use a second nonterminal (Record) at the root of that definition. Note that rule fldl provides an example of a node with an arbitrary collection of children of different kinds. Actually, the record will have no more than one var_part, but there is no need to carry that information into the AST explicitly.

A routine declaration (Figure 5

Figure 5: The structure of a routine declaration
\begin{figure}\begin{flushleft}
\textit{Declarations}\textnormal{[5]}:
\begin{qu...
...o is invoked in definition \htmlref{1}{fwmacro:1}.}
\end{flushleft}
\end{figure}
may use the directive forward or external in lieu of a block. Although these directives are defined as possible descendants of block, the phrase structure described later restricts then to blocks defining routines.


next up previous
Next: Statements Up: The Abstract Syntax Tree Previous: The Abstract Syntax Tree
2008-08-29