The Accent Compiler Compiler

Using the ACCENT Compiler Compiler

Accent
Overview
Tutorial
Language
Installation
Usage
Lex
Algorithms
Distribution

How To Generate a Language Processor


  spec.acc     spec.lex  auxil.c  art.o  
   |            |         |        |
   |            |         |        |
   V            V         |        |  
  +------+     +---+      |        | 
  |ACCENT|     |LEX|      |        |
  +------+     +---+      |        |
   |            |         |        |
   |            |         |        |
   V            V         |        |
  yygrammar.h  lex.yy.c   |        |
  yygrammar.c   |         |        |
   |            |         |        |
   +------------+--+------+--------+
                   |
                   V
                  +--+
                  |CC|
                  +--+
                   |
                   |
                   V
                  calculator

Accent

Accent is invoked with the command
   accent file
This reads the grammar in file and generates the output files yygrammar.h and yygrammar.c.

yygrammar.h contains definitions of token codes and a definition of the type YYSTYPE (which is only effective if there is no previous definition specified by the user).

yygrammar.c contains the grammar encoding and a generated tree walker that performs the semantic actions specified by the user.

Example:

   accent spec.acc
The file spec.acc contains the Accent specification of a simple desk calculator.

Lex

The scanner should be generated with Lex. Lex is invoked by the command
   lex file
which reads the specification in file, a table of regular expressions and corresponding actions, and generates a file yy.lex.c. This file contains the function yylex(), the lexical analyzer which is invoked by the parser.

Example:

   lex spec.lex
The file spec.lex contains the Lex specification for the desk calculator.

Auxiliary Functions

The user has to prepare some auxiliary functions:

There should be a main() function that invokes the parser function yyparse().

yyerror(char *msg) is invoked by the parser when an error is detected. It should print the text msg and perhaps the current line number.

The scanner needs a function yywrap() (it can be used to switch to a further input file). In its simplest form it just returns 1 (indicating no further input file).

In our example, the file auxil.c defines these functions.

Accent Runtime

To create a functioning parser one also has to supply the Accent Runtime. This is contained in the file art.o in the directory art of the distribution.

Compiling and Linking

The C compiler is used to compile the sources and create the object program.

Example:

cc -o calculator yygrammar.c lex.yy.c auxil.c $ART
(where $ART refers to the Accent runtime).

The file build contains a shell script to produce and run the desk calculator.

Invoking the optimizer during compilation increases parser speed by a factor of two. For the GNU C compiler you should specify -O3 as an option when compiling the Accent runtime and the generated program.

accent.compilertools.net