CSG 711 - PowerPoint PPT Presentation

About This Presentation
Title:

CSG 711

Description:

... nonambiguous, LL(1), inductive, non-left recursive: 16 ... Inductive class dictionaries. A node v in a class graph is inductive if there is at least one ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 43
Provided by: karljlie
Category:
Tags: csg | an | in | inductive

less

Transcript and Presenter's Notes

Title: CSG 711


1
CSG 711
  • Karl Lieberherr

2
Matthias Summary(what Karl is allowed to use)
Programming Languages
Semantics
Design
weather models of PLs
Types Logic
Syntax
SE
Reduction semantics (Big, small, medium step
semantics)
extend syntax if not SPC
single point of control (SPC)
3
Matthias Summary(what Karl is allowed to use)
Programming Languages
(Analysis)
Interpretation
data flow analysis control flow analysis abstract
interpretation etc.
connect to model
4
External formats for representing data
  • The essence of XML (by Simeon/Wadler POPL 03)
  • General topic External format for representing
    data External Internal
  • Must have key properties
  • self-describing There must be a function pa
    External -gt Internal. I disagree External, Meta
    -gt Internal
  • round-tripping (pa-1 (pa x)) x for all x in
    External provided type is unambiguous
  • reverse round-tripping

5
Why Essence of XML?
  • Good example of applying the skills that Matthias
    taught to a standard
  • 2 XML projects Christine, Da Lin
  • Matthias and Wadler are co-authors
  • Utterly useful

6
The Next 700 Data Description Languages
  • Fisher, Mandelbaum, Walker (POPL 2006)
  • remarkable insight Types can describe data in
    both its external and internal (programmatic)
    forms.
  • Type T is used to define syntax (external format)
    and semantic properties. Parser is generated to
    translate external format to a data structure
    that has type T.

7
Generalize XML semantics
  • from mark-up languages to a much larger class of
    languages
  • Motivation
  • less verbose languages
  • still easy to read
  • automatic translation grammar G core(G)
    syntaxAspect(G)
  • sentences become robust to changes in grammar
    (bet with Wadler at Schloss Dagstuhl)

8
Automatic translation
  • G1, G2 with core(G1) core(G2) then lambda(x)
    printG2(parseG1 (x)) translates from L(G1) to
    L(G2).

9
Terminology
  • Values
  • external, untyped, sentence
  • internal, typed, object
  • Types
  • validate as Type UntypedValue gt Value
  • Objects(G) parse(Type, Sentences(G))
  • Value erases to UntypedValue
  • Sentences(G) print(Objects(G))
  • parse(t, print(o)) o (reverse round-tripping)

10
Examples
  • Lisp S-expressions for data-type definitions.
  • XML (mark-up languages)
  • Sentences for objects. Provided we have the
    concept of a class dictionary.

11
XML Schema by example
  • Simple and complex types
  • define element title of type xsstring
  • define element author of type xsstring
  • define element paper of type paperType
  • define type paperType
  • element title ,
  • element author

12
XML Schema by example
  • validation annotates each element with a type
  • validate as paper
  • ltpapergt
  • lttitlegt Modula-2 lt/titlegt
  • ltauthorgt Niklaus Wirth lt/authorgt
  • lt/papergt gt
  • element paper of type paperType
  • element title of type string(Modula-2)
  • element author of type string(Niklaus Wirth)

external
internal
13
XML Schema by example(alternative notation)
  • validation annotates each element with a type
  • validate as paper
  • element paper
  • element title Modula-2,
  • element author Niklaus Wirth
  • gt
  • element paper of type paperType
  • element title of type string(Modula-2)
  • element author of type string(Niklaus Wirth)

external
internal
14
Generalize (same)
  • Simple and complex types
  • define element title of type xsstring
  • define element author of type xsstring
  • define element paper of type paperType
  • define type paperType
  • element title ,
  • element author

15
Generalize
  • validation annotates each element with a type
  • validate as paper
  • Modula-2 Niklaus Wirth gt
  • element paper of type paperType
  • element title of type string(Modula-2)
  • element author of type string(Niklaus Wirth)

external
internal
16
Generalize (want XML)
  • Simple and complex types
  • define element title of type xsstring
  • before lttitlegt after lt/titlegt
  • define element author of type xsstring
  • before ltauthorgt after lt/authorgt
  • define element paper of type paperType
  • before ltpapergt after lt/papergt
  • define type paperType
  • element title ,
  • element author

17
Generalize (want XML)(for alternative syntax)
  • Simple and complex types
  • define element title of type xsstring
  • before element title after
  • define element author of type xsstring
  • before element author after
  • define element paper of type paperType
  • before element paper after
  • define type paperType
  • element title ,
  • element author

18
What is going on?
  • Define aspects on types. We did that also in hw 8
    ?!
  • Types plus decoration aspects or external
    representation aspects or printing aspects or
    type erasure aspects.
  • When can we do the parsing?
  • Add much more information during validation.

19
Radical Type Erasure
  • Class dictionary G type definitions plus
    external representation aspects
  • Use restricted form of type definitions

20
XML Types (modeled on regular tree grammars)
  • Type ()
  • ItemType
  • Type , Type
  • Type Type
  • Type Occurrance
  • Occccurrance ?
  • ItemType ElementType AtomicTypeName
  • ElementType element ElementName? OfType?
  • OfType of type TypeName

21
XML Types (modeled on regular tree grammars)
  • Type ()
  • ItemType
  • Type , Type
  • Type Type
  • Type Occurrance
  • Occurrance ? before after
  • ItemType ElementType AtomicTypeName
  • ElementType element ElementName? OfType?
    before after
  • OfType of type TypeName
  • Definition define element ElementName OfType
  • define type TypeName Type

22
Typed XML Values
  • Value () Item (, Item)
  • Item Element Atom
  • Element element ElementName OfType? Value
  • OfType of type TypeName
  • Atom String Integer

23
Untyped XML Values
  • UntypedValue ()
  • UntypedItem (, UntypedItem)
  • UntypedItem element ElementName
    UntypedValue SimpleValue
  • SimpleValue () Atom (,Atom)

24
Want less info Untyped Values
  • UntypedValue ()
  • AtomOrToken (, AtomOrToken)
  • AtomOrToken Atom Token

25
Examples
  • element paper of type paperType
  • element title of type xsstring Modula-2,
  • element author of type xsstring Niklaus
    Wirth
  • element paper
  • element title Modula-2,
  • element author Niklaus Wirth

26
Validation theorem
  • We have that
  • validate as Type UntypedValue gt Value
  • iff
  • Value matches Type and
  • Value erases to UntypedValue

27
Validation theorem(more general)
  • Type.parse(Sentence) gt Object
  • iff
  • Object matches Type and
  • print(Object) gt Sentence

28
Roundtripping Theorem
  • If
  • Object matches Type
  • Value erases to UntypedValue
  • validate as Type UntypedValue gt Value
  • Type is unambiguous for validation
  • then
  • Value Value

29
Roundtripping Theorem(more general)
  • If
  • Object matches Type
  • print(Object) gt Sentence
  • Type.parse(Sentence) gt Object
  • Type is unambiguous
  • then
  • Object Object

30
Reduction semantics for hw 8
  • (traverse c o s v)
  • Transition states (at O, at TGv1,,vn, value of
    visitor)
  • Values

31
Topic switch
32
class dictionaries (11 kinds)
inductive
nonleft-recursive
9
10
8
11
7
6
1
2
LL(1)
3
4
nonambiguous
5
Venn Diagram
33
11 kinds of class dictionaries
  • Why 11 and not 16?
  • Four properties nonambiguous, LL(1), inductive,
    non-left recursive 16 sets if independent
  • But implication relationships
  • LL(1) implies nonambiguous 12 left
  • LL(1) and inductive imply nonleft-recursive 11
    left

34
Inductive class dictionaries
  • inductiveness already defined for class graphs
  • contains only good recursions recursions that
    terminate

Car Motor. Motor ltbelongsTogt Car.
bad recursion, objects must be cyclic, cannot use
for parsing useless nonterminals
35
Inductive class dictionaries
  • A node v in a class graph is inductive if there
    is at least one finite tree object of class v.
  • A class graph is inductive if all its nodes are
    inductive.

Car Motor Transmission. Motor ltbelongsTogt
Car. Transmission .
Which nodes are inductive?
36
Inductiveness style rule to follow
  • Maximize the number of classes which are
    inductive.
  • Reasons cyclic objects
  • cannot be parsed directly from sentences.
  • require visitors to break infinite loops.
  • it is harder to reason about cyclic objects.
  • No message from the Java Compiler Compiler!

37
Left-recursive class dictionaries
  • Bring us back to the same class without consuming
    input.
  • Java Compiler Compiler
  • left recursion detected
  • A -gt C -gt A

A B C. B b. C A.
38
Ambiguous class dictionaries
  • cannot distinguish between objects. Print is not
    injective (one-to-one).

Fruit Apple Orange. Apple a. Orange a.
But undecidable
39
Java Compiler Compilererror message
  • Warning Choice conflict
  • A common prefix is a.
  • Consider using a lookahead of 2 ...

40
LL(1) class dictionaries
  • A special kind of nonambiguous class
    dictionaries. Membership can be checked
    efficiently.

41
Java Compiler CompilerLL(1) error messages Rule
2
  • A B. B .
  • Error message expansion can be mapped by empty
    string, line x, column y in Parser.jj.
  • A B b C. B b. C .
  • Warning only Choice conflict line x column y.
    Expansion nested within construct and expansion
    following construct have common prefixes one of
    which is b.

42
Style rule
  • Ideally, make your class dictionaries LL(1),
    nonleft-recursive and inductive.
Write a Comment
User Comments (0)
About PowerShow.com