130 likes | 257 Views
This comprehensive guide dives into the concept of class dictionaries, a unique type of grammar that describes the inheritance and binary relation structures in applications. It explores symbols such as “=”, “:”, “~”, and “{}” used in defining relationships and properties. Through examples such as baskets containing fruits, the text illustrates the differences between non-ambiguous, LL(1), and inductive definitions in class dictionaries. Discover the intricacies of left-recursion, examples of inductive parsing, and the structures that define object graphs.
E N D
Class Dictionary Jun Gong CCIS NEU SP 04
What is a class dictionary? • A special type of grammar. • Describes the inheritance and the binary relation structure of your application. • “=” and “:”. “has a” and “is a”. • “~”, and “{}”. The list function. • “[]” and “<>”.
Example • Basket = "basket" List(Thing) "end". • Thing : Fruit | Basket. • Fruit : Apple | Orange. • Apple = “apple” [<w> Weight]. • Orange = “orange” [<w> Weight]. • Weight = <i> int. • List(S) ~{S}.
class dictionaries (11 kinds) inductive nonleft-recursive 9 10 11 8 7 6 1 2 LL(1) 3 4 nonambiguous 5 Venn Diagram
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
Nonambiguous • The definition. • Example: • Apple = “apple”. • Orange = “apple”.
LL(1) • The definition. • Example 1: • Apple = Weight “apple”. • Orange = Weight “orange”. • Weight = int. • Example 1 revised: • Apple = “apple” Weight. • Orange = “orange” Weight. • Weight = int.
Nonleft-recursive • Definition. • Directly left-recursive: • A = A “char”. • Indirectly left-recursive: • A1 = A2 “char1”. • A2 = A1 “char2”. • Left-recursion removal: • A = A B | B. A = BP. P = B P | .
Inductive • Definition. • Example 1: • Apple = “apple”. • Example 2: • ManyApples = Apple ManyApples. • Apple = “apple”. • Inductive Good Recursive.
What DemeterJ Wants • LL(1) • Nonleft-recursive • Inductive
Parsing • Basket = "basket" List(Thing) "end". • Thing : Fruit | Basket. • Fruit : Apple | Orange. • Apple = "apple". • Orange = “orange”. • List(S) ~{S}.
Basket {Apple, Basket} {Apple, Orange} Parsing Cont. • basket • apple • basket • apple • orange • end • end
Basket Apple Basket Apple Orange Object Graph • : Basket ( • <thing_list> : Thing_List { • <first> : Nonempty_Thing_List ( • <it> : Apple ( ) • <next> : Nonempty_Thing_List ( • <it> : Basket ( • <thing_list> : Thing_List { • <first> : Nonempty_Thing_List ( • <it> : Apple ( ) • <next> : Nonempty_Thing_List ( • <it> : Orange ( ) ) ) } ) ) ) } )