![]() |
The Accent Compiler Compiler
Using the ACCENT Compiler Compiler |
|
Accent Overview Tutorial Language Installation Usage Lex Algorithms Distribution |
How To Generate a Language Processor
AccentAccent is invoked with the commandaccent fileThis 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.accThe file spec.acc contains the Accent specification of a simple desk calculator. LexThe scanner should be generated with Lex. Lex is invoked by the commandlex filewhich 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.lexThe file spec.lex contains the Lex specification for the desk calculator. Auxiliary FunctionsThe 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 RuntimeTo 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 LinkingThe 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.
|