Page 209 - DCAP507_SYSTEM_SOFTWARE
P. 209
Unit 13: Formal Systems
Notes
Example: FORTRAN has an analogue of the for-statement as we recognize it from
languages such as Java and C, but in FORTRAN the body of the loop is not measured to be piece
of the for-statement; it's just a series of statements, like any other segment of a FORTRAN
program. To organize for the recurrence, the FORTRAN programmer adds a label to the last
declaration in the sequence and prepends a particular DO-statement at the commencement.
The DO-statement states four things: the loop-control variable, its initial value, its final value, and
the label of the last statement. The FORTRAN compiler substitutes the DO-statement with the code
for initializing the loop control variable and adds, after the labelled statement, code for modernizing
and testing the loop-control variable and for making the jump back to the top of the loop.
The statements making up the sequence to be frequent were not essentially apparent as "belonging"
to the loop, and actually it was not atypical for programmers to direct power out of this area and
back in again if they required executing some additional statements that it was suitable to
inscribe elsewhere.
This notion of the program as a flat list of autonomous statements turned out to be excessively
restricting in some respects and excessively flexible in others.
13.2.1 The Purpose and Function of the Notation
The syntactic components of a program generate a hierarchy, with the elements (like identifiers,
operator symbols, keywords, and literal constants) at the bottom and increasingly larger elements
at higher levels. These elements are considered as belonging syntactic categories, with members
of the similar category having similar syntactic tasks and functions. One can symbolize the
arrangement of a program as a syntax tree in which the leaf nodes are syntactic elements and
every interior node is labelled with the syntactic category of the element generated by the
leaves that descend from it.
The Backus-Naur formalism offers a brief manner of describing potential modes of mixture of
elements. It has a supplementary advantage for implementers of languages: It displays exactly
how to construct the recursive data structures for syntax trees.
13.2.2 The Fundamental Idea
The basic idea is to portray the syntax of a programming language as a set of rules (at times
known as productions). Each rule depicts one possible method of building a constituent belonging
to a specific syntactic category, which is named at the commencement of the rule. We'll write the
names of syntactic categories inside angle brackets. The right hand side of the rule then lists, in
order, the components of the constituents; these may comprise syntactic elements, other syntactic
groups, or both.
Any number of components can emerge in the right-hand side of a rule. The syntactic category
at the foundation of the rule is alienated from the right-hand side by the (more or less random)
symbol ::=.
Two or more rules starting with the similar syntactic categories may be united into one by
concatenating their right-hand sides, separating the substitute constructions with vertical bars,
therefore:
<expression> ::= <identifier> | <lambda-expression> | <procedure-call>
The reader must identify that the vertical bar in such cases, like the ::= symbol, is portion of the meta-
notation, not part of the programming language that is being depicted. Certainly, all of these
extensions entail additions to the meta-notation; when they are all deployed immediately, it can at
LOVELY PROFESSIONAL UNIVERSITY 203