• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Petitparser at the Deep into Smalltalk School 2011
 

Petitparser at the Deep into Smalltalk School 2011

on

  • 4,760 views

I used this set of slides for a tutorial I gave at the Deep into Smalltalk School 2011 held at INRIA, Lille on March 10, 2011.

I used this set of slides for a tutorial I gave at the Deep into Smalltalk School 2011 held at INRIA, Lille on March 10, 2011.

Statistics

Views

Total Views
4,760
Views on SlideShare
1,842
Embed Views
2,918

Actions

Likes
0
Downloads
39
Comments
0

8 Embeds 2,918

http://scg.unibe.ch 2258
http://www.humane-assessment.com 270
http://www.humane-assessment.com 270
http://www.tudorgirba.com 115
https://si0.twimg.com 2
http://static.slidesharecdn.com 1
http://feeds.feedburner.com 1
http://humane-assessment.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Petitparser at the Deep into Smalltalk School 2011 Petitparser at the Deep into Smalltalk School 2011 Presentation Transcript

    • with Lukas Renggliwww.tudorgirba.combased on the work of Lukas Renggliwww.lukas-renggli.ch
    • with Lukas Rengglibuilt by Lukas Rengglideeply integrated with Smalltalkpart of the Moose Suite
    • input parse output
    • Mastering Grammars with parse Lukas Renggli
    • Root := Document ?Document := OPEN ElementNode * CLOSEElementNode := OPEN ELEMENTNAME AttributeNode * CLOSEAttributeNode := OPEN SIMPLENAME ValueNode * CLOSEValueNode := Primitive | ElementNodePrimitive := STRING | NUMBEROPEN := "("CLOSE := ")"ELEMENTNAME := letter ( letter | digit ) * ( "." letter ( letter | digit ) ) *SIMPLENAME := letter ( letter | digit ) *NUMBER := "-" ? digit + ( "." digit + ) ? ( ( "e" | "E" ) ( "-" | "+" ) ? digit + ) ?STRING := ( "" [^] * "" ) +digit := [0-9]letter := [a-zA-Z_]comment := """ [^"] * """target
    • IDENTIFIER ::= letter ( letter | digit ) * a..z a..z 0..9
    • identifier := #letter asParser , ( #letter asParser / #digit asParser ) star. a..z a..z 0..9
    • exercise
    • identifier := #letter asParser , ( #letter asParser / #digit asParser ) star. a..z a..z 0..9
    • identifier := #letter asParser , ( #letter asParser / #digit asParser ) star. sequence letter many choice letter digit
    • identifier := #letter asParser , ( #letter asParser / #digit asParser ) star. sequence letter manyparsers are objects choice letter digit
    • terminals$c asParser parse character “c”‘string’ asParser parse string “string”#any asParser parse any character#digit asParser parse one digit#letter asParser parse one letter
    • terminals are defined in PPPredicateObjectParserexercise:!browse!PPPredicateObjectParser
    • combinatorsp1 , p2 parse p1 followed by p2 (sequence)p1 / p2 parse p1, otherwise parse p2 (ordered choice)p star parse zero or more pp plus parse one or more pp optional parse p if possiblepredicatesp not negation (non-consuming look-ahead)p negate negation (consuming)p end end of input
    • PPParser is the root of all parsersall operations are defined in this class
    • exercise:!browse!PPParser!operations
    • exercise
    • actionsp ==> aBlock Transforms the result of p through aBlock.p flatten Creates a string from the result of p.p token Creates a token from the result of p.p trim Trims whitespaces before and after p.
    • string := $ asParser , $ asParser negate star , $ asParser.
    • string := $ asParser , $ asParser negate star flatten , $ asParser ==> [:token | token second ].
    • stringText := $ asParser negate star flatten.string := $ asParser , stringText , $ asParser ==> [:token | token second ].
    • exercise
    • Root := Document ?Document := OPEN ElementNode * CLOSE exerciseElementNode := OPEN ELEMENTNAME AttributeNode * CLOSEAttributeNode := OPEN SIMPLENAME ValueNode * CLOSEValueNode := Primitive | ElementNodePrimitive := STRING | NUMBEROPEN := "("CLOSE := ")"ELEMENTNAME := letter ( letter | digit ) * ( "." letter ( letter | digit ) *)SIMPLENAME := letter ( letter | digit ) *NUMBER := "-" ? digit + ( "." digit + ) ? ( ( "e" | "E" ) ( "-" | "+" ) ? digit + ) ?STRING := ( "" [^] * "" ) +digit := [0-9]letter := [a-zA-Z_]comment := """ [^"] * """( (FAMIX.Package (name PackageP)) (FAMIX.Class (name ClassA)) (FAMIX.Method (name methodM)))
    • stringText := $ asParser negate star flatten.string := $ asParser , stringText , $ asParser ==> [:token | token second ].
    • stringText := PPUnresolvedParser new.string := $ asParser , stringText , $ asParser ==> [:token | token second ].stringText def: ($ asParser negate star flatten).
    • Root := Document ?Document := OPEN ElementNode * CLOSE exerciseElementNode := OPEN ELEMENTNAME Serial ? AttributeNode * CLOSESerial := OPEN ID INTEGER CLOSEAttributeNode := OPEN SIMPLENAME ValueNode * CLOSEValueNode := Primitive | Reference | ElementNodePrimitive := STRING | NUMBER | Boolean | UnlimitedBoolean := TRUE | FALSEUnlimited := NILReference := IntegerReference | NameReferenceIntegerReference := OPEN REF INTEGER CLOSENameReference := OPEN REF ELEMENTNAME CLOSEOPEN := "("CLOSE := ")"ID := "id:"REF := "ref:"TRUE := "true"FALSE := "false"ELEMENTNAME := letter ( letter | digit ) * ( "." letter ( letter | digit ) ) *SIMPLENAME := letter ( letter | digit ) *INTEGER := digit +NUMBER := "-" ? digit + ( "." digit + ) ? ( ( "e" | "E" ) ( "-" | "+" ) ? digit + ) ?STRING := ( "" [^] * "" ) +digit := [0-9]letter := [a-zA-Z_]comment := """ [^"] * """
    • exercise( (FAMIX.Package (id: 1) (name PackageP)) (FAMIX.Class (id: 2) (name ClassA) (parentPackage (ref: 1))) (FAMIX.Method (id: 3) (name methodA) (declaredType (ref: 1)) (parentType (ref: 2))))
    • scripting = ! nice for prototyping ! but messy
    • subclass PPCompositeParserstart = default start parser
    • externally, parsers map on methodsinternally, parsers map on instance variables
    • to specify actions, subclass the base grammar
    • subclass tests from PPCompositeParserTestspecify the parserClass
    • use #parse:rule: to check the grammar
    • subclass to check the parser result
    • PetitParser comes with a dedicated user interfacePPBrowser open.
    • with Lukas Rengglibuilt by Lukas Rengglideeply integrated with Smalltalkpart of the Moose Suite
    • Tudor Gîrba www.tudorgirba.comcreativecommons.org/licenses/by/3.0/