SE250:lab-9:rwan064:scanner.h

From Marks Wiki
Jump to navigation Jump to search

Back to Lab Report

<html> <head>

 <title>scanner.h</title>

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

<a name="line1"> 1</a> <font color="#444444">/*
<a name="line2"> 2</a> 	File: scanner.h
<a name="line3"> 3</a> 	Purpose: Header for Code that takes an input stream of characters and seperates it into operators, identifiers and seperators.

<a name="line4"> 4</a> 	Author: Rajitha Wannigama
<a name="line5"> 5</a> */</font>
<a name="line6"> 6</a> 
<a name="line7"> 7</a> <font color="0000ff"><strong>#define PRINT_DEBUG printf( <font color="#008000">"DEBUGGING at Line %d<font color="#77dd77">\n</font>"</font>, __LINE__ );</strong></font>

<a name="line8"> 8</a> 
<a name="line9"> 9</a> <strong>extern</strong> <strong>const</strong> <strong>int</strong> <font color="#2040a0">CPFILE_OP</font><font color="4444FF">;</font>
<a name="line10">10</a> <strong>extern</strong> <strong>const</strong> <strong>int</strong> <font color="#2040a0">CPFILE_EOF</font><font color="4444FF">;</font>

<a name="line11">11</a> <strong>extern</strong> <strong>const</strong> <strong>int</strong> <font color="#2040a0">CPFILE_NL</font><font color="4444FF">;</font>
<a name="line12">12</a> <strong>extern</strong> <strong>const</strong> <strong>int</strong> <font color="#2040a0">CPFILE_SP</font><font color="4444FF">;</font>

<a name="line13">13</a> <strong>extern</strong> <strong>const</strong> <strong>int</strong> <font color="#2040a0">CPFILE_TAB</font><font color="4444FF">;</font>
<a name="line14">14</a> <strong>extern</strong> <strong>const</strong> <strong>int</strong> <font color="#2040a0">CPFILE_UN</font><font color="4444FF">;</font>

<a name="line15">15</a> 
<a name="line16">16</a> <font color="#444444">/*
<a name="line17">17</a> 	Returns true if the character passed as a paramter is a C operator, false otherwise.
<a name="line18">18</a> */</font>
<a name="line19">19</a> <font color="#2040a0">bool</font> <font color="#2040a0">is_operator</font><font color="4444FF">(</font> <strong>char</strong> <font color="#2040a0">c</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line20">20</a> 
<a name="line21">21</a> <font color="#444444">/*
<a name="line22">22</a> 	Seperators are SPACE's, TAB's, NEWLINE's or EOF's.
<a name="line23">23</a> */</font>
<a name="line24">24</a> <font color="#2040a0">bool</font> <font color="#2040a0">is_seperator</font><font color="4444FF">(</font> <strong>char</strong> <font color="#2040a0">c</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line25">25</a> 
<a name="line26">26</a> <font color="#444444">/*
<a name="line27">27</a> 	Read till a space, new line, an operator or EOF is reached.
<a name="line28">28</a> 	If an operator is read as the first character then that
<a name="line29">29</a> 	operator is returned and function exits. Otherwise the
<a name="line30">30</a> 	whole word is returned till another operator is found.

<a name="line31">31</a> */</font>
<a name="line32">32</a> <strong>int</strong> <font color="#2040a0">read_word</font><font color="4444FF">(</font> <font color="#2040a0">FILE</font> <font color="4444FF">*</font><font color="#2040a0">fp</font>, <strong>char</strong> <font color="4444FF">*</font><font color="#2040a0">str</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line33">33</a> 
<a name="line34">34</a> <font color="#444444">/*
<a name="line35">35</a> 	Returns true if str is a keyword of C, false otherwise.
<a name="line36">36</a> */</font>
<a name="line37">37</a> <font color="#2040a0">bool</font> <font color="#2040a0">is_keyword</font><font color="4444FF">(</font> <strong>char</strong> <font color="4444FF">*</font><font color="#2040a0">str</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line38">38</a> 
<a name="line39">39</a> <font color="#2040a0">String</font><font color="4444FF">*</font> <font color="#2040a0">scan</font><font color="4444FF">(</font> <font color="#2040a0">FILE</font> <font color="4444FF">*</font><font color="#2040a0">fpIn</font>, <font color="#2040a0">FILE</font> <font color="4444FF">*</font><font color="#2040a0">fpOut</font> <font color="4444FF">)</font><font color="4444FF">;</font>


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