Converting Legacy Data to XML using a Lexer and Parser Generator

10/6/2002


Click here to start


Table of Contents

Converting Legacy Data to XML using a Lexer and Parser Generator

The Lexer and Parser Generator we will use: JFlex and CUP

JFlex

Regular Expressions

Regular Expression Syntax*

Regular Expression Syntax

Building a JFlex Lexical Analyzer

3 Parts of a JFlex Specification

Problem

Start Simple

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

Running the examples

Macros

PPT Slide

Inserting our own code into the lexer

PPT Slide

line count and column count

PPT Slide

Distinguishing the Title token

Total number of chars

PPT Slide

Using a Macro Definition within another Macro

Start to generate XML

PPT Slide

Wrap book data

PPT Slide

Add a root element

PPT Slide

Add xml declaration

PPT Slide

Customizing the tags

YYINITIAL

Legend for Showing State Transitions

States and the transitions

yypushback(int)

Outputting the xml declaration and <BookCatalogue> in YYINITIAL

Declaring states, transitioning states

PPT Slide

How much knowledge of the semantics of the data do we put in the scanner?

Handling Errors

Sample Errors

PPT Slide

Golden Rule of Regex Matching

Golden Rule of Regex Matching

Common Tactic - a catch-all regex

Lookahead

PPT Slide

Syntax of Regex with Lookahead

Distinguish these two

Cannot use lookahead in a macro

Convert Books and Magazines

How will we recognize a Title as a Book Title or a Magazine Title?

PPT Slide

Adding a Parser on top of the lexer

First parser example

PPT Slide

Parser defines a "grammar"

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

Steps to Build a Parser

Debugging a Parser

Debugging Example15

Next example

PPT Slide

PPT Slide

Add xml declaration and root element

PPT Slide

PPT Slide

More descriptive tokens

PPT Slide

Parser uses descriptive tokens

PPT Slide

More semantics in lexer enabled more descriptive parser

Allow for empty elements

PPT Slide

Adding Methods that may be Invoked

Validate Input as the XML is Generated

Author: Roger L. Costello