SlideShare une entreprise Scribd logo
1  sur  236
Declarative Syntax Definition
pretty printing

Guido Wachsmuth




       Delft
                                Course IN4303 2012/13
       University of
       Technology                Compiler Construction
       Challenge the future
Assessment
last lecture




               Pretty Printing   2
Assessment
last lecture

Compare SDF with the plain formalism of context-free grammars.




                                                  Pretty Printing   2
Assessment
last lecture

Compare SDF with the plain formalism of context-free grammars.

Discuss additional description means provided by SDF and why
they are needed in compiler construction.




                                                  Pretty Printing   2
Assessment
last lecture

Compare SDF with the plain formalism of context-free grammars.

Discuss additional description means provided by SDF and why
they are needed in compiler construction.
  •   regular expressions




                                                  Pretty Printing   2
Assessment
last lecture

Compare SDF with the plain formalism of context-free grammars.

Discuss additional description means provided by SDF and why
they are needed in compiler construction.
  •   regular expressions
  •   layout




                                                  Pretty Printing   2
Assessment
last lecture

Compare SDF with the plain formalism of context-free grammars.

Discuss additional description means provided by SDF and why
they are needed in compiler construction.
  •   regular expressions
  •   layout
  •   AST constructors




                                                  Pretty Printing   2
Assessment
last lecture

Compare SDF with the plain formalism of context-free grammars.

Discuss additional description means provided by SDF and why
they are needed in compiler construction.
  •   regular expressions
  •   layout
  •   AST constructors
  •   follow restrictions




                                                  Pretty Printing   2
Assessment
last lecture

Compare SDF with the plain formalism of context-free grammars.

Discuss additional description means provided by SDF and why
they are needed in compiler construction.
  •   regular expressions
  •   layout
  •   AST constructors
  •   follow restrictions
  •   annotations for associativity




                                                  Pretty Printing   2
Assessment
last lecture

Compare SDF with the plain formalism of context-free grammars.

Discuss additional description means provided by SDF and why
they are needed in compiler construction.
  •   regular expressions
  •   layout
  •   AST constructors
  •   follow restrictions
  •   annotations for associativity
  •   priorities




                                                  Pretty Printing   2
Overview
today’s lecture




                  Lexical Analysis   3
Overview
today’s lecture

plagues of traditional parsing algorithms

  •   paradise lost
  •   paradise regained




                                            Lexical Analysis   3
Overview
today’s lecture

plagues of traditional parsing algorithms

  •    paradise lost
  •    paradise regained
pretty-printing
  •    from trees to text
  •    box layout in pretty-print tables




                                            Lexical Analysis   3
Overview
today’s lecture

plagues of traditional parsing algorithms

  •    paradise lost
  •    paradise regained
pretty-printing
  •    from trees to text
  •    box layout in pretty-print tables
template language
  •    alternative to SDF
  •    generation of pretty-printing strategies
  •    generation of completion templates


                                                  Lexical Analysis   3
I
paradise lost & regained




                           Pretty Printing   4
Pure and Declarative
       Syntax Definition:
 Paradise Lost and Regained

Lennart Kats       Eelco Visser       Guido Wachsmuth

               Delft University of Technology
PARADISE
PARADISE LOST
PARADISE
REGAINED
PARADISE DENIED
PARADISE
WORDS
TREES
GRAMMARS
LANGUAGE
ENGINEERS
LANGUAGES
GRAMMARS
NATURAL
PURE
BEAUTIFUL
SOFTWARE
ENGINEERS
LANGUAGE
SOFTWARE
NOT
NATURAL
NOT
PURE
NOT
BEAUTIFUL
SYNTAX
DEFINITIONS
NATURAL
PURE
BEAUTIFUL
THE FALL
PARSER
DEFINITIONS
PARADISE LOST
PAIN
SWEAT
NOT
NATURAL
NOT
PURE
NOT
BEAUTIFUL
THE PLAGUES
context-free grammars




      LL(k)        LR(k)




      LL(1)        LR(1)
                 LALR(1)
                    SLR


      LL(0)        LR(0)



GRAMMAR
 CLASSES
DISAMBIGUATION
LEXICAL SYNTAX
TREE
CONSTRUCTION
EVOLUTION
COMPOSITION
RESTRICTION
  TO PARSERS
PARADISE
WORDS WERE MADE THROUGH
   GRAMMARS
GRAMMARS
Num ➝ Digit Num
Num ➝ Digit
Digit ➝ “0”
Digit ➝ “1”
Num ➝ Digit Num
Num ➝ Digit
Digit ➝ “0”
Digit ➝ “1”




                  production rules
Num ➝ Digit Num
Num ➝ Digit
Digit ➝ “0”
Digit ➝ “1”


                  terminal symbols
                   production rules
Num ➝ Digit Num
Num ➝ Digit
Digit ➝ “0”
Digit ➝ “1”
                  nonterminal symbols
                    terminal symbols
                    production rules
Num ➝ Digit Num
Num ➝ Digit
Digit ➝ “0”
Digit ➝ “1”
                  nonterminal symbols
                    terminal symbols
                    production rules
                      start symbol
WORDS
Num
Num         Num ➝ Digit Num
Digit Num
Num           Num ➝ Digit Num
Digit Num     Num ➝ Digit
Digit Digit
Num           Num ➝ Digit Num
Digit Num     Num ➝ Digit
Digit Digit   Digit ➝ “0”
Digit 0
Num           Num ➝ Digit Num
Digit Num     Num ➝ Digit
Digit Digit   Digit ➝ “0”
Digit 0       Digit ➝ “1”
10
SENTENCES
Exp ➝ Exp “+” Exp
Exp ➝ Exp “*” Exp
Exp ➝ Num




                    production rules
Exp ➝ Exp “+” Exp
Exp ➝ Exp “*” Exp
Exp ➝ Num



                    terminal symbols
                     production rules
Exp ➝ Exp “+” Exp
Exp ➝ Exp “*” Exp
Exp ➝ Num

                    nonterminal symbols
                      terminal symbols
                      production rules
Exp ➝ Exp “+” Exp
Exp ➝ Exp “*” Exp
Exp ➝ Num

                    nonterminal symbols
                      terminal symbols
                      production rules
                        start symbol
Exp
Exp         Exp ➝ Exp “+” Exp
Exp + Exp
Exp               Exp ➝ Exp “+” Exp
Exp + Exp         Exp ➝ Exp “*” Exp
Exp * Exp + Exp
Exp               Exp ➝ Exp “+” Exp
Exp + Exp         Exp ➝ Exp “*” Exp
Exp * Exp + Exp   Exp ➝ Num
3 * Exp + Exp
Exp               Exp ➝ Exp “+” Exp
Exp + Exp         Exp ➝ Exp “*” Exp
Exp * Exp + Exp   Exp ➝ Num
3 * Exp + Exp     Exp ➝ Num
3 * 7 + Exp
Exp               Exp ➝ Exp “+” Exp
Exp + Exp         Exp ➝ Exp “*” Exp
Exp * Exp + Exp   Exp ➝ Num
3 * Exp + Exp     Exp ➝ Num
3 * 7 + Exp       Exp ➝ Num
3 * 7 + 21
THEY MADE LANGUAGES
     BY MAKING GRAMMARS
GRAMMAR
LANGUAGE
TRUTH
Exp ➝ Exp “+” Exp   Exp “+” Exp ➝ Exp
Exp ➝ Exp “*” Exp   Exp “*” Exp ➝ Exp
Exp ➝ Num                 Num ➝ Exp



productive           reductive
3 * 7 + 21
3 * 7 + 21    Num ➝ Exp
3 * 7 + Exp
3 * 7 + 21      Num ➝ Exp
3 * 7 + Exp     Num ➝ Exp
3 * Exp + Exp
3 * 7 + 21        Num ➝ Exp
3 * 7 + Exp       Num ➝ Exp
3 * Exp + Exp     Num ➝ Exp
Exp * Exp + Exp
3 * 7 + 21              Num ➝ Exp
3 * 7 + Exp             Num ➝ Exp
3 * Exp + Exp           Num ➝ Exp
Exp * Exp + Exp   Exp “*” Exp ➝ Exp
Exp + Exp
3 * 7 + 21              Num ➝ Exp
3 * 7 + Exp             Num ➝ Exp
3 * Exp + Exp           Num ➝ Exp
Exp * Exp + Exp   Exp “*” Exp ➝ Exp
Exp + Exp         Exp “+” Exp ➝ Exp
Exp
THEY TURNED WORDS INTO
      TREES
SENTENCES
STRUCTURE
Exp ➝ Exp “+” Exp   Exp “+” Exp ➝ Exp
Exp ➝ Exp “*” Exp   Exp “*” Exp ➝ Exp
Exp ➝ Num                 Num ➝ Exp



productive           reductive
Exp          Exp            Exp

Num        Exp + Exp      Exp * Exp



      tree construction
3 * 7 + 21
Exp

Num   Exp   Exp   Exp

      3 * 7 + 21
Exp         Exp

Exp + Exp
    *       Exp   Exp   Exp

            3 * 7 + 21
Exp

  Exp         Exp

Exp + Exp   Exp   Exp   Exp

            3 * 7 + 21
ONE FORMALISM
THREE READINGS
PURE
DECLARATIVE
BEAUTIFUL
PARADISE LOST
EFFICIENCY
THE FIRST PLAGUE WERE
GRAMMAR CLASSES
context-free grammars
context-free grammars




    LL(0)
context-free grammars




    LL(1)




    LL(0)
context-free grammars




    LL(k)




    LL(1)




    LL(0)
context-free grammars




    LL(k)




    LL(1)




    LL(0)        LR(0)
context-free grammars




    LL(k)




    LL(1)        LR(1)




    LL(0)        LR(0)
context-free grammars




    LL(k)        LR(k)




    LL(1)        LR(1)




    LL(0)        LR(0)
context-free grammars




    LL(k)        LR(k)




    LL(1)        LR(1)


                  SLR


    LL(0)        LR(0)
context-free grammars




    LL(k)        LR(k)




    LL(1)        LR(1)
               LALR(1)
                  SLR


    LL(0)        LR(0)
Exp “+” Exp ➝ Exp   Term (“+” Term)* ➝ Exp
Exp “*” Exp ➝ Exp    Fact (“*” Fact)* ➝ Term
      Num ➝ Exp                  Num ➝ Fact



 paradise           grammar classes
Exp

                             *

      Exp                         *

  Exp               Term Term Term

Exp   Exp   Exp     Fact   Fact       Fact

3 + 7 + 21           3 + 7 + 21


 paradise         grammar classes
THE SECOND PLAGUE WAS
DISAMBIGUATION
Exp               Exp

  Exp                     Exp

Exp   Exp   Exp   Exp   Exp   Exp

3 * 7 + 21        3 * 7 + 21
precedence         operators               associativity
    1                 ( ), [ ]            non-associative
    2                  new                non-associative
    3                    .                left-associative
    4                 ++, --              non-associative
    5        -, +, !, ~, ++, --, (type)   right-associative
    6                 *, /, %             left-associative
    7                  +, -               left-associative
   …                    …                        …


              text books
context-free grammars




    LL(k)        LR(k)




    LL(1)        LR(1)
               LALR(1)
                  SLR


    LL(0)        LR(0)
context-free grammars


      unambigous


    LL(k)          LR(k)




    LL(1)          LR(1)
               LALR(1)
                   SLR


    LL(0)          LR(0)
Exp “+” Term ➝ Exp
          Term ➝ Exp
 Term “*” Fact ➝ Term
          Fact ➝ Term
          Num ➝ Fact


grammar classes
FALSE PROPHETS
L = {ab, a}   L = {ab, a}



“a” “b” ➝ A   “a” “b” /
    “a” ➝ A   “a”     ➝A




paradise        PEGs
L = {ab, a}     L = {a}



    “a” ➝ A   “a”     /
“a” “b” ➝ A   “a” “b” ➝ A




paradise        PEGs
if c1 then if c2 then s1 else s2



      dangling else
“if ” E “then” S “else” S /    “if ” E “then” S          /
“if ” E “then” S          ➝S   “if ” E “then” S “else” S ➝ S




                           PEGs
THE THIRD PLAGUE WAS
LEXICAL SYNTAX
morphology & syntax
LL(k)    LR(k)




      LL(1)    LR(1)
              LALR(1)
               SLR


      LL(0)    LR(0)




limited look-ahead
scanners
3 * 7 + 21
3 * 7 + 21
parsers
3 * 7 + 21
Exp

  Exp

Exp   Exp   Exp

3 * 7 + 21
x = 1. * .10

y   :   array [ 1 .. 10 ] of integer
x = 1. * .10

y   :   array [ 1 .. 10 ] of integer
x = 1. * .10

y   :   array [ 1. .10 ]   of integer
THE FOURTH PLAGUE WAS
TREE CONSTRUCTION
Exp                            Add

  Exp                              Add

Exp   Exp   Exp              Const Const Const

3 + 7 + 21                     3         7   21


                  paradise
Exp

         *                       Add

              *                Add

Term Term Term           Const Const Const

Fact   Fact       Fact     3         7   21

 3 + 7 + 21

              grammar classes
expr:
  INTEGER       { $$ = con($1); }
| expr '+' expr { $$ = opr('+', 2, $1, $3);}
| expr '*' expr { $$ = opr('*', 2, $1, $3);}
;




            semantic actions
THE FIFTH PLAGUE WAS
 EVOLUTION
Exp “+” Term ➝ Exp
Exp “+” Exp ➝ Exp               Term ➝ Exp
Exp “*” Exp ➝ Exp      Term “*” Fact ➝ Term
      Num ➝ Exp                 Fact ➝ Term
                                Num ➝ Fact

  paradise          grammar classes
CExp “+” Term ➝ CExp
                             Term ➝ CExp
Exp “+” Exp ➝ Exp      Term “*” Fact ➝ Term
Exp “*” Exp ➝ Exp               Fact ➝ Term
      Num ➝ Exp                 Num ➝ Fact

Exp “=” Exp ➝ Exp       Exp “=” CExp ➝ Exp
Exp “<” Exp ➝ Exp       Exp “<” CExp ➝ Exp
Exp “>” Exp ➝ Exp       Exp “>” CExp ➝ Exp
                                CExp ➝ Exp

  paradise          grammar classes
THE SIXTH PLAGUE WAS
COMPOSITION
parsers
context-free grammars




    LL(k)        LR(k)




    LL(1)        LR(1)
               LALR(1)
                  SLR


    LL(0)        LR(0)
context-free grammars




    LL(k)        LR(k)




    LL(1)        LR(1)
               LALR(1)
                  SLR


    LL(0)        LR(0)
context-free grammars




    LL(k)        LR(k)




    LL(1)        LR(1)
               LALR(1)
                  SLR


    LL(0)        LR(0)
context-free grammars




    LL(k)        LR(k)




    LL(1)        LR(1)
               LALR(1)
                  SLR


    LL(0)        LR(0)
scanners
public boolean
  authenticate(String user, String pw) {

    SQL stm = <| SELECT id FROM Users
                 WHERE name = ${user}
                 AND   password = ${pw} |>;

    return executeQuery(stm).size() != 0;
}
THE SEVENTH PLAGUE WAS
RESTRICTION
         TO
    PARSERS
PRETTY PRINTERS
SENTENCE
GENERATORS
AST ACCESS
IDE SUPPORT
PARADISE
REGAINED
GENERALISED
PARSING
context-free grammars




    LL(k)        LR(k)




    LL(1)        LR(1)
               LALR(1)
                  SLR


    LL(0)        LR(0)
context-free grammars
context-free syntax
Exp “+” Exp ➝ Exp
Exp “*” Exp ➝ Exp     Exp "+" Exp -> Exp
      Num ➝ Exp       Exp "*" Exp -> Exp
                      NUM         -> Exp


  paradise                 SDF
DECLARATIVE
DISAMBIGUATION
context-free grammars


      unambigous


    LL(k)          LR(k)




    LL(1)          LR(1)
               LALR(1)
                   SLR


    LL(0)          LR(0)
context-free grammars


      unambigous
context-free grammars
precedence         operators               associativity
    1                 ( ), [ ]            non-associative
    2                  new                non-associative
    3                    .                left-associative
    4                 ++, --              non-associative
    5        -, +, !, ~, ++, --, (type)   right-associative
    6                 *, /, %             left-associative
    7                  +, -               left-associative
   …                    …                        …


              text books
context-free priorities

  Exp "*" Exp -> Exp {left}
> Exp "+" Exp -> Exp {left}
context-free syntax
    	
  "if" E "then" S          -> S {prefer}
  "if" E "then" S "else" S -> S
SCANNERLESS
PARSING
morphology & syntax
lexical syntax
    	
  [0-9]+ -> NUM

  [ tn]         -> LAYOUT
  "//" ~[n]* [n] -> LAYOUT
parser
parser
DECLARATIVE
TREE CONSTRUCTION
Exp                            Add

  Exp                              Add

Exp   Exp   Exp              Const Const Const

3 + 7 + 21                     3         7   21


                  paradise
context-free syntax
    	
  Exp "+" Exp -> Exp {cons("Add")}
  Exp "*" Exp -> Exp {cons("Mul")}
  NUM         -> Exp {cons("Const")}



               SDF
Add          Add(
                       Add(
      Add                 Const("3"),
                          Const("7")
Const Const Const      ),
                       Const("21")
  3         7   21   )


  paradise                SDF
SEAMLESS
EVOLUTION
context-free syntax
    	
  Exp "+" Exp -> Exp {cons("Add")}
  Exp "*" Exp -> Exp {cons("Mul")}
  NUM         -> Exp {cons("Const")}

  Exp "=" Exp -> Exp {cons("Eq")}
  Exp ">" Exp -> Exp {cons("Gt")}
  Exp "<" Exp -> Exp {cons("Lt")}
MODULAR
COMPOSITION
context-free grammars




    LL(k)        LR(k)




    LL(1)        LR(1)
               LALR(1)
                  SLR


    LL(0)        LR(0)
context-free grammars
public boolean
  authenticate(String user, String pw) {

    SQL stm = <| SELECT id FROM Users
                 WHERE name = ${user}
                 AND   password = ${pw} |>;

    return executeQuery(stm).size() != 0;
}
module Java-SQL
  imports
    Java SQL

  exports
    context-free syntax

    "<|" Query "|>" -> Exp {cons("ToSQL")}
    "${" Exp "}" -> SqlExp {cons("FromSQL")}
BEYOND
PARSERS
PRETTY PRINTERS
SENTENCE
GENERATORS
AST ACCESS
IDE SUPPORT
PARADISE DENIED
still around
still around
still have to use it
still have to learn
LL, LR, SLR, LALR
still think using
parser generators is hard
modern parser generator
modern parser generator
PARADISE OPEN
coffee break




               Pretty Printing 181
II
pretty-printing




                  Pretty Printing 182
Recap: Parsing & AST construction
let
      function fact(n : int): int = if n < 1 then 1 else n * fact(n - 1)
in
      printint(fact(10))
end


Let(
   [     FunDec(
            "fact"
         , [FArg("n", Tid("int"))]
         , Tid("int")
         , IfThenElse(
               Lt(Var("n"), Int("1"))
            , Int("1")
            , Times(Var("n"), Call("fact", [Minus(Var("n"), Int("1"))]))
            )
         )
      ]
,     [Call("printint", [Call("fact", [Int("10")])])]
)



                                                               Pretty Printing 183
Pretty Printing

from ASTs to text

   •   keywords

   •   layout: spaces, line breaks, indentation

specification

   •   partially defined in grammar

   •   missing layout




                                                  Pretty Printing 184
Box Layout
basic boxes


                 “foo”


              KW [ “foo” ]


                  _1




                             Pretty Printing 185
Box Layout
horizontal boxes


            H hs=x [ B     B       B ]




                   B   B       B




                                         Pretty Printing 186
Box Layout
vertical boxes


          V vs=y is=i [ B
            hs=x            B   B ]


                    B


                        B


                        B

                                      Pretty Printing 187
Pretty Print Tables
generation

"if" Exp "then" Exp              -> Exp {"IfThen"}
"let" Dec* "in" {Exp ";"}* "end" -> Exp {"Let"}




Exp.IfThen -- KW["if"] _1 KW["then"] _2,
Exp.Let    -- KW["let"] _1 KW["in"] _2 KW["end"],

Exp.Let.1:iter-star     -- _1,
Exp.Let.2:iter-star-sep -- _1 KW[";"]



                                             Pretty Printing 188
Pretty Print Tables
manual override

"if" Exp "then" Exp              -> Exp {"IfThen"}
"let" Dec* "in" {Exp ";"}* "end" -> Exp {"Let"}




Exp.Let -- V vs=1 is=0 [
             V vs=1 is=2 [KW["let"] _1]
             V vs=1 is=2 [KW["in"] _2]
             KW["end"]
           ]



                                             Pretty Printing 189
III
syntax templates




                   Pretty Printing 190
Recap: SDF
sorts Exp
	
context-free syntax

    LValue ":=" Exp                        -> Exp
	    	
    "let" Dec* "in" {Exp ";"}* "end"       -> Exp

     "if" Exp "then" Exp                   -> Exp
     "if" Exp "then" Exp "else" Exp        -> Exp
    	
     "while" Exp "do" Exp                  -> Exp
     "for" Id ":=" Exp "to" Exp "do" Exp   -> Exp

    "break"                                -> Exp

    "(" ")"            -> Exp
    "(" Exp ")"        -> Exp
    "(" {Exp ";"}+ ")" -> Exp




                                                    Pretty Printing 191
Pretty Print Tables
manual overrides



Exp.Let -- V vs=1 is=0 [
             V vs=1 is=2 [KW["let"] _1]
             V vs=1 is=2 [KW["in"] _2]
             KW["end"]
           ]




                                          Pretty Printing 192
Recap: Code Completion
module Tiger-Completions

imports Tiger-Completions.generated

completions

    completion keyword   : "function"
	
    completion template Exp:

         "if " <e> " thennt" <s> (blank)
	
    completion proposer : editor-complete




                                             Pretty Printing 193
Templates
explicit layout in syntax definitions

context-free syntax

   Exp "+"   Exp -> Exp {left, "Plus"}
   Exp "-"   Exp -> Exp {left, "Minus"}




context-free syntax

   Exp.Plus = <<Exp> + <Exp>> {left}
   Exp.Minus = <<Exp> - <Exp>> {left}




                                          Pretty Printing 194
Templates
explicit layout in syntax definitions

context-free syntax

   "let" Dec* "in" {Exp ";"}* "end" "   Exp {"Let"}


context-free syntax

   Exp.Let = <
     let
        <Dec*; separator="n">
     in
        <Exp*; separator=";n">
     end>


                                              Pretty Printing 195
IV
summary




          Pretty Printing 196
Summary
lessons learned




                  Pretty Printing 197
Summary
lessons learned

Why are efficient parsing algorithms problematic?
  •   not longer pure, declarative, beautiful
  •   paradise lost: seven plagues
  •   paradise regained: scannerless generalised parsing




                                                           Pretty Printing 197
Summary
lessons learned

Why are efficient parsing algorithms problematic?
  •   not longer pure, declarative, beautiful
  •   paradise lost: seven plagues
  •   paradise regained: scannerless generalised parsing
How can we specify pretty-printers?
  •   generated from SDF
  •   manual overrides
  •   one stop shop: TemplateLanguage




                                                           Pretty Printing 197
Summary
lessons learned

Why are efficient parsing algorithms problematic?
  •   not longer pure, declarative, beautiful
  •   paradise lost: seven plagues
  •   paradise regained: scannerless generalised parsing
How can we specify pretty-printers?
  •   generated from SDF
  •   manual overrides
  •   one stop shop: TemplateLanguage




                                                           Pretty Printing 197
Literature
learn more




             Pretty Printing 198
Literature
learn more

declarative syntax definition
    Lennart C. L. Kats, Eelco Visser, Guido Wachsmuth: Pure and Declarative
    Syntax Definition - Paradise Lost and Regained. SPLASH 2010




                                                                 Pretty Printing 198
Literature
learn more

declarative syntax definition
    Lennart C. L. Kats, Eelco Visser, Guido Wachsmuth: Pure and Declarative
    Syntax Definition - Paradise Lost and Regained. SPLASH 2010

pretty-printing
    Marc G.J. van den Brand, Eelco Visser: Generation of Formatters for Context-
    Free Languages. ACM TOSEM 5(1):1-41, 1996.

    Merijn de Jonge. Pretty-Printing for Software Reengineering. ICSM 2002




                                                                  Pretty Printing 198
Literature
learn more

declarative syntax definition
    Lennart C. L. Kats, Eelco Visser, Guido Wachsmuth: Pure and Declarative
    Syntax Definition - Paradise Lost and Regained. SPLASH 2010

pretty-printing
    Marc G.J. van den Brand, Eelco Visser: Generation of Formatters for Context-
    Free Languages. ACM TOSEM 5(1):1-41, 1996.

    Merijn de Jonge. Pretty-Printing for Software Reengineering. ICSM 2002

template language
    Tobi Vollebregt, Lennart C. L. Kats, Eelco Visser. Declarative Specification of
    Template-Based Textual Editors. LDTA 2012


                                                                      Pretty Printing 198
Outlook
beyond IN4303

Model-driven Software Development
  •   domain-specific languages
  •   build your own language with Spoofax

Seminar Metaprogramming
  •   science behind the scenes

Master theses
  •   theory & practice
  •   WebDSL & mobl
  •   Spoofax



                                             Pretty Printing 199
Outlook
coming next

declarative semantics definition
  •    Lecture 4: Term Rewriting
  •    Lecture 5: Static Analysis and Error Checking
  •    Lecture 6: Code Generation

Labs
  •    Sep 27 syntax definition

  •    Oct 4 code completion & pretty printing




                                                       Pretty Printing 200
copyrights




             Pretty Printing 201
Pretty Printing 202
Pictures
attribution & copyrights

Slide 1:
   Latin Bible by Gerard Brils (photo by Adrian Pingstone), public domain

Slide 188:
   West Cornwall Pasty Co. by Dominica Williamson, some rights reserved

Slide 199-200:
   Ostsee by Mario Thiel, some rights reserved

Slides 5-180:
   Pure and Declarative Syntax Definition: Paradise Lost and Regained, some rights reserved




                                                                            Pretty Printing 203

Contenu connexe

Tendances

Introduction to regular expressions
Introduction to regular expressionsIntroduction to regular expressions
Introduction to regular expressionsBen Brumfield
 
163692498 grammar
163692498 grammar163692498 grammar
163692498 grammarcjsmann
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsRaghu nath
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsEran Zimbler
 
Brogramming - Python, Bash for Data Processing, and Git
Brogramming - Python, Bash for Data Processing, and GitBrogramming - Python, Bash for Data Processing, and Git
Brogramming - Python, Bash for Data Processing, and GitRon Reiter
 
3.2 javascript regex
3.2 javascript regex3.2 javascript regex
3.2 javascript regexJalpesh Vasa
 
Grep - A powerful search utility
Grep - A powerful search utilityGrep - A powerful search utility
Grep - A powerful search utilityNirajan Pant
 

Tendances (11)

Lexing and parsing
Lexing and parsingLexing and parsing
Lexing and parsing
 
Introduction to regular expressions
Introduction to regular expressionsIntroduction to regular expressions
Introduction to regular expressions
 
163692498 grammar
163692498 grammar163692498 grammar
163692498 grammar
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Brogramming - Python, Bash for Data Processing, and Git
Brogramming - Python, Bash for Data Processing, and GitBrogramming - Python, Bash for Data Processing, and Git
Brogramming - Python, Bash for Data Processing, and Git
 
3.2 javascript regex
3.2 javascript regex3.2 javascript regex
3.2 javascript regex
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Grep - A powerful search utility
Grep - A powerful search utilityGrep - A powerful search utility
Grep - A powerful search utility
 
Bioinformatics p2-p3-perl-regexes v2014
Bioinformatics p2-p3-perl-regexes v2014Bioinformatics p2-p3-perl-regexes v2014
Bioinformatics p2-p3-perl-regexes v2014
 

En vedette

Hamlet commentary to be or not to be
Hamlet commentary to be or not to beHamlet commentary to be or not to be
Hamlet commentary to be or not to be12903
 
Temptation scene in "paradise lost"
Temptation scene in "paradise lost"Temptation scene in "paradise lost"
Temptation scene in "paradise lost"trivedidisha
 
Temptation scene in paradise lost, p 1- nimesh
Temptation scene in paradise lost, p 1- nimeshTemptation scene in paradise lost, p 1- nimesh
Temptation scene in paradise lost, p 1- nimeshDave Nimesh B
 
To be or not to be - Hamlet- * Shakespeare 400*.
To be or not to be - Hamlet- * Shakespeare 400*.To be or not to be - Hamlet- * Shakespeare 400*.
To be or not to be - Hamlet- * Shakespeare 400*.Makala (D)
 
Annotations in PHP: They Exist
Annotations in PHP: They ExistAnnotations in PHP: They Exist
Annotations in PHP: They ExistRafael Dohms
 

En vedette (7)

To Be Or Not To Be
To Be Or Not To BeTo Be Or Not To Be
To Be Or Not To Be
 
Hamlet commentary to be or not to be
Hamlet commentary to be or not to beHamlet commentary to be or not to be
Hamlet commentary to be or not to be
 
Hamlet lecture slides
Hamlet lecture slidesHamlet lecture slides
Hamlet lecture slides
 
Temptation scene in "paradise lost"
Temptation scene in "paradise lost"Temptation scene in "paradise lost"
Temptation scene in "paradise lost"
 
Temptation scene in paradise lost, p 1- nimesh
Temptation scene in paradise lost, p 1- nimeshTemptation scene in paradise lost, p 1- nimesh
Temptation scene in paradise lost, p 1- nimesh
 
To be or not to be - Hamlet- * Shakespeare 400*.
To be or not to be - Hamlet- * Shakespeare 400*.To be or not to be - Hamlet- * Shakespeare 400*.
To be or not to be - Hamlet- * Shakespeare 400*.
 
Annotations in PHP: They Exist
Annotations in PHP: They ExistAnnotations in PHP: They Exist
Annotations in PHP: They Exist
 

Similaire à SDF vs Context-Free Grammars for Compiler Construction

Declarative Syntax Definition - Grammars and Trees
Declarative Syntax Definition - Grammars and TreesDeclarative Syntax Definition - Grammars and Trees
Declarative Syntax Definition - Grammars and TreesGuido Wachsmuth
 
Regexp secrets
Regexp secretsRegexp secrets
Regexp secretsHiro Asari
 
Advanced REXX Programming Techniques
Advanced REXX Programming TechniquesAdvanced REXX Programming Techniques
Advanced REXX Programming TechniquesDan O'Dea
 
Redesigning Common Lisp
Redesigning Common LispRedesigning Common Lisp
Redesigning Common Lispfukamachi
 
Programming_Language_Syntax.ppt
Programming_Language_Syntax.pptProgramming_Language_Syntax.ppt
Programming_Language_Syntax.pptAmrita Sharma
 
System Programming Unit IV
System Programming Unit IVSystem Programming Unit IV
System Programming Unit IVManoj Patil
 
Introduction of bison
Introduction of bisonIntroduction of bison
Introduction of bisonvip_du
 
Unicode Regular Expressions
Unicode Regular ExpressionsUnicode Regular Expressions
Unicode Regular ExpressionsNova Patch
 
Compiler Components and their Generators - Traditional Parsing Algorithms
Compiler Components and their Generators - Traditional Parsing AlgorithmsCompiler Components and their Generators - Traditional Parsing Algorithms
Compiler Components and their Generators - Traditional Parsing AlgorithmsGuido Wachsmuth
 
Declarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term RewritingDeclarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term RewritingGuido Wachsmuth
 
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/ibrettflorio
 
Ruby -the wheel Technology
Ruby -the wheel TechnologyRuby -the wheel Technology
Ruby -the wheel Technologyppparthpatel123
 
5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx
5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx
5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptxvenkatapranaykumarGa
 
Haskell retrospective
Haskell retrospectiveHaskell retrospective
Haskell retrospectivechenge2k
 

Similaire à SDF vs Context-Free Grammars for Compiler Construction (20)

Formal Grammars
Formal GrammarsFormal Grammars
Formal Grammars
 
Declarative Syntax Definition - Grammars and Trees
Declarative Syntax Definition - Grammars and TreesDeclarative Syntax Definition - Grammars and Trees
Declarative Syntax Definition - Grammars and Trees
 
Regexp secrets
Regexp secretsRegexp secrets
Regexp secrets
 
Lambda hardcore
Lambda hardcoreLambda hardcore
Lambda hardcore
 
Advanced REXX Programming Techniques
Advanced REXX Programming TechniquesAdvanced REXX Programming Techniques
Advanced REXX Programming Techniques
 
Redesigning Common Lisp
Redesigning Common LispRedesigning Common Lisp
Redesigning Common Lisp
 
Ch2 (1).ppt
Ch2 (1).pptCh2 (1).ppt
Ch2 (1).ppt
 
Programming_Language_Syntax.ppt
Programming_Language_Syntax.pptProgramming_Language_Syntax.ppt
Programming_Language_Syntax.ppt
 
System Programming Unit IV
System Programming Unit IVSystem Programming Unit IV
System Programming Unit IV
 
Syntax Definition
Syntax DefinitionSyntax Definition
Syntax Definition
 
Introduction of bison
Introduction of bisonIntroduction of bison
Introduction of bison
 
Unicode Regular Expressions
Unicode Regular ExpressionsUnicode Regular Expressions
Unicode Regular Expressions
 
Compiler Components and their Generators - Traditional Parsing Algorithms
Compiler Components and their Generators - Traditional Parsing AlgorithmsCompiler Components and their Generators - Traditional Parsing Algorithms
Compiler Components and their Generators - Traditional Parsing Algorithms
 
Declarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term RewritingDeclarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term Rewriting
 
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i
 
Ruby -the wheel Technology
Ruby -the wheel TechnologyRuby -the wheel Technology
Ruby -the wheel Technology
 
Control structure
Control structureControl structure
Control structure
 
Quick start reg ex
Quick start reg exQuick start reg ex
Quick start reg ex
 
5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx
5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx
5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx
 
Haskell retrospective
Haskell retrospectiveHaskell retrospective
Haskell retrospective
 

Plus de Guido Wachsmuth

Domain-Specific Type Systems
Domain-Specific Type SystemsDomain-Specific Type Systems
Domain-Specific Type SystemsGuido Wachsmuth
 
Compiler Components and their Generators - LR Parsing
Compiler Components and their Generators - LR ParsingCompiler Components and their Generators - LR Parsing
Compiler Components and their Generators - LR ParsingGuido Wachsmuth
 
Compiling Imperative and Object-Oriented Languages - Garbage Collection
Compiling Imperative and Object-Oriented Languages - Garbage CollectionCompiling Imperative and Object-Oriented Languages - Garbage Collection
Compiling Imperative and Object-Oriented Languages - Garbage CollectionGuido Wachsmuth
 
Compiler Components and their Generators - Lexical Analysis
Compiler Components and their Generators - Lexical AnalysisCompiler Components and their Generators - Lexical Analysis
Compiler Components and their Generators - Lexical AnalysisGuido Wachsmuth
 
Compiling Imperative and Object-Oriented Languages - Register Allocation
Compiling Imperative and Object-Oriented Languages - Register AllocationCompiling Imperative and Object-Oriented Languages - Register Allocation
Compiling Imperative and Object-Oriented Languages - Register AllocationGuido Wachsmuth
 
Compiling Imperative and Object-Oriented Languages - Dataflow Analysis
Compiling Imperative and Object-Oriented Languages - Dataflow AnalysisCompiling Imperative and Object-Oriented Languages - Dataflow Analysis
Compiling Imperative and Object-Oriented Languages - Dataflow AnalysisGuido Wachsmuth
 
Introduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented LanguagesIntroduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented LanguagesGuido Wachsmuth
 
Compiling Imperative and Object-Oriented Languages - Activation Records
Compiling Imperative and Object-Oriented Languages - Activation RecordsCompiling Imperative and Object-Oriented Languages - Activation Records
Compiling Imperative and Object-Oriented Languages - Activation RecordsGuido Wachsmuth
 
Declarative Semantics Definition - Code Generation
Declarative Semantics Definition - Code Generation Declarative Semantics Definition - Code Generation
Declarative Semantics Definition - Code Generation Guido Wachsmuth
 
Declarative Semantics Definition - Static Analysis and Error Checking
Declarative Semantics Definition - Static Analysis and Error CheckingDeclarative Semantics Definition - Static Analysis and Error Checking
Declarative Semantics Definition - Static Analysis and Error CheckingGuido Wachsmuth
 

Plus de Guido Wachsmuth (12)

Language
LanguageLanguage
Language
 
Domain-Specific Type Systems
Domain-Specific Type SystemsDomain-Specific Type Systems
Domain-Specific Type Systems
 
Compiler Components and their Generators - LR Parsing
Compiler Components and their Generators - LR ParsingCompiler Components and their Generators - LR Parsing
Compiler Components and their Generators - LR Parsing
 
Compiling Imperative and Object-Oriented Languages - Garbage Collection
Compiling Imperative and Object-Oriented Languages - Garbage CollectionCompiling Imperative and Object-Oriented Languages - Garbage Collection
Compiling Imperative and Object-Oriented Languages - Garbage Collection
 
Compiler Components and their Generators - Lexical Analysis
Compiler Components and their Generators - Lexical AnalysisCompiler Components and their Generators - Lexical Analysis
Compiler Components and their Generators - Lexical Analysis
 
Compiling Imperative and Object-Oriented Languages - Register Allocation
Compiling Imperative and Object-Oriented Languages - Register AllocationCompiling Imperative and Object-Oriented Languages - Register Allocation
Compiling Imperative and Object-Oriented Languages - Register Allocation
 
Compiling Imperative and Object-Oriented Languages - Dataflow Analysis
Compiling Imperative and Object-Oriented Languages - Dataflow AnalysisCompiling Imperative and Object-Oriented Languages - Dataflow Analysis
Compiling Imperative and Object-Oriented Languages - Dataflow Analysis
 
Introduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented LanguagesIntroduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented Languages
 
Compiling Imperative and Object-Oriented Languages - Activation Records
Compiling Imperative and Object-Oriented Languages - Activation RecordsCompiling Imperative and Object-Oriented Languages - Activation Records
Compiling Imperative and Object-Oriented Languages - Activation Records
 
Declarative Semantics Definition - Code Generation
Declarative Semantics Definition - Code Generation Declarative Semantics Definition - Code Generation
Declarative Semantics Definition - Code Generation
 
Declarative Semantics Definition - Static Analysis and Error Checking
Declarative Semantics Definition - Static Analysis and Error CheckingDeclarative Semantics Definition - Static Analysis and Error Checking
Declarative Semantics Definition - Static Analysis and Error Checking
 
Software Languages
Software LanguagesSoftware Languages
Software Languages
 

Dernier

Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxleah joy valeriano
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 

Dernier (20)

Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 

SDF vs Context-Free Grammars for Compiler Construction

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. My name is Guido Wachsmuth, \n
  15. and I will tell you a sad story.\n
  16. A story about the paradise of pure and declarative syntax definition,\n
  17. about how this paradise once was lost,\n
  18. and about how it was regained later,\n
  19. but also about how this paradise is denied until these days. \n
  20. In the beginning\n
  21. were the words, and the words\n
  22. were trees, and the trees were words. \n
  23. All words were made through grammars, and without grammars was not any word made that was made. \n
  24. Those were the days of the garden of Eden. \nAnd there where language engineers strolling through the garden. \n
  25. They made languages which were sets of words by making grammars full of beauty. \n
  26. And with these grammars, they turned words into trees and trees into words. \n
  27. And the trees were natural, \n
  28. and pure, \n
  29. and beautiful, as were the grammars.\n
  30. Among them were software engineers who made software as the language engineers made languages. And they dwelt with them and they were one people. The language engineers were software engineers and the software engineers were language engineers. \n
  31. And the language engineers made language software. They made recognisers to know words, and generators to make words, and parsers to turn words into trees, and formatters to turn trees into words.\n
  32. But the software they made was not as natural, \n
  33. and pure, \n
  34. and beautiful as the grammars they made. \n
  35. So they made software to make language software and began to make language software by making syntax definitions. And the syntax definitions were grammars and grammars were syntax definitions. With their software, they turned syntax definitions into language software. And the syntax definitions were language software and language software were syntax definitions.\n
  36. And the syntax definitions were natural, \n
  37. and pure, \n
  38. and beautiful, as were the grammars.\n
  39. Now the serpent was more crafty than any other beast of the field. He said to the language engineers\n\nDid you actually decide not to build any parsers?\n\nAnd the language engineers said to the serpent,\n\nWe build parsers, but we decided not to build others than general parsers, nor shall we try it, lest we lose our syntax definitions to be natural, and pure, and beautiful.\n\nBut the serpent said to the language engineers,\n\nYou will not surely lose your syntax definitions to be natural, and pure, and beautiful. For you know that when you build particular parsers your benchmarks will be improved, and your parsers will be the best, running fast and efficient.\n
  40. So when the language engineers saw that restricted parsers were good for efficiency, and that they were a delight to the benchmarks, they made software to make efficient parsers and began to make efficient parsers by making parser definitions.\n
  41. Those days, the language engineers went out from the garden of Eden. \n
  42. In pain they made parser definitions all the days of their life. But the parser definitions were not grammars and grammars were not parser definitions.\n
  43. And by the sweat of their faces they turned parser definitions into efficient parsers. \n
  44. But the parser definitions were not natural, \n
  45. nor pure, \n
  46. nor beautiful, as the grammars had been before.\n
  47. Their software was full of plagues. \n
  48. The first plague were grammar classes. Only few grammars could be turned directly into parser definitions. And language engineers massaged their grammars all the days of their life to make them fit into a grammar class. And the parser definitions became unnatural, and impure, and ugly. And there was weeping and mourning.\n
  49. The second plague was disambiguation. Their new parsers were deterministic. So the language engineers encoded precedence in parser definitions. And the parser definitions became unnatural, and impure, and ugly.\n\n
  50. The third plague was lexical syntax. The new software could not handle lexical syntax definitions. So the language engineers made another software to turn lexical syntax definitions into scanners. But lexical syntax definitions were less expressive than the grammars they used before. And they were separated from parser definitions, as were scan- ners from parsers. And there was weeping and wailing.\n\n
  51. The fourth plague was tree construction. The language engineers wanted the efficient parsers to turn words into trees, as their old parsers did. So they added code to their parser definitions. And the parser definitions became unnatural, and impure, and ugly. And those who were oblivious to the working of the efficient parsers made parsers that turn the right words into the wrong trees.\n\n
  52. The fifth and sixth plague were evolution\n
  53. and composition. Once the language engineers added a new rule to their parser definitions, those tended to break. And they massaged them by the sweat of their faces to make them fit again into the grammar class. And they were not able to compose two parser definitions to a single parser definition because of grammar classes and separate scanners. And there was weeping and groaning.\n
  54. The seventh plague was the restriction to parsers. The language engineers turned parser definitions into recognizers and into parsers. But they could not turn them into generators or formatters. That was because parser definitions were not grammars.\n
  55. Many have undertaken to compile a narrative of the things that have been accomplished among us. It seemed good to us also, having followed all things closely for some time past, to tell an orderly account for you that you may have certainty concerning the things you have been taught.\n
  56. It all starts with the beauty of grammars and trees\n
  57. and it all starts with Noam Chomsky.\n\nLike other linguists, he was thinking about the infinite productivity of language.\nWe can produce sentences that no-one produced before.\n\n
  58. But how can we put this productivity into finite models?\nChomsky&amp;#x2019;s came up with grammars as generative devices.\nFinite models, declaring how words are made from letters and sentences are made from words.\n\n
  59. This is a grammar for generating binary numbers.\n
  60. It consists of 4 production rules\n
  61. At the RHS of these rules we see terminal symbols.\nThese are the symbols binary numbers are made of.\n
  62. At the LHS of each rule we see a nonterminal symbol.\nNonterminal symbols are variables in the generation.\nThey can also occur on the right-hand side of a production rule.\nWe say: The LHS symbol produces the symbols on the RHS.\n
  63. The start symbol is a particular nonterminal symbol.\n
  64. When we generate words through grammars,\n
  65. we start with this start symbol.\n
  66. and apply production rules by replacing nonterminal symbols.\nWe replace a nonterminal symbol from the LHS of a rule with the symbols of the RHS.\n
  67. We do this as long as there are nonterminal symbols for which we can find production rules.\nWe are free to choose any nonterminal symbol and apply any rule.\nSo let&amp;#x2019;s take another rule for NUM this time.\n
  68. Now we can replace one of the both symbols for digits.\nLet&amp;#x2019;s apply the first rule.\n
  69. There is still one nonterminal symbol left.\nLet&amp;#x2019;s take the other rule for digits this time.\nWe are done. \nWe generated the word 10.\n
  70. But with grammars we can not only generate words but also sentences.\n
  71. Here is a grammar for generating expressions.\nAgain we have production rules\n
  72. with terminal symbols occuring on the RHS of these rules.\nHere, we have two different kinds of terminal symbols:\n+ and * each representing a particular morphem,\nand NUM, representing a whole class of morphems, let&amp;#x2019;s assume in this case decimal numbers.\n
  73. We have only a single nonterminal symbol\n
  74. which is also the start symbol.\n
  75. We can now generate an expression.\n
  76. We replace the start symbol by applying the first rule for EXP.\n
  77. Now let&amp;#x2019;s replace the first EXP and let&amp;#x2019;s use the second rule this time.\n
  78. Let&amp;#x2019;s take again the first EXP and replace it by a morphem from the morphem class NUM.\n
  79. When we do this two more times\n
  80. we have generated an expression.\n
  81. We can use grammars to describe languages by making a grammar that generates all the words of a given language.\n
  82. For example, we can come up with a grammar for Latin.\n
  83. Which should generate all these Latin sentences.\nAnd all other correct Latin sentences.\n
  84. But a grammar can also define a language. \nIt defines the language of sentences that it generates.\nAnd we can make new languages my making grammars.\nAnd we can ask the grammar if a sentence is in the language or not.\nThe grammar is the only truth.\n
  85. For this, we read the production rules of a grammar as reduction rules.\nThe symbols of the RHS can be reduced to the nonterminal symbol of the LHS.\nTo emphasise this reading, we can write the rules in a reductive way, switching LHS and RHS.\n
  86. Now let&amp;#x2019;s see if this is a valid expression according to our grammar we&amp;#x2019;ve seen before.\n
  87. We apply reduction rules where ever we can, finding the LHS of a rule and replacing it with the nonterminal symbol from the RHS.\nHere we can reduce 21 to EXP.\n
  88. The same for 7\n
  89. and 3.\n
  90. Now we can replace EXP*EXP by EXP\n
  91. and finally EXP+EXP by EXP.\nIt remains the start symbol of our grammar, telling us the truth:\n3*7+21 is a valid expression.\n
  92. We can use grammars also to turn words into trees.\n
  93. We do so because we are not only interested if a sentence is an element of a language,\n
  94. but also its structure. \nAs we know from primary school, \nthis structure can typically be represented as trees.\n
  95. we saw already two readings of grammars\n
  96. now, here we have a third one: rules as tree construction rules. \nnonterminal symbol as the root, symbols constituting the root as leaves\n
  97. \n
  98. \n
  99. \n
  100. \n
  101. \n
  102. \n
  103. \n
  104. \n
  105. \n
  106. \n
  107. \n
  108. \n
  109. \n
  110. \n
  111. \n
  112. \n
  113. \n
  114. \n
  115. \n
  116. \n
  117. non-intuitive classification\nnon-intuitive error messages\ncomplex parsing algorithms\n
  118. \n
  119. \n
  120. \n
  121. declarative disambiguation\n
  122. \n
  123. \n
  124. \n
  125. \n
  126. \n
  127. \n
  128. \n
  129. \n
  130. \n
  131. \n
  132. \n
  133. \n
  134. \n
  135. \n
  136. \n
  137. \n
  138. \n
  139. \n
  140. \n
  141. \n
  142. \n
  143. \n
  144. interleaved with evaluation of the parser\n
  145. \n
  146. \n
  147. \n
  148. \n
  149. \n
  150. not closed under composition\n
  151. not closed under composition\n
  152. not closed under composition\n
  153. \n
  154. overlapping morphem classes\nglobally reserved words\n
  155. \n
  156. \n
  157. \n
  158. \n
  159. \n
  160. \n
  161. \n
  162. \n
  163. \n
  164. \n
  165. \n
  166. \n
  167. \n
  168. \n
  169. \n
  170. \n
  171. \n
  172. \n
  173. \n
  174. \n
  175. \n
  176. \n
  177. \n
  178. \n
  179. \n
  180. \n
  181. \n
  182. \n
  183. \n
  184. \n
  185. \n
  186. \n
  187. what did before the scanner, now does the parser\n
  188. \n
  189. \n
  190. \n
  191. \n
  192. \n
  193. \n
  194. \n
  195. \n
  196. closed under composition\n
  197. closed under composition\n
  198. closed under composition\n
  199. closed under composition\n
  200. closed under composition\n
  201. closed under composition\n
  202. closed under composition\n
  203. closed under composition\n
  204. \n
  205. \n
  206. \n
  207. \n
  208. \n
  209. \n
  210. \n
  211. \n
  212. \n
  213. \n
  214. \n
  215. \n
  216. \n
  217. \n
  218. \n
  219. Fear not! Stand firm! See the naturalness, and the pureness, and the beauty of declarative syntax definitions, which will work for you. \nFor the parser definitions that you see today, you shall never see again.\n
  220. Go out to the promised land! \nMake new software to make parsers and begin to make parsers by making syntax definitions again. \nLet the syntax definitions be grammars again and grammars be syntax definitions again. \nAnd the syntax definitions will be natural, and pure, and beautiful again, as will the grammars.\n
  221. \n
  222. \n
  223. \n
  224. \n
  225. \n
  226. \n
  227. \n
  228. \n
  229. \n
  230. \n
  231. \n
  232. \n
  233. \n
  234. \n
  235. \n
  236. \n
  237. \n
  238. \n
  239. \n
  240. \n
  241. \n
  242. \n
  243. \n
  244. \n
  245. WebDSL &amp; mobl: Flash to HTML5, query optimisation, data synchronisation, partitioning, e-learning platform\nSpoofax: debugging, integration, testing, visualisation, incremental compilation, DSLs for robotics\n
  246. \n
  247. round-up on every lecture\n\nwhat to take with you\n\ncheck yourself, pre- and post-paration\n
  248. \n
  249. \n