In this section, we examine the syntax of programming languages. The syntax of programming languages is described using metalanguages. In the Preliminary course, we examined EBNF and railroad diagrams. We will use these metalanguages to describe the syntax of commands used to define and use
Metalanguages The rules of a programming language must be precise. Computers cannot follow vague instructions, so programs have to be written in a very precise way. The computer does not understand the text of a program. You must not use words of symbols that are not expected, and each instruction must adhere to a given structure or set of rules. Each program instruction written in a programming language is known as a sentence. The rules that tell us how the sentence can be constructed is called the syntax. Ever programming language has its own syntax or rules. When we use a language we must obey its syntactic rules The rules can be described in a number of ways.
Sometimes the syntax of a language is given using all of these methods. A text description explains what the sentence is about. Metalanguages provide the best way of defining the structures common to all programming languages. These are formal standard structures understood by all professional developers and programmers. Metalanguages can be divided into text based descriptions of syntax provided by BNF (Backus Normal Format) and EBNF (extended Backus Naur Format), and the graphical0based descriptions of syntax used by syntax structure diagrams or railroad diagrams. BNF and EBNF BNF/EBNF descriptions of language syntax have these major components:
<digit> ::= 1 can be written in English as "a 1 is assigned as the meaning of the non terminal symbol called digit". Railroad Diagrams Introduction |
