SE250:lab-9:rwan064:main.c

From Marks Wiki
Jump to navigation Jump to search

Back to Lab Report

<html> <head>

 <title>main.c</title>

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

<a name="line1">  1</a> <font color="#444444">/*
<a name="line2">  2</a> 	File: main.c
<a name="line3">  3</a> 	Purpose: Test program for SE250 Lab 9 Tokeniser.

<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>#include <font color="#008000"><stdio.h></font></strong></font>

<a name="line8">  8</a> <font color="0000ff"><strong>#include <font color="#008000"><stdlib.h></font></strong></font>
<a name="line9">  9</a> <font color="0000ff"><strong>#include <font color="#008000"><string.h></font></strong></font>
<a name="line10"> 10</a> 
<a name="line11"> 11</a> <font color="0000ff"><strong>#include <font color="#008000">"tokenise.h"</font></strong></font>

<a name="line12"> 12</a> <font color="0000ff"><strong>#include <font color="#008000">"string.h"</font></strong></font>
<a name="line13"> 13</a> <font color="0000ff"><strong>#include <font color="#008000">"scanner.h"</font></strong></font>
<a name="line14"> 14</a> 
<a name="line15"> 15</a> <strong>void</strong> <font color="#2040a0">test_String</font><font color="4444FF">(</font> <strong>void</strong> <font color="4444FF">)</font>

<a name="line16"> 16</a> <font color="4444FF"><strong>{</strong></font>
<a name="line17"> 17</a> 	<font color="#2040a0">String</font> <font color="4444FF">*</font><font color="#2040a0">s1</font> <font color="4444FF">=</font> <font color="#2040a0">create_empty_string</font><font color="4444FF">(</font><font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line18"> 18</a> 	<font color="#2040a0">String</font> <font color="4444FF">*</font><font color="#2040a0">s2</font> <font color="4444FF">=</font> <font color="#2040a0">create_string</font><font color="4444FF">(</font> <font color="#008000">"hello"</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line19"> 19</a> 	<font color="#2040a0">String</font> <font color="4444FF">*</font><font color="#2040a0">s3</font> <font color="4444FF">=</font> <font color="#2040a0">create_string</font><font color="4444FF">(</font> <font color="#008000">"world!"</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line20"> 20</a> 	<font color="#2040a0">print_string</font><font color="4444FF">(</font> <font color="#2040a0">s1</font> <font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line21"> 21</a> 	<font color="#2040a0">print_string</font><font color="4444FF">(</font> <font color="#2040a0">s2</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line22"> 22</a> 	
<a name="line23"> 23</a> 	<font color="#2040a0">puts</font><font color="4444FF">(</font> <font color="#008000">"--- Test change_string() "</font> <font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line24"> 24</a> 	<font color="#2040a0">change_string</font><font color="4444FF">(</font> <font color="#2040a0">s1</font>, <font color="#2040a0">s2</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line25"> 25</a> 	<font color="#2040a0">print_string</font><font color="4444FF">(</font> <font color="#2040a0">s1</font> <font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line26"> 26</a> 	<font color="#2040a0">print_string</font><font color="4444FF">(</font> <font color="#2040a0">s2</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line27"> 27</a> 	
<a name="line28"> 28</a> 	<font color="#2040a0">puts</font><font color="4444FF">(</font> <font color="#008000">"--- Test append_string() "</font> <font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line29"> 29</a> 	<font color="#2040a0">append_string</font><font color="4444FF">(</font> <font color="#2040a0">s1</font>, <font color="#2040a0">s3</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line30"> 30</a> 	<font color="#2040a0">print_string</font><font color="4444FF">(</font> <font color="#2040a0">s1</font> <font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line31"> 31</a> 	<font color="#2040a0">print_string</font><font color="4444FF">(</font> <font color="#2040a0">s2</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line32"> 32</a> 	<font color="#2040a0">printf</font><font color="4444FF">(</font> <font color="#008000">"%d %d<font color="#77dd77">\n</font>"</font>, <font color="#2040a0">s1</font><font color="4444FF">-</font><font color="4444FF">></font><font color="#2040a0">length</font>, <font color="#2040a0">s1</font><font color="4444FF">-</font><font color="4444FF">></font><font color="#2040a0">capacity</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line33"> 33</a> 	<font color="#2040a0">printf</font><font color="4444FF">(</font> <font color="#008000">"%d %d<font color="#77dd77">\n</font>"</font>, <font color="#2040a0">s2</font><font color="4444FF">-</font><font color="4444FF">></font><font color="#2040a0">length</font>, <font color="#2040a0">s2</font><font color="4444FF">-</font><font color="4444FF">></font><font color="#2040a0">capacity</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line34"> 34</a> 	
<a name="line35"> 35</a> 	<font color="#2040a0">puts</font><font color="4444FF">(</font> <font color="#2040a0">get_cstring</font><font color="4444FF">(</font> <font color="#2040a0">s1</font> <font color="4444FF">)</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line36"> 36</a> 	
<a name="line37"> 37</a> 	<font color="#2040a0">puts</font><font color="4444FF">(</font> <font color="#008000">"--- Test append_cstring() "</font> <font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line38"> 38</a> 	<font color="#2040a0">append_cstring</font><font color="4444FF">(</font> <font color="#2040a0">s1</font>, <font color="#008000">" my world! "</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line39"> 39</a> 	<font color="#2040a0">append_cstring</font><font color="4444FF">(</font> <font color="#2040a0">s1</font>, <font color="#008000">"int compile( FILE *fpIn, FILE *fpOut )"</font> <font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line40"> 40</a> 	<font color="#2040a0">print_string</font><font color="4444FF">(</font> <font color="#2040a0">s1</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line41"> 41</a> 	<font color="#2040a0">printf</font><font color="4444FF">(</font> <font color="#008000">"%d %d<font color="#77dd77">\n</font>"</font>, <font color="#2040a0">s1</font><font color="4444FF">-</font><font color="4444FF">></font><font color="#2040a0">length</font>, <font color="#2040a0">s1</font><font color="4444FF">-</font><font color="4444FF">></font><font color="#2040a0">capacity</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line42"> 42</a> <font color="4444FF"><strong>}</strong></font>
<a name="line43"> 43</a> 
<a name="line44"> 44</a> 
<a name="line45"> 45</a> 
<a name="line46"> 46</a> 

<a name="line47"> 47</a> <font color="#444444">/*
<a name="line48"> 48</a> 	All main does is open the input source file and an output file stream with the filenames
<a name="line49"> 49</a> 	given at the command line and calls the "scan" function. Then closes both the streams.
<a name="line50"> 50</a> */</font>

<a name="line51"> 51</a> <strong>int</strong> <font color="#2040a0">main</font><font color="4444FF">(</font> <strong>int</strong> <font color="#2040a0">argc</font>, <strong>char</strong> <font color="4444FF">*</font><font color="#2040a0">argv</font><font color="4444FF">[</font><font color="4444FF">]</font> <font color="4444FF">)</font>

<a name="line52"> 52</a> <font color="4444FF"><strong>{</strong></font>
<a name="line53"> 53</a> <font color="0000ff"><strong>#if 1</strong></font>
<a name="line54"> 54</a> 	<strong>if</strong> <font color="4444FF">(</font> <font color="#2040a0">argc</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#FF0000">3</font> <font color="4444FF">)</font> <font color="4444FF"><strong>{</strong></font>

<a name="line55"> 55</a> 		<font color="#2040a0">FILE</font> <font color="4444FF">*</font><font color="#2040a0">fpIn</font><font color="4444FF">;</font>		// <font color="#2040a0">Input</font> <font color="#2040a0">C</font> <font color="#2040a0">file</font>
<a name="line56"> 56</a> 		<font color="#2040a0">FILE</font> <font color="4444FF">*</font><font color="#2040a0">fpOut</font><font color="4444FF">;</font>	// <font color="#2040a0">Output</font> <font color="#2040a0">C</font> <font color="#2040a0">file</font>

<a name="line57"> 57</a> 		
<a name="line58"> 58</a> 		<font color="#2040a0">fpIn</font> <font color="4444FF">=</font> <font color="#2040a0">fopen</font><font color="4444FF">(</font> <font color="#2040a0">argv</font><font color="4444FF">[</font><font color="#FF0000">1</font><font color="4444FF">]</font>, <font color="#008000">"r"</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line59"> 59</a> 		<strong>if</strong> <font color="4444FF">(</font> <font color="#2040a0">fpIn</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#2040a0">NULL</font> <font color="4444FF">)</font> <font color="4444FF"><strong>{</strong></font>

<a name="line60"> 60</a> 			<font color="#2040a0">printf</font><font color="4444FF">(</font> <font color="#008000">"Cannot open file <font color="#77dd77">\"</font>%s<font color="#77dd77">\"</font> for reading<font color="#77dd77">\n</font>"</font>, <font color="#2040a0">argv</font><font color="4444FF">[</font><font color="#FF0000">1</font><font color="4444FF">]</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line61"> 61</a> 			<strong>return</strong> <font color="#FF0000">0</font><font color="4444FF">;</font>
<a name="line62"> 62</a> 		<font color="4444FF"><strong>}</strong></font>
<a name="line63"> 63</a> 		
<a name="line64"> 64</a> 		// <font color="#2040a0">Below</font> <font color="#2040a0">code</font> <font color="#2040a0">assumes</font> <font color="#2040a0">filename</font> <font color="#2040a0">of</font> <font color="#2040a0">file</font> <font color="#2040a0">to</font> <font color="#2040a0">be</font> <font color="#2040a0">created</font> <font color="#2040a0">is</font> <font color="#2040a0">initially</font> <font color="#2040a0">on</font> <font color="#2040a0">argv</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font>.

<a name="line65"> 65</a> 		<font color="#2040a0">fpOut</font> <font color="4444FF">=</font> <font color="#2040a0">fopen</font><font color="4444FF">(</font> <font color="#2040a0">argv</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font>, <font color="#008000">"r"</font> <font color="4444FF">)</font><font color="4444FF">;</font>	// <font color="#2040a0">Open</font> <strong>for</strong> <font color="#2040a0">reading</font> <font color="#2040a0">so</font> <font color="#2040a0">I</font> <font color="#2040a0">can</font> <font color="#2040a0">check</font> <strong>for</strong> <font color="#2040a0">existing</font> <font color="#2040a0">files</font> <font color="#2040a0">with</font> <font color="#2040a0">that</font> <font color="#2040a0">name</font>.

<a name="line66"> 66</a> 		<strong>if</strong> <font color="4444FF">(</font> <font color="#2040a0">fpOut</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#2040a0">NULL</font> <font color="4444FF">)</font> <font color="4444FF"><strong>{</strong></font>

<a name="line67"> 67</a> 			// <font color="#2040a0">File</font> <font color="#2040a0">doesn</font>'<font color="#2040a0">t</font> <font color="#2040a0">exist</font>, <font color="#2040a0">so</font> <font color="#2040a0">create</font> <font color="#2040a0">new</font> <font color="#2040a0">file</font>. <font color="#2040a0">No</font> <font color="#2040a0">need</font> <font color="#2040a0">to</font> <font color="#2040a0">use</font> <font color="#2040a0">fclose</font> <font color="#2040a0">since</font> <font color="#2040a0">first</font> <font color="#2040a0">open</font> <font color="#2040a0">was</font> <font color="#2040a0">un</font><font color="4444FF">-</font><font color="#2040a0">successful</font>.

<a name="line68"> 68</a> 			<font color="#2040a0">fpOut</font> <font color="4444FF">=</font> <font color="#2040a0">fopen</font><font color="4444FF">(</font> <font color="#2040a0">argv</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font>, <font color="#008000">"w"</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line69"> 69</a> 			<strong>if</strong> <font color="4444FF">(</font> <font color="#2040a0">fpOut</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#2040a0">NULL</font> <font color="4444FF">)</font> <font color="4444FF"><strong>{</strong></font>

<a name="line70"> 70</a> 				<font color="#2040a0">printf</font><font color="4444FF">(</font> <font color="#008000">"Cannot create output file <font color="#77dd77">\"</font>%s<font color="#77dd77">\"</font><font color="#77dd77">\n</font>"</font>, <font color="#2040a0">argv</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line71"> 71</a> 				<strong>return</strong> <font color="#FF0000">0</font><font color="4444FF">;</font>
<a name="line72"> 72</a> 			<font color="4444FF"><strong>}</strong></font>
<a name="line73"> 73</a> 		<font color="4444FF"><strong>}</strong></font>

<a name="line74"> 74</a> 		<strong>else</strong> <font color="4444FF"><strong>{</strong></font>
<a name="line75"> 75</a> 			<strong>int</strong> <font color="#2040a0">again</font> <font color="4444FF">=</font> <font color="#FF0000">1</font><font color="4444FF">;</font>		// <font color="#2040a0">To</font> <font color="#2040a0">control</font> <strong>while</strong> <font color="#2040a0">loop</font>.

<a name="line76"> 76</a> 			<strong>char</strong> <font color="#2040a0">input</font><font color="4444FF">[</font><font color="#FF0000">256</font><font color="4444FF">]</font><font color="4444FF">;</font>	// <font color="#2040a0">New</font> <font color="#2040a0">output</font> <font color="#2040a0">filename</font>, <strong>if</strong> <font color="#2040a0">necessary</font>.

<a name="line77"> 77</a> 			<strong>char</strong> <font color="#2040a0">ans</font><font color="4444FF">[</font><font color="#FF0000">20</font><font color="4444FF">]</font><font color="4444FF">;</font>		// <font color="#2040a0">Answer</font> <font color="#2040a0">to</font> <font color="#2040a0">Yes</font>/<font color="#2040a0">No</font> <font color="#2040a0">question</font>.

<a name="line78"> 78</a> 			
<a name="line79"> 79</a> 			// <font color="#2040a0">Need</font> <font color="#2040a0">to</font> <font color="#2040a0">copy</font> <font color="#2040a0">filename</font> <font color="#2040a0">given</font> <font color="#2040a0">as</font> <font color="#2040a0">command</font> <font color="#2040a0">line</font> <font color="#2040a0">input</font> <font color="#2040a0">into</font> <font color="#2040a0">a</font> <font color="#2040a0">new</font> <font color="#2040a0">string</font> <font color="#2040a0">so</font> <font color="#2040a0">the</font> <strong>while</strong> <font color="#2040a0">loop</font> <font color="#2040a0">will</font> <font color="#2040a0">work</font> <font color="#2040a0">properly</font>.

<a name="line80"> 80</a> 			<font color="#2040a0">strcpy</font><font color="4444FF">(</font> <font color="#2040a0">input</font>, <font color="#2040a0">argv</font><font color="4444FF">[</font><font color="#FF0000">2</font><font color="4444FF">]</font> <font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line81"> 81</a> 			

<a name="line82"> 82</a> 			<strong>while</strong> <font color="4444FF">(</font> <font color="#2040a0">again</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#FF0000">1</font> <font color="4444FF">)</font> <font color="4444FF"><strong>{</strong></font>

<a name="line83"> 83</a> 				// <font color="#2040a0">File</font> <font color="#2040a0">exists</font>, <font color="#2040a0">ask</font> <strong>for</strong> <font color="#2040a0">replacement</font> <font color="#2040a0">or</font> <font color="#2040a0">new</font> <font color="#2040a0">output</font> <font color="#2040a0">filename</font>.

<a name="line84"> 84</a> 				<font color="#2040a0">printf</font><font color="4444FF">(</font> <font color="#008000">"A file with the name <font color="#77dd77">\"</font>%s<font color="#77dd77">\"</font> already exist. Replace file? (Y/N): "</font>, <font color="#2040a0">input</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line85"> 85</a> 				<font color="#2040a0">gets</font><font color="4444FF">(</font> <font color="#2040a0">ans</font> <font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line86"> 86</a> 				<strong>if</strong> <font color="4444FF">(</font> <font color="4444FF">(</font><font color="4444FF">(</font><font color="#2040a0">ans</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#008000">'Y'</font><font color="4444FF">)</font> <font color="4444FF">|</font><font color="4444FF">|</font> <font color="4444FF">(</font><font color="#2040a0">ans</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#008000">'y'</font><font color="4444FF">)</font><font color="4444FF">)</font> <font color="4444FF">&</font><font color="4444FF">&</font> <font color="4444FF">(</font> <font color="#2040a0">strlen</font><font color="4444FF">(</font> <font color="#2040a0">ans</font> <font color="4444FF">)</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#FF0000">1</font> <font color="4444FF">)</font> <font color="4444FF">)</font> <font color="4444FF"><strong>{</strong></font>

<a name="line87"> 87</a> 					// <font color="#2040a0">Replace</font> <font color="#2040a0">existing</font> <font color="#2040a0">file</font>.
<a name="line88"> 88</a> 					<font color="#2040a0">fclose</font><font color="4444FF">(</font> <font color="#2040a0">fpOut</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line89"> 89</a> 					<font color="#2040a0">fpOut</font> <font color="4444FF">=</font> <font color="#2040a0">fopen</font><font color="4444FF">(</font> <font color="#2040a0">input</font>, <font color="#008000">"w"</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line90"> 90</a> 					<strong>if</strong> <font color="4444FF">(</font> <font color="#2040a0">fpOut</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#2040a0">NULL</font> <font color="4444FF">)</font> <font color="4444FF"><strong>{</strong></font>

<a name="line91"> 91</a> 						<font color="#2040a0">printf</font><font color="4444FF">(</font> <font color="#008000">"Cannot create output file <font color="#77dd77">\"</font>%s<font color="#77dd77">\"</font><font color="#77dd77">\n</font>"</font>, <font color="#2040a0">input</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line92"> 92</a> 						<strong>return</strong> <font color="#FF0000">0</font><font color="4444FF">;</font>
<a name="line93"> 93</a> 					<font color="4444FF"><strong>}</strong></font>
<a name="line94"> 94</a> 					<font color="#2040a0">again</font> <font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">;</font>

<a name="line95"> 95</a> 				<font color="4444FF"><strong>}</strong></font>
<a name="line96"> 96</a> 				<strong>else</strong> <font color="4444FF"><strong>{</strong></font>
<a name="line97"> 97</a> 					// <font color="#2040a0">Don</font>'<font color="#2040a0">t</font> <font color="#2040a0">replace</font> <font color="#2040a0">file</font>. <font color="#2040a0">So</font> <font color="#2040a0">close</font> <font color="#2040a0">existing</font> <font color="#2040a0">stream</font> <font color="#2040a0">and</font> <font color="#2040a0">open</font> <font color="#2040a0">a</font> <font color="#2040a0">new</font> <font color="#2040a0">one</font>.

<a name="line98"> 98</a> 					<font color="#2040a0">fclose</font><font color="4444FF">(</font> <font color="#2040a0">fpOut</font> <font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line99"> 99</a> 					<font color="#2040a0">printf</font><font color="4444FF">(</font> <font color="#008000">"Enter a new output filename: "</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line100">100</a> 					<font color="#2040a0">gets</font><font color="4444FF">(</font> <font color="#2040a0">input</font> <font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line101">101</a> 					// <font color="#2040a0">MUST</font> <font color="#2040a0">CHECK</font> <font color="#2040a0">IF</font> <font color="#2040a0">NEW</font> <font color="#2040a0">FILENAME</font> <font color="#2040a0">EXISTS</font> <font color="#2040a0">ASWELL</font><font color="4444FF">!</font>

<a name="line102">102</a> 					<font color="#2040a0">fpOut</font> <font color="4444FF">=</font> <font color="#2040a0">fopen</font><font color="4444FF">(</font> <font color="#2040a0">input</font>, <font color="#008000">"r"</font> <font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line103">103</a> 					<strong>if</strong> <font color="4444FF">(</font> <font color="#2040a0">fpOut</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#2040a0">NULL</font> <font color="4444FF">)</font> <font color="4444FF"><strong>{</strong></font>

<a name="line104">104</a> 						// <font color="#2040a0">File</font> <font color="#2040a0">doesn</font>'<font color="#2040a0">t</font> <font color="#2040a0">exist</font>, <font color="#2040a0">so</font> <font color="#2040a0">create</font> <font color="#2040a0">new</font> <font color="#2040a0">file</font>. <font color="#2040a0">Not</font> <font color="#2040a0">need</font> <font color="#2040a0">to</font> <font color="#2040a0">use</font> <font color="#2040a0">fclose</font> <font color="#2040a0">since</font> <font color="#2040a0">first</font> <font color="#2040a0">open</font> <font color="#2040a0">was</font> <font color="#2040a0">un</font><font color="4444FF">-</font><font color="#2040a0">successful</font>.

<a name="line105">105</a> 						<font color="#2040a0">fpOut</font> <font color="4444FF">=</font> <font color="#2040a0">fopen</font><font color="4444FF">(</font> <font color="#2040a0">input</font>, <font color="#008000">"w"</font> <font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line106">106</a> 						<strong>if</strong> <font color="4444FF">(</font> <font color="#2040a0">fpOut</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#2040a0">NULL</font> <font color="4444FF">)</font> <font color="4444FF"><strong>{</strong></font>

<a name="line107">107</a> 							<font color="#2040a0">printf</font><font color="4444FF">(</font> <font color="#008000">"Cannot create output file <font color="#77dd77">\"</font>%s<font color="#77dd77">\"</font><font color="#77dd77">\n</font>"</font>, <font color="#2040a0">input</font> <font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line108">108</a> 							<strong>return</strong> <font color="#FF0000">0</font><font color="4444FF">;</font>

<a name="line109">109</a> 						<font color="4444FF"><strong>}</strong></font>
<a name="line110">110</a> 						<font color="#2040a0">again</font> <font color="4444FF">=</font> <font color="#FF0000">0</font><font color="4444FF">;</font>
<a name="line111">111</a> 					<font color="4444FF"><strong>}</strong></font>

<a name="line112">112</a> 				<font color="4444FF"><strong>}</strong></font>
<a name="line113">113</a> 			<font color="4444FF"><strong>}</strong></font>
<a name="line114">114</a> 			
<a name="line115">115</a> 		<font color="4444FF"><strong>}</strong></font>
<a name="line116">116</a> 		<font color="#2040a0">TokenStream</font><font color="4444FF">*</font> <font color="#2040a0">tokens</font> <font color="4444FF">=</font> <font color="4444FF">(</font><font color="#2040a0">TokenStream</font><font color="4444FF">*</font><font color="4444FF">)</font> <font color="#2040a0">malloc</font><font color="4444FF">(</font><strong>sizeof</strong><font color="4444FF">(</font><font color="#2040a0">TokenStream</font><font color="4444FF">)</font><font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line117">117</a> 		<font color="#2040a0">String</font> <font color="4444FF">*</font><font color="#2040a0">code</font> <font color="4444FF">=</font> <font color="#2040a0">scan</font><font color="4444FF">(</font> <font color="#2040a0">fpIn</font>, <font color="#2040a0">fpOut</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line118">118</a> 		<strong>char</strong> <font color="4444FF">*</font><font color="#2040a0">token_string</font> <font color="4444FF">=</font> <font color="#2040a0">get_cstring</font><font color="4444FF">(</font> <font color="#2040a0">code</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line119">119</a> 		<font color="#2040a0">init_TokenStream</font><font color="4444FF">(</font> <font color="#2040a0">tokens</font>, <font color="#2040a0">token_string</font> <font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line120">120</a> 		<font color="#2040a0">printf</font><font color="4444FF">(</font> <font color="#008000">"<font color="#77dd77">\n</font><font color="#77dd77">\n</font>%s"</font>, <font color="#2040a0">token_string</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line121">121</a> 		<font color="#2040a0">Token</font> <font color="#2040a0">s</font>, <font color="#2040a0">t</font><font color="4444FF">;</font>
<a name="line122">122</a> 		<font color="#2040a0">s</font>.<font color="#2040a0">type</font> <font color="4444FF">=</font> <font color="#2040a0">T_SYMBOL</font><font color="4444FF">;</font>

<a name="line123">123</a> 		<font color="#2040a0">t</font>.<font color="#2040a0">type</font> <font color="4444FF">=</font> <font color="#2040a0">T_SYMBOL</font><font color="4444FF">;</font>
<a name="line124">124</a> 		<font color="#2040a0">s</font>.<font color="#2040a0">val</font>.<font color="#2040a0">symval</font> <font color="4444FF">=</font> <font color="#FF0000">25</font><font color="4444FF">;</font>

<a name="line125">125</a> 		<font color="#2040a0">t</font>.<font color="#2040a0">val</font>.<font color="#2040a0">symval</font> <font color="4444FF">=</font> <font color="#FF0000">25</font><font color="4444FF">;</font>
<a name="line126">126</a> 		//<font color="#2040a0">printf</font><font color="4444FF">(</font> <font color="#008000">"%d<font color="#77dd77">\n</font>"</font>, <font color="#2040a0">eqToken</font><font color="4444FF">(</font> <font color="4444FF">&</font><font color="#2040a0">s</font>, <font color="4444FF">&</font><font color="#2040a0">t</font> <font color="4444FF">)</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line127">127</a> 		
<a name="line128">128</a> 		<font color="#2040a0">fclose</font><font color="4444FF">(</font> <font color="#2040a0">fpIn</font> <font color="4444FF">)</font><font color="4444FF">;</font>
<a name="line129">129</a> 		<font color="#2040a0">fclose</font><font color="4444FF">(</font> <font color="#2040a0">fpOut</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line130">130</a> 	<font color="4444FF"><strong>}</strong></font>
<a name="line131">131</a> 	<strong>else</strong> <font color="4444FF"><strong>{</strong></font>
<a name="line132">132</a> 		<font color="#2040a0">puts</font><font color="4444FF">(</font> <font color="#008000">"Usage: main.exe <input.c> <output.c><font color="#77dd77">\n</font>"</font> <font color="4444FF">)</font><font color="4444FF">;</font>

<a name="line133">133</a> 	<font color="4444FF"><strong>}</strong></font>
<a name="line134">134</a> <font color="0000ff"><strong>#endif</strong></font>
<a name="line135">135</a> 	
<a name="line136">136</a> 	<strong>return</strong> <font color="#FF0000">0</font><font color="4444FF">;</font>

<a name="line137">137</a> <font color="4444FF"><strong>}</strong></font>


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