3.0 Introduction

3.1 Metalanguage

3.2 The Driver

3.3 The Generator

3.4 Error Handling

3.5 Generating vs. Writing

3.6 LEX, A Lexical Analyzer Generator

3.7 Summary

Web References

Exercises

3.1 Metalanguage

The metalanguage for a scanner generator is a set of regular expressions describing the tokens in the language. A program stub or finite state table is generated from the regular expressions. At compile-time, the driver reads input characters from the source program, consults the table based upon the input and the current state, and moves to a new state based upon the entry, perhaps prforming an action such as entering an identifier into a name table.

We will illustrate these concepts with a sample language consisting of assignment statements whose right-hand sides are arithmetic expressions.

Example 1

These regular expressions are input to the generator to produce state tables either in table form or as a case statement program stub.

Example 2

In Section 3.2 and in Section 3.3, we discuss the two programs, the driver program and the lexical analyzer generator.

Send questions and comments to: Karen Lemone