Van Wijngaarden Grammar

stevefan19991 pts0 comments

Van Wijngaarden grammar - Wikipedia

Jump to content

Search

Search

Donate

Create account

Log in

Personal tools

Donate

Create account

Log in

Van Wijngaarden grammar

6 languages

Deutsch<br>Français<br>Hrvatski<br>Nederlands<br>Português<br>Русский

Edit links

From Wikipedia, the free encyclopedia

Notation techniques for grammars in computer science

In computer science, a Van Wijngaarden grammar (also vW-grammar or W-grammar [1]) is a formalism for defining formal languages. The name derives from the formalism invented by Adriaan van Wijngaarden[2]<br>for the purpose of defining the ALGOL 68 programming language.<br>The resulting specification[3] remains its most notable application.

Van Wijngaarden grammars address the problem that context-free grammars cannot express agreement or reference, where two different parts of the sentence must agree with each other in some way. For example, the sentence "The birds was eating" is not Standard English because it fails to agree on number. A context-free grammar would parse "The birds was eating" and "The birds were eating" and "The bird was eating" in the same way. However, context-free grammars have the benefit of simplicity whereas van Wijngaarden grammars are considered highly complex.[4]

Two levels<br>[edit]

W-grammars are two-level grammars : they are defined by a pair of grammars, that operate on different levels:

the hypergrammar is an attribute grammar, i.e. a set of context-free grammar rules in which the nonterminals may have attributes; and

the metagrammar is a context-free grammar defining possible values for these attributes.

The set of strings generated by a W-grammar is defined by a two-stage process:

within each hyperrule, for each attribute that occurs in it, pick a value for it generated by the metagrammar; the result is a normal context-free grammar rule; do this in every possible way;

use the resulting (possibly infinite) context-free grammar to generate strings in the normal way.

The consistent substitution used in the first step is the same as substitution in predicate logic, and actually supports logic programming; it corresponds to unification in Prolog, as noted by Alain Colmerauer[where?].

W-grammars are Turing complete;[5]<br>hence, all decision problems regarding the languages they generate, such as

whether a W-grammar generates a given string

whether a W-grammar generates no strings at all

are undecidable.

Curtailed variants, known as affix grammars, were developed, and applied in compiler construction and to the description of natural languages.

Definite logic programs, that is, logic programs that make no use of negation, can be viewed as a subclass of W-grammars.[6]

Motivation and history<br>[edit]

In the 1950s, attempts started to apply computers to the recognition, interpretation and translation of natural languages, such as English and Russian. This requires a machine-readable description of the phrase structure of sentences, that can be used to parse and interpret them, and to generate them. Context-free grammars, a concept from structural linguistics, were adopted for this purpose; their rules can express how sentences are recursively built out of parts of speech, such as noun phrases and verb phrases, and ultimately, words, such as nouns, verbs, and pronouns.

This work influenced the design and implementation of programming languages, most notably, of ALGOL 60, which introduced a syntax description in Backus–Naur form.

However, context-free rules cannot express agreement or reference (anaphora), where two different parts of the sentence must agree with each other in some way.

These can be readily expressed in W-grammars. (See example below.)

Programming languages have the analogous notions of typing and scoping.<br>A compiler or interpreter for the language must recognize which uses of a variable belong together (refer to the same variable). This is typically subject to constraints such as:

A variable must be initialized before its value is used.

In strongly typed languages, each variable is assigned a type, and all uses of the variable must respect its type.

Often, its type must be declared explicitly, before use.

W-grammars are based on the idea of providing the nonterminal symbols of context-free grammars with attributes (or affixes) that pass information between the nodes of the parse tree, used to constrain the syntax and to specify the semantics.

This idea was well known at the time; e.g. Donald Knuth visited the ALGOL 68 design committee while developing his own version of it, attribute grammars.[7]

By augmenting the syntax description with attributes, constraints like the above can be checked, ruling many invalid programs out at compile time.<br>As Van Wijngaarden wrote in his preface:[2]

My main objections were certain to me unnecessary restrictions and the definition of the syntax and semantics. Actually the syntax viewed in MR 75 produces a large number of programs, whereas I should prefer to have the subset of...

grammars grammar free context wijngaarden languages

Related Articles