![]() |
![]() |
|
home—info—lectures—exams—hws—archive
- grammar: + terminology: "nonterminal", "production", etc. + Recall: From book, p.124 (Example 3.3): A grammar for arithmetic expressions: AExpr ::= AExpr + AExpr | AExpr * AExpr | (AExpr) | number | variable (We also saw derivations, and parse trees.) As we saw, this was ambiguous. + Here is another grammar for Expr, but this is not ambiguous: (book example 3.4 p.126) Expr ::= Expr + Term | Term Term ::= Term * Factor ::= Factor Factor ::= (Expr) | number | variable Make a parse tree for each of 3 + 4 * 5 3 * 4 + 5 Not only is this non-ambiguous, but it has hacked the precedence rules (semantics) into the syntax-layer. There are algorithms to tell if simple (context-free) grammars are non-ambiguous; however, note that in general, context-sensitive grammars (where the left-hand-side of a production contains multiple symbols) is is NOT COMPUTABLE whether the grammar is ambiguous. + What about a grammar for scheme's arithmetic -- it's very similar to AExpr. Is that ambiguous? Why not -- what's the difference? + A grammar for XML - programs that handle grammars Develop XML code (and show) examples of an internalized form add a method: toString. We'll make the string "happen" to look just like the raw input would. add a method: realLength (the number of *non-markup* characters) add another class: XEntity ==== For next week: - writing XML.parse - map, filter, fold as applied to fire-planes [map-reduce; fold in Perl]
home—info—lectures—exams—hws—archive
©2009, Ian Barland, Radford University Last modified 2009.Mar.30 (Mon) |
Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |
![]() |