Title: CSG 711
1CSG 711
2Matthias 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)
3Matthias Summary(what Karl is allowed to use)
Programming Languages
(Analysis)
Interpretation
data flow analysis control flow analysis abstract
interpretation etc.
connect to model
4External 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
5Why 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
6The 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.
7Generalize 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)
8Automatic translation
- G1, G2 with core(G1) core(G2) then lambda(x)
printG2(parseG1 (x)) translates from L(G1) to
L(G2).
9Terminology
- 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)
10Examples
- Lisp S-expressions for data-type definitions.
- XML (mark-up languages)
- Sentences for objects. Provided we have the
concept of a class dictionary.
11XML 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
12XML 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
13XML 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
14Generalize (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
15Generalize
- 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
16Generalize (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
17Generalize (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
18What 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.
19Radical Type Erasure
- Class dictionary G type definitions plus
external representation aspects - Use restricted form of type definitions
20XML 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
21XML 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
22Typed XML Values
- Value () Item (, Item)
- Item Element Atom
- Element element ElementName OfType? Value
- OfType of type TypeName
- Atom String Integer
-
23Untyped XML Values
- UntypedValue ()
- UntypedItem (, UntypedItem)
- UntypedItem element ElementName
UntypedValue SimpleValue - SimpleValue () Atom (,Atom)
24Want less info Untyped Values
- UntypedValue ()
- AtomOrToken (, AtomOrToken)
- AtomOrToken Atom Token
25Examples
- 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
-
-
26Validation theorem
- We have that
- validate as Type UntypedValue gt Value
- iff
- Value matches Type and
- Value erases to UntypedValue
27Validation theorem(more general)
- Type.parse(Sentence) gt Object
- iff
- Object matches Type and
- print(Object) gt Sentence
28Roundtripping Theorem
- If
- Object matches Type
- Value erases to UntypedValue
- validate as Type UntypedValue gt Value
- Type is unambiguous for validation
- then
- Value Value
29Roundtripping Theorem(more general)
- If
- Object matches Type
- print(Object) gt Sentence
- Type.parse(Sentence) gt Object
- Type is unambiguous
- then
- Object Object
30Reduction semantics for hw 8
- (traverse c o s v)
- Transition states (at O, at TGv1,,vn, value of
visitor) - Values
31Topic switch
32class dictionaries (11 kinds)
inductive
nonleft-recursive
9
10
8
11
7
6
1
2
LL(1)
3
4
nonambiguous
5
Venn Diagram
3311 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
34Inductive 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
35Inductive 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?
36Inductiveness 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!
37Left-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.
38Ambiguous class dictionaries
- cannot distinguish between objects. Print is not
injective (one-to-one).
Fruit Apple Orange. Apple a. Orange a.
But undecidable
39Java Compiler Compilererror message
- Warning Choice conflict
- A common prefix is a.
- Consider using a lookahead of 2 ...
40LL(1) class dictionaries
- A special kind of nonambiguous class
dictionaries. Membership can be checked
efficiently.
41Java 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.
42Style rule
- Ideally, make your class dictionaries LL(1),
nonleft-recursive and inductive.