-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepl_8cpp_source.html
executable file
·117 lines (117 loc) · 12.9 KB
/
repl_8cpp_source.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Lisp: repl.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.3 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main Page</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<div class="tabs">
<ul>
<li><a href="files.html"><span>File List</span></a></li>
<li><a href="globals.html"><span>File Members</span></a></li>
</ul>
</div>
<h1>repl.cpp</h1><a href="repl_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001
<a name="l00002"></a>00002 <span class="preprocessor">#include <iostream></span>
<a name="l00003"></a>00003 <span class="preprocessor">#include <string></span>
<a name="l00004"></a>00004 <span class="preprocessor">#include <cstdlib></span>
<a name="l00005"></a>00005 <span class="preprocessor">#include <fstream></span>
<a name="l00006"></a>00006
<a name="l00007"></a>00007 <span class="preprocessor">#include "<a class="code" href="repl_8h.html">repl.h</a>"</span>
<a name="l00008"></a>00008 <span class="preprocessor">#include "<a class="code" href="parser_8h.html">parser.h</a>"</span>
<a name="l00009"></a>00009 <span class="preprocessor">#include "<a class="code" href="exceptions_8h.html">exceptions.h</a>"</span>
<a name="l00010"></a>00010
<a name="l00011"></a><a class="code" href="classRepl.html#ad62e656af4e8a8deea5b0942db93dda5">00011</a> <span class="keywordtype">void</span> <a class="code" href="classRepl.html#ad62e656af4e8a8deea5b0942db93dda5">Repl::run</a>(<a class="code" href="classEnviroment.html" title="Enviroment - prostředí ve kterém se provádí kód.">Enviroment</a> env) {
<a name="l00012"></a>00012 <a class="code" href="classParser.html" title="Převede zdroják na programový strom.">Parser</a> p;
<a name="l00013"></a>00013
<a name="l00014"></a>00014 <span class="keywordflow">while</span> (cin.good()) {
<a name="l00015"></a>00015 cout << <span class="stringliteral">"> "</span>; <span class="comment">// prompt</span>
<a name="l00016"></a>00016 <span class="keywordtype">string</span> command = this-><a class="code" href="classRepl.html#af4afd8a3329ff3c19f464af05b1633b7" title="načte a vrátí řádek načtený z parametru is">getline</a>(cin);
<a name="l00017"></a>00017
<a name="l00018"></a>00018 <a class="code" href="classLList.html" title="Seznam - linked list.">LList</a>* program = p.<a class="code" href="classParser.html#ac8a6e3b6fe3822be53b6e8c10e655e31">parseString</a>(command);
<a name="l00019"></a>00019 <span class="comment">// cout <<"program: " << program->printable();</span>
<a name="l00020"></a>00020 <a class="code" href="repl_8cpp.html#adef3a81477183de1af12cf2a6a77e6ad">evalProgram</a>(&env, program);
<a name="l00021"></a>00021 }
<a name="l00022"></a>00022 }
<a name="l00023"></a>00023
<a name="l00024"></a><a class="code" href="classRepl.html#af4afd8a3329ff3c19f464af05b1633b7">00024</a> <span class="keywordtype">string</span> <a class="code" href="classRepl.html#af4afd8a3329ff3c19f464af05b1633b7" title="načte a vrátí řádek načtený z parametru is">Repl::getline</a>(istream&is) {
<a name="l00025"></a>00025 <span class="keywordtype">string</span> str;
<a name="l00026"></a>00026 <span class="keywordtype">char</span> chr = 0;
<a name="l00027"></a>00027 <span class="keywordflow">while</span> (is.good() && chr != <span class="charliteral">'\n'</span>) {
<a name="l00028"></a>00028 chr = is.get();
<a name="l00029"></a>00029 str.push_back(chr);
<a name="l00030"></a>00030 }
<a name="l00031"></a>00031
<a name="l00032"></a>00032 <span class="keywordflow">return</span> str;
<a name="l00033"></a>00033 }
<a name="l00034"></a>00034
<a name="l00036"></a><a class="code" href="repl_8cpp.html#a4f3aa76a2bcefccddf31adf2c8b2afff">00036</a> <span class="keywordtype">void</span> <a class="code" href="repl_8cpp.html#a4f3aa76a2bcefccddf31adf2c8b2afff" title="Vytiskne Traceback (informace o stacku v době chyby).">printTraceback</a>(<a class="code" href="classBaseException.html" title="Rodičovská, abstraktní třída všech vyjímek.">BaseException</a> e) {
<a name="l00037"></a>00037 cout << <span class="stringliteral">"---------------------------------------------------------------------------"</span> << endl;
<a name="l00038"></a>00038 cout << <span class="stringliteral">"Trackback:"</span> << endl;
<a name="l00039"></a>00039 <span class="keywordflow">for</span> (list<LFunction*>::iterator it = e.<a class="code" href="classBaseException.html#a7335307cbf17b3203a94aadbc55fc7dd" title="debug. info pro traceback">functions</a>.begin(); it != e.<a class="code" href="classBaseException.html#a7335307cbf17b3203a94aadbc55fc7dd" title="debug. info pro traceback">functions</a>.end(); it++) {
<a name="l00040"></a>00040 <span class="keywordflow">if</span> ((*it)->name != <span class="stringliteral">""</span>) {
<a name="l00041"></a>00041 cout << <span class="stringliteral">"> "</span> << (*it)->name << <span class="stringliteral">": "</span>;
<a name="l00042"></a>00042
<a name="l00043"></a>00043 <span class="keywordflow">if</span> ((*it)->line) {
<a name="l00044"></a>00044 cout << <span class="stringliteral">"on line "</span> << (*it)->line << <span class="stringliteral">" "</span>;
<a name="l00045"></a>00045 }
<a name="l00046"></a>00046 cout << endl;
<a name="l00047"></a>00047 }
<a name="l00048"></a>00048 }
<a name="l00049"></a>00049 }
<a name="l00050"></a>00050
<a name="l00051"></a><a class="code" href="repl_8h.html#adef3a81477183de1af12cf2a6a77e6ad">00051</a> <a class="code" href="classElem.html" title="Abstraktní prataťka všech datových typů.">Elem</a> * <a class="code" href="repl_8cpp.html#adef3a81477183de1af12cf2a6a77e6ad">evalProgram</a>(<a class="code" href="classEnviroment.html" title="Enviroment - prostředí ve kterém se provádí kód.">Enviroment</a> * env, <a class="code" href="classLList.html" title="Seznam - linked list.">LList</a> * program) {
<a name="l00052"></a>00052 <span class="keywordflow">try</span> {
<a name="l00053"></a>00053 <span class="keywordflow">return</span> env-><a class="code" href="classEnviroment.html#a97ec775af7153a1da74447ec95569052">progn</a>(program); <span class="comment">// zkus program vykonat</span>
<a name="l00054"></a>00054 } <span class="keywordflow">catch</span> (<a class="code" href="classNameException.html" title="vyjímka pro neexistující symbol (funkce i proměnné)">NameException</a> e) { <span class="comment">// a kdyz se to nepovede napis co se stalo:</span>
<a name="l00055"></a>00055
<a name="l00056"></a>00056 <span class="keywordflow">if</span> (!e.<a class="code" href="classBaseException.html#a7335307cbf17b3203a94aadbc55fc7dd" title="debug. info pro traceback">functions</a>.empty()) {
<a name="l00057"></a>00057 <a class="code" href="repl_8cpp.html#a4f3aa76a2bcefccddf31adf2c8b2afff" title="Vytiskne Traceback (informace o stacku v době chyby).">printTraceback</a>(e);
<a name="l00058"></a>00058 }
<a name="l00059"></a>00059 cout << <span class="stringliteral">"NameError: "</span> << e.<a class="code" href="classBaseException.html#ac970c7f195710ce512a2b05da04bc01a" title="Informace pro chybovou hlášku.">desc</a> << <span class="stringliteral">" "</span>;
<a name="l00060"></a>00060 <span class="keywordflow">if</span> (e.<a class="code" href="classBaseException.html#aab474f5dda270c1618e707a4d03936bc" title="Informace pro chybovou hlášku.">line</a>) {
<a name="l00061"></a>00061 cout << <span class="stringliteral">"on line "</span> << e.<a class="code" href="classBaseException.html#aab474f5dda270c1618e707a4d03936bc" title="Informace pro chybovou hlášku.">line</a> << <span class="stringliteral">". "</span>;
<a name="l00062"></a>00062 }
<a name="l00063"></a>00063
<a name="l00064"></a>00064 cout << endl;
<a name="l00065"></a>00065 } <span class="keywordflow">catch</span> (<a class="code" href="classBaseException.html" title="Rodičovská, abstraktní třída všech vyjímek.">BaseException</a> e) { <span class="comment">//vyjimky poskytuji v .desc dostatek informací.</span>
<a name="l00066"></a>00066 cout << <span class="stringliteral">"ERROR: "</span> << e.<a class="code" href="classBaseException.html#ac970c7f195710ce512a2b05da04bc01a" title="Informace pro chybovou hlášku.">desc</a> << endl;
<a name="l00067"></a>00067 <span class="keywordflow">if</span> (!e.<a class="code" href="classBaseException.html#a7335307cbf17b3203a94aadbc55fc7dd" title="debug. info pro traceback">functions</a>.empty()) {
<a name="l00068"></a>00068 <a class="code" href="repl_8cpp.html#a4f3aa76a2bcefccddf31adf2c8b2afff" title="Vytiskne Traceback (informace o stacku v době chyby).">printTraceback</a>(e);
<a name="l00069"></a>00069 }
<a name="l00070"></a>00070 }
<a name="l00071"></a>00071 <span class="keywordflow">return</span> NULL;
<a name="l00072"></a>00072 }
<a name="l00073"></a>00073
<a name="l00074"></a><a class="code" href="repl_8h.html#aefadd946a208caa8d0dffb0e41f0e919">00074</a> <a class="code" href="classElem.html" title="Abstraktní prataťka všech datových typů.">Elem</a> * <a class="code" href="repl_8cpp.html#aefadd946a208caa8d0dffb0e41f0e919" title="Spustí lispovský program daný parametrem filename v enviromentu env.">proccessFile</a>(<a class="code" href="classEnviroment.html" title="Enviroment - prostředí ve kterém se provádí kód.">Enviroment</a>& env, <span class="keywordtype">string</span> filename) {
<a name="l00075"></a>00075 <a class="code" href="classParser.html" title="Převede zdroják na programový strom.">Parser</a> p;
<a name="l00076"></a>00076 <span class="keywordflow">try</span> {
<a name="l00077"></a>00077 ifstream stdlibStream(filename.c_str(), ifstream::in);
<a name="l00078"></a>00078 <a class="code" href="classLList.html" title="Seznam - linked list.">LList</a>* stdlib = p.<a class="code" href="classParser.html#a9aec6055008f7898b73692b8b9dc9143" title="Převede předaný stream na string a předá parseString() (mají stejné API).">parseStream</a>(stdlibStream);
<a name="l00079"></a>00079 <span class="keywordflow">return</span> <a class="code" href="repl_8cpp.html#adef3a81477183de1af12cf2a6a77e6ad">evalProgram</a>(&env, stdlib);
<a name="l00080"></a>00080 } <span class="keywordflow">catch</span> (<a class="code" href="classIOException.html" title="vyjímka pro špatné I/O operace (neexistující soubor atd)">IOException</a> e) {
<a name="l00081"></a>00081 cout << <span class="stringliteral">"lisp: Can't open file "</span> << filename << <span class="stringliteral">": No such file or directory"</span> << endl;
<a name="l00082"></a>00082 <span class="keywordflow">return</span> NULL;
<a name="l00083"></a>00083 } <span class="keywordflow">catch</span> (<a class="code" href="classSyntaxException.html" title="vyjímka pro chyby v syntaxi (vyhazuje Parser)">SyntaxException</a> e) {
<a name="l00084"></a>00084
<a name="l00085"></a>00085 cout << e.<a class="code" href="classBaseException.html#ac970c7f195710ce512a2b05da04bc01a" title="Informace pro chybovou hlášku.">desc</a> << <span class="stringliteral">" in file "</span> << filename << <span class="stringliteral">" on line "</span> << e.<a class="code" href="classBaseException.html#aab474f5dda270c1618e707a4d03936bc" title="Informace pro chybovou hlášku.">line</a> << endl;
<a name="l00086"></a>00086 }
<a name="l00087"></a>00087 <span class="keywordflow">return</span> NULL; <span class="comment">//v případě chyby</span>
<a name="l00088"></a>00088 }
</pre></div></div>
<hr class="footer"/><address style="text-align: right;"><small>Generated on Tue May 24 16:12:17 2011 for Lisp by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
</body>
</html>