• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content

Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

Text_Processing_With.. - The Iterator Blues

on

  • 1,279 views

 

Statistics

Views

Total Views
1,279
Views on SlideShare
1,279
Embed Views
0

Actions

Likes
0
Downloads
3
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

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
  • No, you can't. Yes, I can! Irving Berlin, Annie Get Your Gun.
  • Remember program flow diagrams? Input -> Magic Happens -> Output. Input and Output are often text (text/config files, html/xml, scripts, log files, etc.) Std support for text manipulation poor. Boost fills gaps in Std and adds more powerful utilities.
  • atoi: If the input cannot be converted to a value of that type, the return value is 0. The return value is undefined in case of overflow.
  • Actually, anything can be converted to anything this way as long as both types are streamable
  • *_copy() variants create copies i* variants are case-insensitive (uses global locale)
  • So fundamental, it's a bit embarrassing to even talk about it!
  • In grammar, an imperative sentence gives an instruction. First, do this, then do that. A declarative sentence makes a simple statement – an observation about the way things are. (Interrogative sentence? Exclamatory sentence?)
  • “ Imperative programs make the algorithm explicit and leave the goal implicit, while declarative programs make the goal explicit and leave the algorithm implicit.” – Wikipedia, declarative programming. (Interrogative Programming? Exclamatory Programming? a = b!!!  ) Question: What is an example of a language that supports declarative programming? Answer: Prolog. HTML/XML. SQL. Question: C++ supports which programming paradigm? Answer #1: Imperative. C,C++,Java,C# are all imperative programming languages. Answer #2: Both! C++ is a multi-paradigm language; it has the power to support declarative programming through powerful libraries.
  • Style is imperative . First do this, then do that. Describes algorithm, goal is implicit. Code is brittle and hard to maintain.
  • Code is simpler. Clearly states programmer intention. Describes goal (find an email subject), not algorithm. Forest/trees.
  • Answer: Imperative languages are more general purpose . Since you cannot specify the algorithm with declarative programming, it’s best suited to situations where the algorithm can only take a limited set of forms. That’s typically true for narrow domains; e.g. finite automata for pattern matching, recursive descent for parsing, etc. Conclusion: declarative programming is ideal for domain-specific languages , imperative is better for general-purpose programming languages.
  • domain-specific for high-level, declarative solutions in specific domains general purpose for everything else can host multiple DSLs within the same general-purpose language!
  • Q: Why “\d” instead of “d”? A: The first escape is consumed by the C++ compiler. The second by the regex parser. {n} is a special postfix quantifier that means to match the previous thing exactly n times.
  • Will only succeed when the pattern matches the whole input!
  • Regex_constants::icase makes this a case-insensitive pattern. “ .*?” means match any character zero or more times, preferring the shorter matches.
  • Incrementing a regex_iterator moves to the next match Dereferencing a regex_iterator returns a reference to a match_results
  • Last parameter tells how to extract tokens from a match. “1” means to extract capture #1. {0,1} would extract whole match followed by first capture. Incrementing a regex_token_iterator moves to the next token, either within the current match or from the next match. Dereferencing a regex_token_iterator returns a reference to a string.
  • The limits of regular expressions They can only find regular patterns (no recursive patterns) Little support for contextual matching Can’t build parsers out of them! Jamie Zawinski: XEmacs author, original author of Netscape Navigator
  • "Full access to types and data" : This becomes important later when we build parsers with semantic actions
  • Demonstrates use of expression templates to implement a static DSEL in C++ Note use of overloaded operators postfix becomes prefix, etc. rules are pre-declared. A grammar is made up of rules .
  • _p means "parser"
  • For operator overloading to kick in, at least one operand must be a user-defined type.
  • right-hand side can be arbitrarily complicated.
  • This parser works on the character level – it will not ignore spaces. So "1 + 3" will not match!
  • A phrase_scanner is really a skip parser.
  • A grammar IS-A parser, and can be used wherever a parser can.
  • Notice the expression is used in-place without first assigning to a rule<> Actions can be anything that can be invoked as Func(iter1, iter2)
  • The first closure-generated member can be used as a rule’s “return value”
  • arg1 is a placeholder like lambda::_1 It receives the return value of whatever parser to which this action is attached Since these actions are attached to rules with closures, arg1 gets the current value of the rule's closure.
  • As with a rule, the "return value" of a grammar with a closure is the closure context. var(n) is needed here to turn the double into a phoenix lambda expression.
  • A Boost.Regex work-alike. Interface closely follows that of TR1 regex (but not exactly)
  • Embed a dynamic regex in a static regex – fully interoperable. Unlike Spirit, xpressive regex object embed by value by default. There is a special by_ref() helper for embedding a regex by reference. Useful for creating recursive regexes.
  • Xpressive actually has semantic actions, but they're undocumented for 1.0. They'll become official in 2.0.
  • Caveat: not an official Boost library!

Text_Processing_With.. - The Iterator Blues Text_Processing_With.. - The Iterator Blues Presentation Transcript