Adaptive grammar

An adaptive grammar is a formal grammar that explicitly provides mechanisms within the formalism to allow its own production rules to be manipulated.

Overview
John N. Shutt defines adaptive grammar as a grammatical formalism that allows rule sets (aka sets of production rules) to be explicitly manipulated within a grammar. Types of manipulation include rule addition, deletion, and modification.

Early history
The first description of grammar adaptivity (though not under that name) in the literature is generally  taken to be in a paper by Alfonso Caracciolo di Forino published in 1963. The next generally accepted reference to an adaptive formalism (extensible context-free grammars) came from Wegbreit in 1970 in the study of extensible programming languages, followed by the dynamic syntax of Hanford and Jones in 1973.

Collaborative efforts
Until fairly recently, much of the research into the formal properties of adaptive grammars was uncoordinated between researchers, only first being summarized by Henning Christiansen in 1990 in response to a paper in ACM SIGPLAN Notices by Boris Burshteyn. The Department of Engineering at the University of São Paulo has its Adaptive Languages and Techniques Laboratory, specifically focusing on research and practice in adaptive technologies and theory. The LTA also maintains a page naming researchers in the field.

Terminology and taxonomy
While early efforts made reference to dynamic syntax and extensible, modifiable, dynamic, and adaptable grammars, more recent usage has tended towards the use of the term adaptive (or some variant such as adaptativa, depending on the publication language of the literature). Iwai refers to her formalism as adaptive grammars, but this specific use of simply adaptive grammars is not typically currently used in the literature without name qualification. Moreover, no standardization or categorization efforts have been undertaken between various researchers, although several have made efforts in this direction.

The Shutt classification (and extensions)
Shutt categorizes adaptive grammar models into two main categories:


 * Imperative adaptive grammars vary their rules based on a global state changing over the time of the generation of a language.
 * Declarative adaptive grammars vary their rules only over the space of the generation of a language (i.e., position in the syntax tree of the generated string).

Jackson refines Shutt's taxonomy, referring to changes over time as global and changes over space as local, and adding a hybrid time-space category:


 * Time-space adaptive grammars (hybrids) vary their rules over either the time or the space (or both) of the generation of a language (and local and global operations are explicitly differentiated by the notation for such changes).

Adaptive formalisms in the literature
Adaptive formalisms may be divided into two main categories: full grammar formalisms (adaptive grammars), and adaptive machines, upon which some grammar formalisms have been based.

Adaptive grammar formalisms
The following is a list (by no means complete) of grammar formalisms that, by Shutt's definition above, are considered to be (or have been classified by their own inventors as being) adaptive grammars. They are listed in their historical order of first mention in the literature.

Extensible context-free grammars (Wegbreit)
Described in Wegbreit's doctoral dissertation in 1970, an extensible context-free grammar consists of a context-free grammar whose rule set is modified according to instructions output by a finite state transducer when reading the terminal prefix during a leftmost derivation. Thus, the rule set varies over position in the generated string, but this variation ignores the hierarchical structure of the syntax tree. Extensible context-free grammars were classified by Shutt as imperative.

Christiansen grammars (Christiansen)
First introduced in 1985 as Generative Grammars and later more elaborated upon, Christiansen grammars (apparently dubbed so by Shutt, possibly due to conflict with Chomsky generative grammars) are an adaptive extension of attribute grammars. Christiansen grammars were classified by Shutt as declarative.

The redoubling language $$L = \{ww | w \mbox{ is a letter}\}$$ is demonstrated as follows:

      →    

where w-rule =         →   w

    →     >      →   <ε>       →   a

Bottom-up modifiable grammars, top-down modifiable grammars, and USSA (Burshteyn)
First introduced in May 1990 and later expanded upon in December 1990, modifiable grammars explicitly provide a mechanism for the addition and deletion of rules during a parse. In response to the ACM SIGPLAN Notices responses, Burshteyn later modified his formalism and introduced his adaptive Universal Syntax and Semantics Analyzer (USSA) in 1992. These formalisms were classified by Shutt as imperative.

Recursive adaptive grammars (Shutt)
Introduced in 1993, Recursive Adaptive Grammars (RAGs) were an attempt to introduce a Turing powerful formalism that maintained much of the elegance of context-free grammars. Shutt self-classifies RAGs as being a declarative formalism.

Dynamic grammars (Boullier)
Boullier's dynamic grammars, introduced in 1994, appear to be the first adaptive grammar family of grammars to rigorously introduce the notion of a time continuum of a parse as part of the notation of the grammar formalism itself. Dynamic grammars are a sequence of grammars, with each grammar Gi differing in some way from other grammars in the sequence, over time. Boullier's main paper on dynamic grammars also defines a dynamic parser, the machine that effects a parse against these grammars, and shows examples of how his formalism can handle such things as type checking, extensible languages, polymorphism, and other constructs typically considered to be in the semantic domain of programming language translation.

Adaptive grammars (Iwai)
The work of Iwai in 2000 takes the adaptive automata of Neto further by applying adaptive automata to context-sensitive grammars. Iwai's adaptive grammars (note the qualifier by name) allow for three operations during a parse: ? query (similar in some respects to a syntactic predicate, but tied to inspection of rules from which modifications are chosen), + addition, and - deletion (which it shares with its predecessor adaptive automata).

§-calculus (Jackson)
Introduced in 2000 and most fully discussed in 2006, the §-Calculus (§ here pronounced meta-ess) allows for the explicit addition, deletion, and modification of productions within a grammar, as well as providing for syntactic predicates. This formalism is self-classified by its creator as both imperative and adaptive, or, more specifically, as a time-space adaptive grammar formalism, and was further classified by others as being an analytic formalism.

The redoubling language $$L = \{ww | w \in \{a,b\}^+\}$$ is demonstrated as follows:

grammar ww { S ::= #phi(A.X<-"") R; R ::= $C('[ab]') #phi(A.X<-A.X C) #phi(N<=A.X) N | R; };

(Note on notation: In the above example, the #phi(...) statements identify the points in the production R that modify the grammar explicitly. #phi(A.X<-A.X C) represents a global modification (over time) and the #phi(N<=A.X) statement identifies a local modification (over space). The #phi(A.X<-"") statement in the S production effectively declares a global production called A.X by placing the empty string into that production before its reference by R.)

Adaptive devices (Neto & Pistori)
First described by Neto in 2001, adaptive devices were later enhanced and expanded upon by Pistori in 2003.

Adapser (Carmi)
In 2002, Adam Carmi introduced an LALR(1)-based adaptive grammar formalism known as Adapser. Specifics of the formalism do not appear to have been released.

Adaptive CFGs with appearance checking (Bravo)
In 2004, César Bravo introduced the notion of merging the concept of appearance checking with adaptive context-free grammars, a restricted form of Iwai's adaptive grammars, showing these new grammars, called Adaptive CFGs with Appearance Checking to be Turing powerful.

Adaptive machine formalisms
The formalisms listed below, while not grammar formalisms, either serve as the basis of full grammar formalisms, or are included here because they are adaptive in nature. They are listed in their historical order of first mention in the literature.


 * Self-modifying finite state automata (Shutt & Rubinstein)
 * Introduced in 1994 by Shutt and Rubinstein, Self-Modifying Finite State Automata (SMFAs) are shown to be, in a restricted form, Turing powerful.


 * Adaptive automata (Neto)
 * In 1994, Neto introduced the machine he called a structured pushdown automaton, the core of adaptive automata theory as pursued by Iwai, Pistori, Bravo and others. This formalism allows for the operations of inspection (similar to syntactic predicates, as noted above relating to Iwai's adaptive grammars), addition, and deletion of rules.