Show parser.html syntax highlighted
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>5.3. Parser</title><link rel="stylesheet" href="megapov.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="MegaPOV Documentation"><link rel="up" href="internals.html" title="Chapter 5. Internals"><link rel="previous" href="binaries.html" title="5.2. Binaries"><link rel="next" href="internals_patterns.html" title="5.4. Patterns"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.3. Parser</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="binaries.html">Prev</a> </td><th width="60%" align="center">Chapter 5. Internals</th><td width="20%" align="right"> <a accesskey="n" href="internals_patterns.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="parser"></a>5.3. Parser</h2></div></div><div></div></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="internals_tokens"></a>5.3.1. Adding tokens</h3></div></div><div></div></div><p>
Whatever is changed in <span class="trademark">POV-Ray</span>™ sources, it is probably that new keywords to the parser have to be added.
To call your new keyword as <i class="parameter"><tt>NEW_KEYWORD_TOKEN</tt></i> we have to open <tt class="filename">parse.h</tt>
and find enumerated tokens within <tt class="function">TOKEN_IDS</tt>. Entries in this list are sorted mostly by usage.
</p><pre class="programlisting">enum TOKEN_IDS
{
ABS_TOKEN = 0,
:
:
#ifdef USAGE_WITH_NEW_KEYWORD_PATCH
NEW_KEYWORD_TOKEN,
#endif
:
:
};</pre><p>
Once integer identifier is added we have to connect <i class="parameter"><tt>NEW_KEYWORD_TOKEN</tt></i> with string
for proper parsing. This connection is realized via <tt class="function">Reserved_Words</tt> array in
<tt class="filename">tokenize.cpp</tt>.
</p><pre class="programlisting">RESERVED_WORD <i class="parameter"><tt>Reserved_Words</tt></i>[<i class="parameter"><tt>LAST_TOKEN</tt></i>] = {
{<i class="parameter"><tt>AA_THRESHOLD_TOKEN</tt></i>, "aa_threshold"},
:
:
#ifdef USAGE_WITH_NEW_KEYWORD_PATCH
{<i class="parameter"><tt>NEW_KEYWORD_TOKEN</tt></i>, "new_keyword" },
#endif
:
:
};</pre><p>
</p><div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Important"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="icons/important.gif"></td><th align="left">Important</th></tr><tr><td colspan="2" align="left" valign="top"><p>
Placing of entry into <i class="parameter"><tt>Reserved_Words</tt></i> table in <tt class="filename">tokenize.cpp</tt> does not
require any special order, but adding integer identifier into <tt class="function">TOKEN_IDS</tt> structure
in <tt class="filename">parse.h</tt> is connected with type of data returned by usage of added keywords.
They have to be located in following order:
</p><pre class="programlisting">enum <i class="parameter"><tt>TOKEN_IDS</tt></i>
{
/* tokens to be used when float value is expected from here */
<i class="parameter"><tt>ABS_TOKEN</tt></i> = 0,
<i class="parameter"><tt>ATAN_TOKEN</tt></i>,
:
<i class="parameter"><tt>FLOAT_FUNCT_TOKEN</tt></i>,
/* tokens to be used when vector value is expected from here */
<i class="parameter"><tt>VAXIS_ROTATE_TOKEN</tt></i>,
:
<i class="parameter"><tt>VECTOR_FUNCT_TOKEN</tt></i>,
/* tokens to be used when color value is expected from here */
<i class="parameter"><tt>ALPHA_TOKEN</tt></i>,
:
<i class="parameter"><tt>COLOUR_KEY_TOKEN</tt></i>,
/* other tokens from here */
:
/* <i class="parameter"><tt>LAST_TOKEN</tt></i> has to be the last */
<i class="parameter"><tt>LAST_TOKEN</tt></i>
};</pre><p>
</p></td></tr></table></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="binaries.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="internals.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="internals_patterns.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.2. Binaries </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 5.4. Patterns</td></tr></table></div></body></html>
See more files for this project here