Interactive
Software Engineering
EiffelLex/EiffelParse

[ISE Home] Home ] Release Notes ] Technology Papers ] Installation Notes ] About Eiffel ]


Introduction

In this documentation we will explain you how to use EiffelLex and EiffelParse in you Projects:

EiffelLex provides a set of efficient object-oriented mechanisms for lexical analysis, based on several kinds of finite automata, deterministic and non-deterministic.

EiffelParse provides a set of object-oriented mechanisms for parsing, based on simple principles allowing a direct mapping from a BNF-like syntax specification to Eiffel classes - one per syntactic construct.

The library and its design principles are described in detail, together with EiffelBase, EiffelLex and EiffelParse in the book Reusable Software: The Base Object-Oriented Component Libraries.

A complementary tool, YOOCC, is available from Monash University (Melbourne, Australia).

Technical Information

EiffelLex is located in : $EIFFEL5/library/lex

EiffelParse is located in : $EIFFEL5/library/parse

Getting Started

You just need to get the EiffelLex and EiffelParse directories, to work with these libraries.

How to configure your Ace file

In order to use EiffelLex and EiffelParse in an Eiffel Project, you have to include in your project, the right clusters and the right external files. Thus, you need to configure your Ace file.

You can get all the information about Ace files here.

To include the EiffelLex cluster you just need to include in your ace file :

        lex:     "$EIFFEL5\library\lex";

To include the EiffelParse cluster you just need to include in your ace file:

        parse: "$EIFFEL5\library\parse";

You can check the examples to see a working Ace file.

Some working examples

We developed two examples that you can try to see how to use EiffelLex and EiffelParse

  • For EiffelLex

The example is located in the directory: $EIFFEL5/examples/lex

In order to run this example, you need to copy the file eiffel_regular in the directory EIFGEN/W_Code of your project.

Usage:
eiffel_scan eiffel_file_name

For example:
eiffel_scan sample_file.e

Description:
Example of a lexical analyzer for Eiffel.

If not previously built and stored, a stored lexical analyzer object is created according to regular expressions described by the file `eiffel_regular' and stored in `eiffel_lex' for doing lexical analysis of Eiffel code. (This may take a few moments.)

This object is then used to analyze the file named by the argument. Once the analyzer has been built, subsequent calls will be much faster.

See the "Introduction to the Lexical Library" chapter of EIFFEL: THE LIBRARIES for more information.

  • For EiffelParse

The example is located in the directory: $EIFFEL5/examples/parse

In order to run this example, you need to copy the file test_file in the directory EIFGEN/W_Code of your project.

Usage: 
process

Description:
Prompts for the name of a file with a polynomial description (see below), reads a polynomial from the given file, prompts for integer values of the variables, and evaluates the polynomial.

POLYNOMIAL DESCRIPTION 

  • Grammar:

    LINE = VARIABLES ":" SUM 
    VARIABLES = VAR .. ";" 
    SUM = DIFF .. "+" 
    DIFF = PRODUCT .. "-" 
    PRODUCT = TERM .. "*" 
    TERM = SIMPLE_VAR | INT_CONSTANT | NESTED
    NESTED = "(" SUM ")" 

Example: 
x;y: x*(y+8-(2*x))

See the "Introduction to the Parsing Library" chapter of EIFFEL: THE LIBRARIES for more information.