Grammar Adaptation Ralf Lmmel, CWI - PowerPoint PPT Presentation

1 / 44
About This Presentation
Title:

Grammar Adaptation Ralf Lmmel, CWI

Description:

Model Restructuring (fold unfold) and Local Changes (removal of phrases, restriction) ... delete level-number (data-name | 'FILLER')? in REDEFINES-clause ... – PowerPoint PPT presentation

Number of Views:55
Avg rating:3.0/5.0
Slides: 45
Provided by: jav8
Learn more at: https://www.uab.edu
Category:

less

Transcript and Presenter's Notes

Title: Grammar Adaptation Ralf Lmmel, CWI


1
Grammar Adaptation (Ralf Lämmel, CWI)
  • Presentation and slides by
  • Faizan Javed
  • March 9th, 2004

2
1. 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.

3
1. 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

4
1. 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.

5
1. 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

6
1. 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

7
1. 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

8
2. 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.

9
2.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.

10
2.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

11
2.2 Deviation (contd..)
  • Relevant set of grammar symbols

12
2.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.

13
2.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

14
2.3 Semantics (contd..)
  • Terminal strings not sufficient since grammar
    fragments are not necessarily terminated (ex
    productions with bottom non-terminals)
  • Incomplete grammar

15
2.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.

16
2.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.

17
2.3 Semantics (contd..)
  • Looping non-terminals non-terminal b lacks a
    base case
  • Ultimate denotation of n w.r.t

18
3. Formal Reasoning
  • Need to compare grammars, and characterize the
    properties of grammar transformations.
  • Certain relations on the grammar fragments are
    defined.

19
3.1 Equivalent grammars
  • Equivalent grammars
  • Useful in fold/unfold manipulations

20
3.1 Equivalent Grammars
  • Equivalent grammars example
  • Using equivalence properties,

21
3.2 Beyond Equivalence
  • Equivalence often too restrictive to characterize
    related grammars!
  • Some relaxations on the relations between two
    grammars

22
3.2 Beyond Equivalence (contd.)
  • Equivalence modulo renaming
  • In above fig, it holds that

23
3.2 Beyond Equivalence (contd.)
  • Sub-grammar relation
  • In above fig., it holds that but
    not vice versa.

24
3.2 Beyond Equivalence (contd.)
  • Enrichment relation
  • In above fig, it holds that

25
3.2 Beyond Equivalence (contd.)
  • Instance relation
  • In above fig., it holds that

26
3.3 Grammar Transformers
  • Partial grammar transformers Grammar relations
    can be used to define various preservation
    properties for grammar transformations.

27
4. Transformation Framework
  • Define a framework for grammar transformations
    offering transformation primitives and
    combinators.
  • Discuss supplementary concepts like focus,
    constraints and symbolic operands.

28
4.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

29
4.1 Primitives (contd.)
30
4.2 Combinators
31
4.3 Constraints
32
4.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.

33
5.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

34
5.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.

35
5.2 Refactoring (contd.)
36
5.3 Construction
  • Facilitate grammar substitution, extension and
    completion.

37
5.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.

38
5.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.

39
5.4 Destruction
  • Essentially inverse of construction (except
    delete operator)

40
5.4 Destruction (contd.)
  • Separate example

41
5.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.

42
5.5 Discussion
43
5.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

44
6.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.
Write a Comment
User Comments (0)
About PowerShow.com