Title: Grammar Adaptation Ralf Lmmel, CWI
1Grammar Adaptation (Ralf Lämmel, CWI)
- Presentation and slides by
- Faizan Javed
- March 9th, 2004
21. Introduction
- Grammar Adaptation
- Model Restructuring (fold unfold) and Local
Changes (removal of phrases, restriction) - Performed by grammar programmers manually,
otherwise. - Transformations relevant for grammar development,
maintenance, re-engineering and recovery.
31. Introduction (contd.)
- Grammar Recovery
- Concerned with derivation of a languages
grammar. - Grammar transformations can be used to facilitate
grammar recovery. - Important for software re-engineering
- - Y2K problem, Euro-conversion problem
41. Introduction (contd..)
- Grammar recovery is hard
- ancient languages (ex Cobol dialects)
- in-house languages and language extensions
- COBOL example Lämmel, Verhoef
- Grammar transformations made the process
- - accessible, traceable and measurable.
51. Introduction (contd)
- Sample Adaptation (VS Cobol II)
- Problems faced were errors, omissions and use of
informal comments. - Reason lack of use of formal methods
- Example VS Cobol II REDEFINES clause
61. Introduction (contd.)
- REDEFINES clause is actually of type
- REDEFINES data-name
- Sample defines a structure of a data item with a
REDEFINES clause. - Use delete transformation operator
- delete level-number (data-name FILLER")?
in REDEFINES-clause
71. Introduction (contd..)
- Transformational approach benefits
- Adds Traceability changes can be recorded
- Reusable adaptation scripts useful for dialects
of the same grammar - Relaxed notions for non-semantics preserving
operators
82. Grammar Fragments
- Grammar fragments are a variant of context-free
grammars used for grammar transformations. In
grammar adaptation, grammars evolve. - Evolving grammars rather than reduced
grammars reduced grammars assume that each
production can be used in some derivation of a
terminal string from the start symbol.
92.1 Standard Context-Free grammars
- Standard CFG definition ltN, T, s, Pgt
- N and T are disjoint finite sets of nonterminals
and terminals respectively. - s is the start symbol,
- P is a finite set of productions or
(context-free) rules with - A production ltn, ugt P with n 2 N and
- u 2 (N U T) is also written as n ? u.
102.2 Deviation
- Start symbol not required for incomplete grammars
- No explicit declaration of non-terminals and
terminals grammar represented just by
productions - Non-terminals from and terminals from
- Bottom non-terminals non-terminals which are not
terminated - This deviation known as grammar fragments.
- Domain defined as
-
112.2 Deviation (contd..)
- Relevant set of grammar symbols
122.2 Deviation (contd..)
- Bottom non-terminals ( )
- Non-terminal lacking a definition, OR
- Indicates a connectivity problem defined with a
different left-hand side. - Top non-terminals ( )
- Non-terminals defined, but not used.
- Start symbols usually meet this criteria.
-
132.3 Semantics
- Language generated by a common CFG defined as
- Terminal strings can also be generated from an
arbitrary non-terminal n the semantics of n
w.r.t. a grammar fragment are -
142.3 Semantics (contd..)
- Terminal strings not sufficient since grammar
fragments are not necessarily terminated (ex
productions with bottom non-terminals) - Incomplete grammar
152.3 Semantics (contd..)
- Sentential forms provide an upper bound on the
denotation. - However, sentential forms dont provide a basis
to state the semantics preservation of
fold/unfold modulations.
162.3 Semantics (contd..)
- Observable non-terminals restrict sentential
forms so that only particular non-terminals are
observable. - means semantics restricted to
sentential forms consisting solely of bottom
non-terminals and terminals.
172.3 Semantics (contd..)
- Looping non-terminals non-terminal b lacks a
base case - Ultimate denotation of n w.r.t
183. Formal Reasoning
- Need to compare grammars, and characterize the
properties of grammar transformations. - Certain relations on the grammar fragments are
defined.
193.1 Equivalent grammars
- Equivalent grammars
- Useful in fold/unfold manipulations
203.1 Equivalent Grammars
- Equivalent grammars example
- Using equivalence properties,
213.2 Beyond Equivalence
- Equivalence often too restrictive to characterize
related grammars! - Some relaxations on the relations between two
grammars -
223.2 Beyond Equivalence (contd.)
- Equivalence modulo renaming
- In above fig, it holds that
233.2 Beyond Equivalence (contd.)
- Sub-grammar relation
- In above fig., it holds that but
not vice versa.
243.2 Beyond Equivalence (contd.)
- Enrichment relation
- In above fig, it holds that
253.2 Beyond Equivalence (contd.)
- Instance relation
- In above fig., it holds that
263.3 Grammar Transformers
- Partial grammar transformers Grammar relations
can be used to define various preservation
properties for grammar transformations.
274. Transformation Framework
- Define a framework for grammar transformations
offering transformation primitives and
combinators. - Discuss supplementary concepts like focus,
constraints and symbolic operands.
284.1 Primitives
- id identity function
- fail undefined grammar transformation
- reset returning empty set of rules
- add/subtract add/subtract a rule from a grammar
- replace replace a phrase by a phrase in a
grammar - substitute substitute non-terminal by a
non-terminal
294.1 Primitives (contd.)
304.2 Combinators
314.3 Constraints
324.4 Symbolic operands
- Introduces higher level of abstraction?
- Examples
- definition of n Denotes RHS of n. Useful in
unfolding operation no need to point out
definition explicitly. - all focus operand. Denotes all non-terminals
defined in a grammar. Useful if an operator
expecting a focus parameter should be applied
globally.
335.1 Operator Suite - Overview
- Stepwise adaptation application of a sequence of
transformation operators from the operator suite,
T1..Tm. - Transformational grammar programmer uses only
operators of the suite, not the combinators or
the primitives. - Three groups of operators
- Refactoring
- Construction
- Destruction
345.2 Refactoring
- Restructure grammar so that
- Comprehensibility is improved
- Subsequent adaptation steps are easier to perform
- Semantics-preserving in the narrow sense.
- Use of pre- and post- conditions in operators.
355.2 Refactoring (contd.)
365.3 Construction
- Facilitate grammar substitution, extension and
completion.
375.3 Construction (contd.)
- Unify example
- Useful if a bottom non-terminal should be
resolved interms of an existing definition - Or, if two bottom non-terminals intentionally
coincide.
385.3 Construction (contd.)
- Useful in grammar completion and connection
- Missing rules added by include.
- Too restrictive phrases generalised by
generalise. - Missing definition of non-terminals established
using resolve. - Non-terminals unified with unify.
395.4 Destruction
- Essentially inverse of construction (except
delete operator)
405.4 Destruction (contd.)
415.4 Destruction (contd.)
- Useful for correction or revision
- Too general phrases can be restricted.
- Superfluous rules or definitions can be excluded
or rejected, respectively. - Accidentally unified phrases can be separated by
introducing new non-terminals in certain
occurrences.
425.5 Discussion
435.5 Discussion (contd.)
- Some semantics preservation examples
- preserve strictly preserving equivalence of
phrases implies equivalent grammars. - unfold strictly preserving unfold defined
interms of preserve. - introduce introducing adds a rule for a new
non-terminal
446.0 Conclusion
- Towards proper grammar re-engineering
- -viewed as coding work
- -not a research focus anymoremore research
needed! - -paper contributes by defining the foundations
of an adaptive style of grammar development. - Semantics preservation and relaxation
- -refactoring operators are semantics preserving
only. - -paper introduces a set of weaker preservation
notions, suitable to characterise revisions and
extensions. - Perspective
- - more global notions than just preservation
can the grammar be improved with the
transformation sequence? - -Open research problem how clients of a grammar
such as compiler compiler inputs, rewrite rules
have to be adapted if the grammar serving as
contract changes. -
-