SE250:lab-9:rwan064:tokenise.h

From Marks Wiki
Revision as of 05:20, 3 November 2008 by Mark (Sọ̀rọ̀ | contribs) (3 revision(s))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Back to Lab Report

<html> <head>

 <title>tokenise.h</title>

</head> <body bgcolor="#ffffff" text="#000000">

<a name="line1"> 1</a> <font color="#444444">/*
<a name="line2"> 2</a> 	File: tokenise.h
<a name="line3"> 3</a> 	Purpose: Header file for Tokeniser for SE250 Lab 9.

<a name="line4"> 4</a> 	Author: Rajitha Wannigama, John Hamer
<a name="line5"> 5</a> */</font>
<a name="line6"> 6</a> 
<a name="line7"> 7</a> <font color="0000ff"><strong>#include <font color="#008000"><stdio.h></font></strong></font>

<a name="line8"> 8</a> 
<a name="line9"> 9</a> <strong>typedef</strong> <strong>enum</strong> <font color="4444FF"><strong>{</strong></font>
<a name="line10">10</a> 	<font color="#2040a0">T_SYMBOL</font>,
<a name="line11">11</a> 	<font color="#2040a0">T_IDENT</font>,

<a name="line12">12</a> 	<font color="#2040a0">T_INTEGER</font>,
<a name="line13">13</a> 	<font color="#2040a0">T_FLOAT</font>,
<a name="line14">14</a> 	<font color="#2040a0">T_STRING</font>,
<a name="line15">15</a> 	<font color="#2040a0">T_END</font>,
<a name="line16">16</a> 	<font color="#2040a0">T_NOTHING</font>

<a name="line17">17</a> <font color="4444FF"><strong>}</strong></font> <font color="#2040a0">token_t</font><font color="4444FF">;</font>
<a name="line18">18</a> 
<a name="line19">19</a> <strong>typedef</strong> <strong>struct</strong> <font color="4444FF"><strong>{</strong></font>

<a name="line20">20</a> 	<font color="#2040a0">token_t</font> <font color="#2040a0">type</font><font color="4444FF">;</font>
<a name="line21">21</a> 	<strong>union</strong> <font color="4444FF"><strong>{</strong></font>
<a name="line22">22</a> 		<strong>int</strong>		<font color="#2040a0">symval</font><font color="4444FF">;</font>

<a name="line23">23</a> 		<strong>char</strong><font color="4444FF">*</font>	<font color="#2040a0">strval</font><font color="4444FF">;</font>
<a name="line24">24</a> 		<strong>int</strong>		<font color="#2040a0">intval</font><font color="4444FF">;</font>
<a name="line25">25</a> 		<strong>double</strong>	<font color="#2040a0">fltval</font><font color="4444FF">;</font>

<a name="line26">26</a> 	<font color="4444FF"><strong>}</strong></font> <font color="#2040a0">val</font><font color="4444FF">;</font>
<a name="line27">27</a> <font color="4444FF"><strong>}</strong></font> <font color="#2040a0">Token</font><font color="4444FF">;</font>
<a name="line28">28</a> 
<a name="line29">29</a> <strong>typedef</strong> <strong>struct</strong> <font color="4444FF"><strong>{</strong></font>

<a name="line30">30</a> 	<font color="#2040a0">Token</font><font color="4444FF">*</font> <font color="#2040a0">current</font><font color="4444FF">;</font>
<a name="line31">31</a> 	<strong>int</strong> <font color="#2040a0">pos</font><font color="4444FF">;</font>
<a name="line32">32</a> <font color="4444FF"><strong>}</strong></font> <font color="#2040a0">TokenStream</font><font color="4444FF">;</font>

<a name="line33">33</a> 
<a name="line34">34</a> 
<a name="line35">35</a> <font color="0000ff"><strong>#ifndef TOKENISE_H</strong></font>
<a name="line36">36</a> <font color="0000ff"><strong>#define TOKENISE_H</strong></font>
<a name="line37">37</a> 
<a name="line38">38</a> <strong>typedef</strong> <strong>enum</strong> <font color="4444FF"><strong>{</strong></font> <font color="#2040a0">false</font> <font color="4444FF">=</font> <font color="#FF0000">0</font>, <font color="#2040a0">true</font> <font color="4444FF">=</font> <font color="#FF0000">1</font> <font color="4444FF"><strong>}</strong></font> <font color="#2040a0">bool</font><font color="4444FF">;</font>

<a name="line39">39</a> 
<a name="line40">40</a> 
<a name="line41">41</a> <font color="#444444">/* The tokeniser interface */</font>
<a name="line42">42</a> <strong>void</strong> <font color="#2040a0">init_TokenStream</font><font color="4444FF">(</font> <font color="#2040a0">TokenStream</font><font color="4444FF">*</font>, <strong>char</strong><font color="4444FF">*</font> <font color="4444FF">)</font> <font color="4444FF">;</font>

<a name="line43">43</a> <font color="#2040a0">bool</font> <font color="#2040a0">eqToken</font><font color="4444FF">(</font> <font color="#2040a0">Token</font><font color="4444FF">*</font>, <font color="#2040a0">Token</font><font color="4444FF">*</font> <font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line44">44</a> <strong>void</strong> <font color="#2040a0">print_token</font><font color="4444FF">(</font> <font color="#2040a0">Token</font><font color="4444FF">*</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line45">45</a> <font color="#2040a0">Token</font><font color="4444FF">*</font> <font color="#2040a0">current</font><font color="4444FF">(</font> <font color="#2040a0">TokenStream</font><font color="4444FF">*</font> <font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line46">46</a> <strong>void</strong> <font color="#2040a0">advance</font><font color="4444FF">(</font> <font color="#2040a0">TokenStream</font><font color="4444FF">*</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line47">47</a> <strong>void</strong> <font color="#2040a0">expect</font><font color="4444FF">(</font> <font color="#2040a0">TokenStream</font><font color="4444FF">*</font>, <font color="#2040a0">Token</font><font color="4444FF">*</font> <font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line48">48</a> <strong>void</strong> <font color="#2040a0">error</font><font color="4444FF">(</font> <strong>char</strong><font color="4444FF">*</font> <font color="#2040a0">fmt</font>, ... <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line49">49</a> <font color="#2040a0">bool</font> <font color="#2040a0">isVariable</font><font color="4444FF">(</font> <font color="#2040a0">Token</font><font color="4444FF">*</font> <font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line50">50</a> <font color="#2040a0">bool</font> <font color="#2040a0">isConstant</font><font color="4444FF">(</font> <font color="#2040a0">Token</font><font color="4444FF">*</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line51">51</a> <font color="#2040a0">bool</font> <font color="#2040a0">end_of_tokens</font><font color="4444FF">(</font> <font color="#2040a0">TokenStream</font><font color="4444FF">*</font> <font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line52">52</a> 
<a name="line53">53</a> <strong>extern</strong> <font color="#2040a0">Token</font> <font color="#2040a0">TOK_ADD</font><font color="4444FF">;</font>

<a name="line54">54</a> <strong>extern</strong> <font color="#2040a0">Token</font> <font color="#2040a0">TOK_ASSIGN</font><font color="4444FF">;</font>
<a name="line55">55</a> <strong>extern</strong> <font color="#2040a0">Token</font> <font color="#2040a0">TOK_CLOSEBRACE</font><font color="4444FF">;</font>

<a name="line56">56</a> <strong>extern</strong> <font color="#2040a0">Token</font> <font color="#2040a0">TOK_DIV</font><font color="4444FF">;</font>
<a name="line57">57</a> <strong>extern</strong> <font color="#2040a0">Token</font> <font color="#2040a0">TOK_DO</font><font color="4444FF">;</font>

<a name="line58">58</a> <strong>extern</strong> <font color="#2040a0">Token</font> <font color="#2040a0">TOK_ELSE</font><font color="4444FF">;</font>
<a name="line59">59</a> <strong>extern</strong> <font color="#2040a0">Token</font> <font color="#2040a0">TOK_EQ</font><font color="4444FF">;</font>

<a name="line60">60</a> <strong>extern</strong> <font color="#2040a0">Token</font> <font color="#2040a0">TOK_ERROR</font><font color="4444FF">;</font>
<a name="line61">61</a> <strong>extern</strong> <font color="#2040a0">Token</font> <font color="#2040a0">TOK_IF</font><font color="4444FF">;</font>

<a name="line62">62</a> <strong>extern</strong> <font color="#2040a0">Token</font> <font color="#2040a0">TOK_MUL</font><font color="4444FF">;</font>
<a name="line63">63</a> <strong>extern</strong> <font color="#2040a0">Token</font> <font color="#2040a0">TOK_NOT</font><font color="4444FF">;</font>

<a name="line64">64</a> <strong>extern</strong> <font color="#2040a0">Token</font> <font color="#2040a0">TOK_OPENBRACE</font><font color="4444FF">;</font>
<a name="line65">65</a> <strong>extern</strong> <font color="#2040a0">Token</font> <font color="#2040a0">TOK_PCLOSE</font><font color="4444FF">;</font>

<a name="line66">66</a> <strong>extern</strong> <font color="#2040a0">Token</font> <font color="#2040a0">TOK_POPEN</font><font color="4444FF">;</font>
<a name="line67">67</a> <strong>extern</strong> <font color="#2040a0">Token</font> <font color="#2040a0">TOK_PRINT</font><font color="4444FF">;</font>

<a name="line68">68</a> <strong>extern</strong> <font color="#2040a0">Token</font> <font color="#2040a0">TOK_SEMICOLON</font><font color="4444FF">;</font>
<a name="line69">69</a> <strong>extern</strong> <font color="#2040a0">Token</font> <font color="#2040a0">TOK_SKIP</font><font color="4444FF">;</font>

<a name="line70">70</a> <strong>extern</strong> <font color="#2040a0">Token</font> <font color="#2040a0">TOK_SUB</font><font color="4444FF">;</font>
<a name="line71">71</a> <strong>extern</strong> <font color="#2040a0">Token</font> <font color="#2040a0">TOK_THEN</font><font color="4444FF">;</font>

<a name="line72">72</a> <strong>extern</strong> <font color="#2040a0">Token</font> <font color="#2040a0">TOK_WHILE</font><font color="4444FF">;</font>
<a name="line73">73</a> 
<a name="line74">74</a> <strong>void</strong> <font color="#2040a0">init_predefined_tokens</font><font color="4444FF">(</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line75">75</a> 
<a name="line76">76</a> <font color="0000ff"><strong>#endif</strong></font>


syntax highlighted by <a href="http://www.palfrader.org/code2html">Code2HTML</a>, v. 0.9.1 </body> </html>