meta languages

Post on 12-Nov-2014

2.084 Views

Category:

Education

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Metalanguages as described by the NSW BOS for the SDD syllabus. Explanations, syntax and examples for BNF, EBNF and Railroad diagrams.

TRANSCRIPT

Meta Languages in SDD

Software Design and Development

Contents

2. EBNF2. EBNF

1. BNF1. BNF

3. Railroad diagram3. Railroad diagram

Course Specifications

NSW BOS Course Specifications

4. examples4. examples

BNF

Abbreviation for Backus-Naur form.

BNF is a metalanguage used to define the syntax of a programming language.

It uses the following symbols:

Contents

BNFexamples

This translates into English as:

•A postal address consists of a name-part, followed by a street-address part, followed by a zip-code part. •A name-part consists of either: a personal-part followed by a last name followed by an optional "jr-part" (Jr., Sr., or dynastic number) and end-of-line, or a personal part followed by a name part (this rule illustrates the use of recursion in BNFs, covering the case of people who use multiple first and middle names and/or initials). •A personal-part consists of either a first name or an initial followed by a dot. •A street address consists of a house number, followed by a street name, followed by an optional apartment specifier, followed by an end-of-line. •A zip-part consists of a town-name, followed by a comma, followed by a state code, followed by a ZIP-code followed by an end-of-line.

Note that many things (such as the format of a first-name, apartment specifier, ZIP-code, and Roman numeral) are left unspecified here. If necessary, they may be described using additional BNF rules.

Contents

EBNF

Abbreviation for extended Backus-Naur form.EBNF is a metalanguage used to define the syntax of a programming language.

In this extended form the following symbols are used:

Interpretation:An identifier is defined to be a Letter followed by one or more Letters or Digits.Letter is a non-terminal symbol and is defined elsewhere, and Digit is another non-terminal symbol defined elsewhere.

Contents

EBNFexampleContents

Railroad diagram

This is an alternative, graphical method used to define the syntax of a programming language.

• Rectangles are used to enclose non-terminal symbols (that is, symbols that will be further defined).

• Circles or rounded rectangles are used to enclose terminal symbols.

These elements are linked by paths to show all legal combinations.

1. By starting at the left-hand side of the diagram and 2. tracing any path in a forward direction 3. to reach the right-hand side of the diagram, 4. a syntactically correct construct will be covered.

(‘Railroad’ in this context means a branch in the diagram is legal if it is treated as a set of points in a railroad layout and a train can take the branch in a forward direction only).

Contents

Railroad diagramexampleContents

BNF, EBNF, Railroad Diagramexample

One possible set of syntax diagrams for this grammar is:

Contents

top related