RU beehive logo ITEC dept promo banner
ITEC 380
2008fall
ibarland

homeinfolecturesexamsarchive

lect07a
BNF; recursive descent parsing

We saw last time, BNF for specifying grammars; derivations in a grammar; the parse-tree associated with a derivation; grammars can be ambiguous; you can encode precedence-of-operations via grammar productions.

What is a BNF for XML? Let's use very basic XML -- no attributes, no entities, and no initial format/namespace tags.

As noted, the BNF for XML is the data definition. What would any code processing XML look like?

Okay, now let's look at parsing: given a flat string of chars, turn it into an instance of our data def'n. (In other words: create a parse tree.)

For each nonterminal X, we'll have a method readX : String → myXstruct. (Actually, in Java, we'll use a Scanner instead of a String.)

This is called recursive descent parsing (§4.4).

Note that XML is a particularly simple language: not only is it non-ambiguous, but we can peek at just the first few characters of the string to tell whether we are reading a string, an open-tag, or a close-tag. (As opposed to an AExpr, where "23456 + 11" you need to look quite a few characters ahead to tell if this is a 'high-priority-term' or 'low-priority-term'.)

homeinfolecturesexamsarchive


©2008, Ian Barland, Radford University
Last modified 2008.Oct.13 (Mon)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme