DOC PREVIEW
TRINITY CSCI 1321 - RexEx and Parsing

This preview shows page 1-2-3 out of 10 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10RexEx and Parsing10-31-2011Opening DiscussionDo you have any questions about the quiz?Minute essay comments:RegEx with multiple parts. Doubles.Help with all types of parsing.Performance of RegEx.For Loops and RegExRemember that for-loops do pattern matches for storing values. They also skip anything that doesn't match the pattern.This makes them ideal when running through the results of findAllIn.Examples of RegExLet's run through some different examples of using regular expressions.Decimal numbersPoints in 2-D or 3-DDatesPolynomialsCF Grammars and Internal DSLsThere are times when you might want to include elements in your programs that go beyond regular grammars.An example of this would be an internal DSL (Domain Specific Language). This is like a little language that is understood in your program.Mathematical formulas count as these, but so would simple commands that have some structure to them.Example CF GrammarHere is a CF grammar for math expressions:expr ::= term { “+” term | “-” term }term ::= factor { “*” factor | “/” factor }factor ::= floatingPointNumber | “(“ expr “)”Use {} for 0 or more and [] for 0 or 1.Lots of languages here:http://www.antlr.org/grammar/listScala Parsersimport scala.util.parsing.combinator._class Arith extends JavaTokenParsers {def expr:Parser[Any] = term~rep(“+”~term | “-”~term)def term:Parser[Any] = factor~rep(“*”~factor | “/”~factor)def factor:Parser[Any] = floatingPointNumber | “(“~expr~”)”}Conversion RulesPut in a class that extends one of the Parsers.Productions become methods.Results are Parsers. Next class we'll see how to make it more specific than Any.Consecutive symbols are adjoined with ~.The {...} is replaced with rep(...).The […] is replaced with opt(...).Using the ParserCall parseAll or parse on your class.Takes two arguments:First argument is the parser to use.Second argument is the string to parse.Let's code this all up and see it in action.Minute EssayQuestions? Can you think of anyplace you might use


View Full Document

TRINITY CSCI 1321 - RexEx and Parsing

Documents in this Course
Recursion

Recursion

11 pages

Iterators

Iterators

10 pages

Actors

Actors

9 pages

Recursion

Recursion

15 pages

Recursion

Recursion

10 pages

Threads

Threads

7 pages

Trees

Trees

11 pages

Load more
Download RexEx and Parsing
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view RexEx and Parsing and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view RexEx and Parsing 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?