Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Parser Output3-28-2011Opening DiscussionMinute essay comments:What does asInstanceOf[] do?Parser usage.Default Parser OutputStrings match themselves.RegEx and tokens give strings.P~Q gives back ~(p,q), where p and q are the matches of P and Q.P | Q gives either p or q.rep(P) or repsep(P,seperator) give a list of p values.opt(P) gives an Option, either Some(p) or None.Specifying OutputYou can override the default of P by using P ^^ f. The f is a function (or partial function) that takes the normal output of P.The output you get is f(p).Example uses:floatingPointNumber ^^ (_.toDouble)“true” ^^ (x=>true)“(“~ident~”,”~ident~”)” ^^ { case “(“~i1~”,”~i2~”)” => (i1,i2) }Ignoring Parts of the ParseIn something like the last example shown, there are strings that are part of the parse that really don't impact the result.When you have this type of situation you can use ~> or <~ instead of just ~. The aprse result will only include what the arrow points to.“(“~>ident~”,”~ident<~”)” ^^ { case i1~”,”~i2 => (i1,i2) }Our CodeLet's work on putting this type of functionality in our formula code.We had the parser, but we want to parse to a tree similar to what we produced with the recursive parser we wrote ourselves.With that we can make this alternate code functional.Minute EssayWhat questions do you have about parsers, regex, or grammars?Next class we do spatial trees.IcP #7 is next class.Spring classes and Web
View Full Document