Notes
Slide Show
Outline
1
Contact
2
What is Software?
3
This is Software
4
Jim Coplien
5
What is Style?
6
Suppose I Wanted...
  • ...to search some source code for...
    • binary operators not flanked by whitespace
    • use of old-style casts
    • using-declarations in a header file
    • \ or /* or " in a header name
    • macro guards not matching filename
    • class name different to filename
    • operator== but no operator!=
    • private inheritance
    • returning a literal
    • returns at different levels of nesting
    • /* inside a comment
    • identifiers that differ only in case
    • things I haven't thought of yet
    • things you'll all now ask for...
7
Style Tools?
8
Sauce
9
Grammar
10
Non Terminals
11
Productions
12
Qualified Symbols
13
Multiplicity
14
Terminals
15
Composite
16
Design
17
Where To Start?
18
multiplicity
  • drive design by considering use
    • how will I typically create multiplicity objects?
    • how can I represent infinity?
19
Special Value
20
multiplicity
21
multiplicity
22
As Values
  • how will I typically use bound values?
23
bound
24
bound Sugar
25
bound Primitives
26
Spot the Bug
27
More of the same
  • same progression for other grammar classes
    • terminal_symbol_definition
    • qualified_symbol_definition
    • production_symbol_definition
    • non_terminal_symbol_definition
  • writing tests
    • forces you to build ever larger objects – e.g. to consider lifetime issues
    • so far I have refactored over 1000 times,
      each time rerunning the tests
28
Problem?
29
Lifetime Problem
  • a qualified-symbol-definition can refer to...
    • a non-terminal-symbol-definition
      • unique per grammar
      • held by value inside grammar object
    • a terminal-symbol-definition
      • can occur multiple times in a grammar
      • exists only via association
30
Solution
31
Parsing
  • now I wanted to actually parse!
32
Visitor
33
visitor
34
Parsing
35
parseable_source
36
Parsing...
  • ...non_terminal_symbol_definitions
37
Parsing...
  • ...production_symbol_definitions
38
Parsing... ...qsd's
39
Parsing....
  • ...terminal_symbol_definitions
40
Reposition
41
Source Parser Visitor
42
Parsing
43
Problem
  • real language grammars...
    • contain informal productions
    • written in natural language
    • how can these be handled?
44
Solution
45
Predicates
46
Grammar Package
47
Framework
48
Problem
49
GOF?
50
Trees
51
AST
52
meta grammar - 1
53
meta grammar - 2
54
meta grammar - 3
55
meta_grammar.hpp
56
meta_grammar.cpp
57
Grammar Generator
58
Software
59
Software
60
Round Tripping!
61
XML
62
C# Grammars
63
Left Recursion
  • left-recursive productions...
    • cause infinite recursion in the descent
    • must be rewritten as right recursive
    • changes associativity
64
C# Parser Visitors
65
C# Source
66
C# Source
67
Collect  ++ --
68
Consistency Metric
69
Consistent Order?
70
Consistent Order
71
That's All Folks!
  • what would you'd like sauce to detect?
    • please tell me