<i>Accent</i> is invoked with the command
<pre>
accent file
</pre>
This reads the grammar in <tt>file</tt>
and generates the output files
<tt>yygrammar.h</tt> and
<tt>yygrammar.c</tt>.
<p>
<tt>yygrammar.h</tt> contains definitions of token codes
and a definition of the type <tt>YYSTYPE</tt> (which is only
effective if there is no previous definition specified by the user).
<p>
<tt>yygrammar.c</tt> contains the grammar encoding and a generated
tree walker that performs the semantic actions specified by the user.
<p>
Example:
<pre>
accent spec.acc
</pre>
The file
<a href="spec.acc">spec.acc</a>
contains the <i>Accent</i> specification of a simple desk calculator.
<h3>Lex</h3>
The scanner should be generated with <i>Lex</i>.
<i>Lex</i> is invoked by the command
<pre>
lex file
</pre>
which reads the specification in <tt>file</tt>,
a table of regular expressions and corresponding actions,
and generates a file <tt>yy.lex.c</tt>.
This file contains the function <tt>yylex()</tt>,
the lexical analyzer which is invoked by the parser.
<p>
Example:
<pre>
lex spec.lex
</pre>
The file
<a href="spec.lex">spec.lex</a>
contains the <i>Lex</i> specification
for the desk calculator.
<h3>Auxiliary Functions</h3>
The user has to prepare some auxiliary functions:
<p>
There should be a <tt>main()</tt> function that invokes
the parser function <tt>yyparse()</tt>.
<p>
<tt>yyerror(char *msg)</tt>
is invoked by the parser when an error is detected. It should print
the text <tt>msg</tt> and perhaps the current line number.
<p>
The scanner needs a function <tt>yywrap()</tt>
(it can be used to switch to a further input file).
In its simplest form it just returns <tt>1</tt>
(indicating no further input file).
<p>
In our example, the file
<a href="auxil.c"><tt>auxil.c</tt></a>
defines these functions.
<h3>Accent Runtime</h3>
To create a functioning parser one also has to supply
the <i>Accent Runtime</i>.
This is contained in the file <tt>art.o</tt> in the
directory <tt>art</tt> of the distribution.
<h3>Compiling and Linking</h3>
The <i>C</i> compiler is used
to compile the sources and create the object program.
<p>
Example:
<pre>
cc -o calculator yygrammar.c lex.yy.c auxil.c $ART
</pre>
(where <tt>$ART</tt> refers to the Accent runtime).
<p>
The file
<a href="build"><tt>build</tt></a>
contains a shell script to produce and run the desk calculator.
<p>
Invoking the optimizer during compilation increases parser speed
by a factor of two.
For the GNU C compiler you should specify <tt>-O3</tt> as an option
when compiling the Accent runtime and the generated program. <!--- end main content -->
<br>
<br>
<font face="helvetica" size="1">
<a href="http://accent.compilertools.net">accent.compilertools.net</a>
</font>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
¤ Dauer der Verarbeitung: 0.24 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.