Download presentation
Presentation is loading. Please wait.
Published byRegina Lyons Modified over 9 years ago
1
Parsing XML Grammars, PDAs, Lexical Analysis, Recursive Descent
2
Recipe Book Markup Language Why Markup languages? – Give structure of contents – aid in interpreting semantics of content, storing in database, etc. Why XML? – Human readable (sort of) – Widely accepted and used for data interchange Why RBML? – Don’t reinvent the wheel – use existing stuff IAAP – Simplest of the recipe XML formats I found
3
Formal Languages What is a Formal Language? – Mathematically defined subset of strings over a finite alphabet Regular Languages – Very simple, can be recognized by FSM – Still very powerful Context-Free Languages – Pretty simple, can be recognized by PDA – Esp. useful for programming language
4
Regular Expressions/Languages Alphabet, Σ = finite set of symbols String, σ = sequence of 0 or more symbols in Σ* Regular Expressions – The empty set, Ø – The empty string, ε is an RE and denotes {ε} – For all a in Σ, a is an RE and denotes {a} – If r and s are REs, denoting the languages R and S, resp., then (r+s), (rs), and (r*) are REs that denote R U S, RS, and R*, resp.
5
Context-Free Languages Context-Free Grammar G= – V = variables – T = terminals (alphabet characters) – P = Productions – S = start symbol in V Productions – Replace a variable with a string from (V U T)* – Example: E -> E + E | E * E | (E) | id
6
RBML Grammar cookbook -> “ ” title (section | recipe)+ “ ” title -> “ ” pcdata “ ” section -> “ ” title recipe+ “ ” recipe -> “ ” title recipeinfo ingredientlist preparation serving notes “ ”
7
RBML Grammar recipeinfo -> (author | blurb | effort | genre | preptime | source | yield)* ingredientlist -> ingredient)* preparation -> (pcdata | equipment | step | hyperlink)* serving -> (pcdata | hyperlink)* notes -> (pcdata | hyperlink)*
8
RBML Grammar equipment -> (pcdata | hyperlink)* step -> (pcdata | equipment | hyperlink)* ingredient -> (pcdata | quantity | unit | fooditem)* quantity -> number | number "or" number | number "and" number number -> integer | fraction | integer " " fraction fraction -> integer "/" integer
9
Recipe Book Markup Language unit -> pcdata fooditem -> pcdata blurb -> pcdata effort -> pcdata genre -> pcdata
10
Recipe Book Markup Language preptime -> pcdata source -> (pcdata | hyperlink)* yield -> pcdata hyperlink -> pcdata url
11
Recursive Descent Parsing Match required (literal) symbols Call procedure to match variable – May itself call similar procedures
12
Lexical Analysis Helps prepare for parsing Uses regular language expressions to – Organize input into multi-symbol chunks – Each chunk has a meaning for parser
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.