166 lines
15 KiB
HTML
166 lines
15 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://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"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
|
<meta name="generator" content="Doxygen 1.9.1"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
<title>sapphirec: src/Lexer.h Source File</title>
|
|
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="jquery.js"></script>
|
|
<script type="text/javascript" src="dynsections.js"></script>
|
|
<link href="navtree.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="resize.js"></script>
|
|
<script type="text/javascript" src="navtreedata.js"></script>
|
|
<script type="text/javascript" src="navtree.js"></script>
|
|
<link href="search/search.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="search/searchdata.js"></script>
|
|
<script type="text/javascript" src="search/search.js"></script>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css" />
|
|
<link href="doxygen-awesome.css" rel="stylesheet" type="text/css"/>
|
|
<link href="doxygen-awesome-sidebar-only.css" rel="stylesheet" type="text/css"/>
|
|
</head>
|
|
<body>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr style="height: 56px;">
|
|
<td id="projectalign" style="padding-left: 0.5em;">
|
|
<div id="projectname">sapphirec
|
|
</div>
|
|
<div id="projectbrief">The Sapphire documentation</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.9.1 -->
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
|
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
|
|
/* @license-end */
|
|
</script>
|
|
<script type="text/javascript" src="menudata.js"></script>
|
|
<script type="text/javascript" src="menu.js"></script>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
|
$(function() {
|
|
initMenu('',true,false,'search.php','Search');
|
|
$(document).ready(function() { init_search(); });
|
|
});
|
|
/* @license-end */</script>
|
|
<div id="main-nav"></div>
|
|
</div><!-- top -->
|
|
<div id="side-nav" class="ui-resizable side-nav-resizable">
|
|
<div id="nav-tree">
|
|
<div id="nav-tree-contents">
|
|
<div id="nav-sync" class="sync"></div>
|
|
</div>
|
|
</div>
|
|
<div id="splitbar" style="-moz-user-select:none;"
|
|
class="ui-resizable-handle">
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
|
$(document).ready(function(){initNavTree('_lexer_8h_source.html',''); initResizable(); });
|
|
/* @license-end */
|
|
</script>
|
|
<div id="doc-content">
|
|
<!-- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
</div>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<iframe src="javascript:void(0)" frameborder="0"
|
|
name="MSearchResults" id="MSearchResults">
|
|
</iframe>
|
|
</div>
|
|
|
|
<div class="header">
|
|
<div class="headertitle">
|
|
<div class="title">Lexer.h</div> </div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
<a href="_lexer_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> <span class="preprocessor">#pragma once</span></div>
|
|
<div class="line"><a name="l00002"></a><span class="lineno"> 2</span> <span class="preprocessor">#include "<a class="code" href="_token_8h.html">Token.h</a>"</span></div>
|
|
<div class="line"><a name="l00003"></a><span class="lineno"> 3</span> <span class="preprocessor">#include "<a class="code" href="sapphirepch_8h.html">sapphirepch.h</a>"</span></div>
|
|
<div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="preprocessor">#include <array></span></div>
|
|
<div class="line"><a name="l00005"></a><span class="lineno"> 5</span>  </div>
|
|
<div class="line"><a name="l00006"></a><span class="lineno"> 6</span> <span class="comment">/* Let's redefine TokenStream, as if it wasn't already defined in Token.h*/</span></div>
|
|
<div class="line"><a name="l00007"></a><span class="lineno"><a class="line" href="_lexer_8h.html#a43f892d4a347a32f8602cfbcff2e237e"> 7</a></span> <span class="keyword">typedef</span> std::vector<Token> <a class="code" href="_lexer_8h.html#a43f892d4a347a32f8602cfbcff2e237e">TokenStream</a>;</div>
|
|
<div class="line"><a name="l00008"></a><span class="lineno"> 8</span> <span class="comment">/* The number of data types currently in Sapphire. */</span></div>
|
|
<div class="line"><a name="l00009"></a><span class="lineno"><a class="line" href="_lexer_8h.html#a5aa140c2c2e64a57331d450a98077834"> 9</a></span> <span class="preprocessor">#define TYPE_COUNT 14</span></div>
|
|
<div class="line"><a name="l00010"></a><span class="lineno"> 10</span>  </div>
|
|
<div class="line"><a name="l00011"></a><span class="lineno"> 11</span> <span class="comment">/* The Lexer for the Sapphire compiler. A Lexer reads source code from a file, and turns it into a stream of tokens the</span></div>
|
|
<div class="line"><a name="l00012"></a><span class="lineno"> 12</span> <span class="comment"> * compiler can understand. */</span></div>
|
|
<div class="line"><a name="l00013"></a><span class="lineno"><a class="line" href="class_lexer.html"> 13</a></span> <span class="keyword">class </span><a class="code" href="class_lexer.html">Lexer</a></div>
|
|
<div class="line"><a name="l00014"></a><span class="lineno"> 14</span> {</div>
|
|
<div class="line"><a name="l00015"></a><span class="lineno"> 15</span>  <span class="keyword">private</span>:</div>
|
|
<div class="line"><a name="l00016"></a><span class="lineno"> 16</span>  <a class="code" href="struct_location.html">Location</a> loc;</div>
|
|
<div class="line"><a name="l00017"></a><span class="lineno"> 17</span>  <a class="code" href="struct_location.html">Location</a> prev_loc;</div>
|
|
<div class="line"><a name="l00018"></a><span class="lineno"> 18</span>  </div>
|
|
<div class="line"><a name="l00019"></a><span class="lineno"> 19</span>  <span class="keywordtype">int</span> advance();</div>
|
|
<div class="line"><a name="l00020"></a><span class="lineno"> 20</span>  <span class="keywordtype">int</span> rewind();</div>
|
|
<div class="line"><a name="l00021"></a><span class="lineno"> 21</span>  <span class="keywordtype">char</span> current_char;</div>
|
|
<div class="line"><a name="l00022"></a><span class="lineno"> 22</span>  <span class="keywordtype">int</span> index;</div>
|
|
<div class="line"><a name="l00023"></a><span class="lineno"> 23</span>  </div>
|
|
<div class="line"><a name="l00024"></a><span class="lineno"> 24</span>  <a class="code" href="class_lexer.html">Lexer</a>(<span class="keyword">const</span> std::string& fname);</div>
|
|
<div class="line"><a name="l00025"></a><span class="lineno"> 25</span>  </div>
|
|
<div class="line"><a name="l00026"></a><span class="lineno"> 26</span>  std::string current_line_text;</div>
|
|
<div class="line"><a name="l00027"></a><span class="lineno"> 27</span>  std::string previous_line_text;</div>
|
|
<div class="line"><a name="l00028"></a><span class="lineno"> 28</span>  </div>
|
|
<div class="line"><a name="l00029"></a><span class="lineno"> 29</span>  std::string current_lexed_text;</div>
|
|
<div class="line"><a name="l00030"></a><span class="lineno"> 30</span>  </div>
|
|
<div class="line"><a name="l00031"></a><span class="lineno"> 31</span>  std::string recalculate_current_line(<span class="keyword">const</span> std::string& text);</div>
|
|
<div class="line"><a name="l00032"></a><span class="lineno"> 32</span>  </div>
|
|
<div class="line"><a name="l00033"></a><span class="lineno"> 33</span>  <a class="code" href="struct_token.html">Token</a> create_string();</div>
|
|
<div class="line"><a name="l00034"></a><span class="lineno"> 34</span>  <a class="code" href="struct_token.html">Token</a> create_number();</div>
|
|
<div class="line"><a name="l00035"></a><span class="lineno"> 35</span>  <a class="code" href="struct_token.html">Token</a> create_identifier();</div>
|
|
<div class="line"><a name="l00036"></a><span class="lineno"> 36</span>  </div>
|
|
<div class="line"><a name="l00037"></a><span class="lineno"> 37</span>  <span class="keywordtype">bool</span> is_in_string(<span class="keyword">const</span> std::string& <span class="keywordtype">string</span>, <span class="keyword">const</span> <span class="keywordtype">char</span>& character);</div>
|
|
<div class="line"><a name="l00038"></a><span class="lineno"> 38</span>  </div>
|
|
<div class="line"><a name="l00039"></a><span class="lineno"> 39</span>  <span class="keyword">public</span>:</div>
|
|
<div class="line"><a name="l00040"></a><span class="lineno"> 40</span>  <span class="comment">/* An array containing Sapphire's current data types. */</span></div>
|
|
<div class="line"><a name="l00041"></a><span class="lineno"><a class="line" href="class_lexer.html#a8956f4484cb2a477bea5d09e96ea6c8d"> 41</a></span>  <span class="keyword">static</span> <span class="keyword">const</span> std::array<std::string, TYPE_COUNT> <a class="code" href="class_lexer.html#a8956f4484cb2a477bea5d09e96ea6c8d">types</a>;</div>
|
|
<div class="line"><a name="l00042"></a><span class="lineno"> 42</span>  </div>
|
|
<div class="line"><a name="l00043"></a><span class="lineno"> 43</span>  <a class="code" href="class_lexer.html#ad26a84af23d8d303723e36e83fc4e556">~Lexer</a>();</div>
|
|
<div class="line"><a name="l00044"></a><span class="lineno"> 44</span>  </div>
|
|
<div class="line"><a name="l00045"></a><span class="lineno"> 45</span>  <span class="comment">/* Lex the given text, turning it into a stream of tokens. */</span></div>
|
|
<div class="line"><a name="l00046"></a><span class="lineno"> 46</span>  <a class="code" href="_lexer_8h.html#a43f892d4a347a32f8602cfbcff2e237e">TokenStream</a> <a class="code" href="class_lexer.html#ac53b63f829071be755cc785084126afe">lex</a>(<span class="keyword">const</span> std::string& text);</div>
|
|
<div class="line"><a name="l00047"></a><span class="lineno"> 47</span>  </div>
|
|
<div class="line"><a name="l00048"></a><span class="lineno"> 48</span>  <span class="comment">/* Create a new Lexer and return a pointer to it. */</span></div>
|
|
<div class="line"><a name="l00049"></a><span class="lineno"> 49</span>  <span class="keyword">static</span> std::unique_ptr<Lexer> <a class="code" href="class_lexer.html#a6d24d823847b6d5f7e497d78f5b612d4">make_lexer</a>(<span class="keyword">const</span> std::string& fname);</div>
|
|
<div class="line"><a name="l00050"></a><span class="lineno"> 50</span>  </div>
|
|
<div class="line"><a name="l00051"></a><span class="lineno"> 51</span>  <span class="comment">/* If the Lexer is lexing an impòrted file, give it the location in the parent file at which it was imported. */</span></div>
|
|
<div class="line"><a name="l00052"></a><span class="lineno"> 52</span>  <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="class_lexer.html#a8f5d1d9281b44e287d7db2ef0c0dff09">assign_parent_location</a>(std::unique_ptr<Lexer>& lexer, <span class="keyword">const</span> std::shared_ptr<Location>& loc);</div>
|
|
<div class="line"><a name="l00053"></a><span class="lineno"> 53</span> };</div>
|
|
<div class="ttc" id="a_lexer_8h_html_a43f892d4a347a32f8602cfbcff2e237e"><div class="ttname"><a href="_lexer_8h.html#a43f892d4a347a32f8602cfbcff2e237e">TokenStream</a></div><div class="ttdeci">std::vector< Token > TokenStream</div><div class="ttdef"><b>Definition:</b> Lexer.h:7</div></div>
|
|
<div class="ttc" id="a_token_8h_html"><div class="ttname"><a href="_token_8h.html">Token.h</a></div></div>
|
|
<div class="ttc" id="aclass_lexer_html"><div class="ttname"><a href="class_lexer.html">Lexer</a></div><div class="ttdef"><b>Definition:</b> Lexer.h:14</div></div>
|
|
<div class="ttc" id="aclass_lexer_html_a6d24d823847b6d5f7e497d78f5b612d4"><div class="ttname"><a href="class_lexer.html#a6d24d823847b6d5f7e497d78f5b612d4">Lexer::make_lexer</a></div><div class="ttdeci">static std::unique_ptr< Lexer > make_lexer(const std::string &fname)</div><div class="ttdef"><b>Definition:</b> Lexer.cpp:63</div></div>
|
|
<div class="ttc" id="aclass_lexer_html_a8956f4484cb2a477bea5d09e96ea6c8d"><div class="ttname"><a href="class_lexer.html#a8956f4484cb2a477bea5d09e96ea6c8d">Lexer::types</a></div><div class="ttdeci">static const std::array< std::string, TYPE_COUNT > types</div><div class="ttdef"><b>Definition:</b> Lexer.h:41</div></div>
|
|
<div class="ttc" id="aclass_lexer_html_a8f5d1d9281b44e287d7db2ef0c0dff09"><div class="ttname"><a href="class_lexer.html#a8f5d1d9281b44e287d7db2ef0c0dff09">Lexer::assign_parent_location</a></div><div class="ttdeci">static void assign_parent_location(std::unique_ptr< Lexer > &lexer, const std::shared_ptr< Location > &loc)</div><div class="ttdef"><b>Definition:</b> Lexer.cpp:68</div></div>
|
|
<div class="ttc" id="aclass_lexer_html_ac53b63f829071be755cc785084126afe"><div class="ttname"><a href="class_lexer.html#ac53b63f829071be755cc785084126afe">Lexer::lex</a></div><div class="ttdeci">TokenStream lex(const std::string &text)</div><div class="ttdef"><b>Definition:</b> Lexer.cpp:78</div></div>
|
|
<div class="ttc" id="aclass_lexer_html_ad26a84af23d8d303723e36e83fc4e556"><div class="ttname"><a href="class_lexer.html#ad26a84af23d8d303723e36e83fc4e556">Lexer::~Lexer</a></div><div class="ttdeci">~Lexer()</div><div class="ttdef"><b>Definition:</b> Lexer.cpp:17</div></div>
|
|
<div class="ttc" id="asapphirepch_8h_html"><div class="ttname"><a href="sapphirepch_8h.html">sapphirepch.h</a></div></div>
|
|
<div class="ttc" id="astruct_location_html"><div class="ttname"><a href="struct_location.html">Location</a></div><div class="ttdef"><b>Definition:</b> Location.h:6</div></div>
|
|
<div class="ttc" id="astruct_token_html"><div class="ttname"><a href="struct_token.html">Token</a></div><div class="ttdef"><b>Definition:</b> Token.h:54</div></div>
|
|
</div><!-- fragment --></div><!-- contents -->
|
|
</div><!-- doc-content -->
|
|
<!-- start footer part -->
|
|
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
|
<ul>
|
|
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="_lexer_8h.html">Lexer.h</a></li>
|
|
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1 </li>
|
|
</ul>
|
|
</div>
|
|
</body>
|
|
</html>
|