<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Eli</title>
    <description>The latest articles on Forem by Eli (@elipie).</description>
    <link>https://forem.com/elipie</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F540298%2Fff47ba45-503f-4a73-82f2-8468d0b1574f.png</url>
      <title>Forem: Eli</title>
      <link>https://forem.com/elipie</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/elipie"/>
    <language>en</language>
    <item>
      <title>Rust or Go</title>
      <dc:creator>Eli</dc:creator>
      <pubDate>Sun, 20 Dec 2020 21:21:34 +0000</pubDate>
      <link>https://forem.com/elipie/rust-or-go-19hd</link>
      <guid>https://forem.com/elipie/rust-or-go-19hd</guid>
      <description>&lt;p&gt;Just wanted some pros and cons of both languages&lt;/p&gt;

</description>
      <category>rust</category>
      <category>go</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Designing A Programming Language</title>
      <dc:creator>Eli</dc:creator>
      <pubDate>Thu, 17 Dec 2020 15:32:00 +0000</pubDate>
      <link>https://forem.com/elipie/designing-a-programming-language-22ha</link>
      <guid>https://forem.com/elipie/designing-a-programming-language-22ha</guid>
      <description>&lt;h1&gt;
  
  
  Hello
&lt;/h1&gt;

&lt;p&gt;I recently created a post about how a lexer and parser works... this is a continuation of that post. &lt;/p&gt;

&lt;h1&gt;
  
  
  Starting
&lt;/h1&gt;

&lt;p&gt;When writing a programming language, you want to establish the grammar first. It is the most &lt;em&gt;important&lt;/em&gt; part of the language. You might be thinking: "But what about the code?? That is the most hardest part of the programming language!!"&lt;br&gt;
At a time, I did think that too. But I realized, once I started coding it right away, without establishing the &lt;em&gt;full&lt;/em&gt; grammar, I got lost and didn't know what to do. That is why you establish the grammar first. &lt;/p&gt;

&lt;p&gt;What will the grammar be like?? Will it be like ruby and rust? Julia and Haskell? What do &lt;em&gt;you&lt;/em&gt; think? What is something you &lt;em&gt;really&lt;/em&gt; want in programming? Take that, and put it in your language. Do you want a built in file-encrypt function? Will the print be a macro or function? These are all questions you have to ask yourself before actually creating a programming language.&lt;/p&gt;

&lt;p&gt;The biggest part: &lt;strong&gt;The design Goal&lt;/strong&gt;. The design goal is a goal that you want your programming language to achieve. &lt;em&gt;Will it target machine learning or Data Science? Will it target something unique that you made up?&lt;/em&gt;&lt;br&gt;
The design goal really is the biggest part. It determines what kinda of people you are targeting. It determines whether the language is useful or not. I mean, sometimes it is fun to make a language for general purposes, but you will lose interest(coming from the experience)&lt;/p&gt;

&lt;h1&gt;
  
  
  :)
&lt;/h1&gt;

&lt;p&gt;I hope you use this information well, and happy coding.&lt;/p&gt;

</description>
      <category>python</category>
      <category>replit</category>
      <category>design</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Intro To Parsing &amp; Lexing</title>
      <dc:creator>Eli</dc:creator>
      <pubDate>Mon, 14 Dec 2020 17:29:15 +0000</pubDate>
      <link>https://forem.com/elipie/intro-to-parsing-lexing-3g01</link>
      <guid>https://forem.com/elipie/intro-to-parsing-lexing-3g01</guid>
      <description>&lt;h1&gt;
  
  
  About
&lt;/h1&gt;

&lt;p&gt;I decided one day, that I would learn C++ and make a programming language. It is &lt;em&gt;PieLang&lt;/em&gt;. I have been working on it for 6 months, and hope it will come out swell. I dived into it, and found that the water was, way, way, &lt;strong&gt;way&lt;/strong&gt; to deep. I decided to take a break, and learn how Lexing and Parsing work. 2 months later, I continued. It is an advanced topic, and I still don't know it all. But this is the basics to help you start creating your own programming language!&lt;/p&gt;

&lt;h1&gt;
  
  
  Lexing
&lt;/h1&gt;

&lt;p&gt;Lexing or &lt;em&gt;lex&lt;/em&gt; is the first step of making a programming language. I, if I need to provide code snippets, will write them in C++.&lt;/p&gt;

&lt;p&gt;Well, Lexing basically takes the source code(file/input) and turns them into a stream of tokens. Take this code for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print(2 + 2);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This would return a token stream, something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;IDENT: "print"
LPAREN: '('
NUMBER: '2'
OP: '+'
NUMBER: '2'
RPAREN: ')'
EOL: ';'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;EOL stands for end of line by the way&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You see how that went character by character? It returned a token stream!&lt;/p&gt;

&lt;p&gt;If you don't get what I mean, think of this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="nf"&gt;Lexer&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="c1"&gt;// ...&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;token_stream&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or something like that.&lt;/p&gt;

&lt;p&gt;Lets do another tokenize...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s"&gt;"Hello, world!"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's see what the lexer spits out this time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;IDENT: "int"
IDENT: "main"
LPAREN: '('
RPAREN: ')'
LCURLY: '{'
IDENT: "std::cout"
LESS_THAN: '&amp;lt;'
LESS_THAN: '&amp;lt;'
STRING: "Hello, world!"
EOL: ';'
RCURLY: '}'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Woah, that was much more! Imagine your biggest program, then imagine how many tokens there were!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; See how the double quotes 'disappear'? Thats because the lexer sees them, but it doesn't output them as tokens, it just tells the lexer: &lt;em&gt;"Oh, hey, this is a string!"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Double-Note:&lt;/strong&gt; &lt;code&gt;std::&lt;/code&gt; is a &lt;em&gt;library&lt;/em&gt; so if the &lt;em&gt;real&lt;/em&gt; lexer saw that it would be like: &lt;em&gt;"Lets access the struct/namespace/class called std! Oh wait, that is a built in lib! Lets access that instead"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Lets imagine that we were checking if something was a print statement(this code is not real)!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;type&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s"&gt;"IDENT"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s"&gt;"std::cout"&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="c1"&gt;//...&lt;/span&gt;
  &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;cout&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;That is not real code, it just helps us understand more!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now that you know some lexing, its parsing...&lt;/p&gt;

&lt;h1&gt;
  
  
  Parsing
&lt;/h1&gt;

&lt;p&gt;The &lt;em&gt;parser&lt;/em&gt; creates an &lt;strong&gt;AST&lt;/strong&gt;(abstract syntax tree) and then either executes it or sends it to the compiler/interpreter to do the work. &lt;/p&gt;

&lt;p&gt;Example of an AST:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     +
    / \
   1   2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This basic representation of a AST helps us understand it better! Lets take a look here. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;+&lt;/code&gt; symbol is telling that we are &lt;em&gt;adding&lt;/em&gt; these numbers. &lt;br&gt;
Then the two numbers are below it(&lt;code&gt;1, 2&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Lets take a more advanced equation. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;1+2*3-4&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Hmm, we couldn't do that in a if statement! That's why we have to send it to the parser!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       -
      /  \
     +    4
    / \
   1   *
       /\
      2  3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remember that little AST that we made before? Well that is this, just more of them packed together! Don't believe me? Lemme explain. We start of with &lt;code&gt;-&lt;/code&gt; or minuce. (Remember how we started off with the &lt;code&gt;+&lt;/code&gt; last time?) Then we went to &lt;code&gt;+&lt;/code&gt; and &lt;code&gt;4&lt;/code&gt;. Lets think of the plus as a &lt;em&gt;variable&lt;/em&gt;, which it holds this value: &lt;br&gt;
&lt;code&gt;+ = 1+(2*3)&lt;/code&gt;&lt;br&gt;
&lt;em&gt;I know that is against the rules of coding,  but this is just to show you&lt;/em&gt;&lt;br&gt;
You get it? Good. Cause next is the second stage. &lt;/p&gt;

&lt;p&gt;The parser eventually solves all of the problems, like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Second stage 
      - 
     / \
    +   4
   / \
  1   6 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Notice:&lt;/strong&gt; Notice how the (2*3) turned to six? Yeah. Cool right?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Third stage
    -
   / \ 
  7   4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yay, we got it all the way down to &lt;code&gt;7-4&lt;/code&gt;! Now we can just do the equation...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Final stage 
3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Boom! We just solved &lt;code&gt;1+2*3-4&lt;/code&gt;!&lt;/p&gt;

&lt;h1&gt;
  
  
  After
&lt;/h1&gt;

&lt;p&gt;It takes a strong mind to actually &lt;em&gt;code&lt;/em&gt; these things. I hope you can do this, with the foundation I have created for you. &lt;/p&gt;

&lt;h1&gt;
  
  
  Links
&lt;/h1&gt;

&lt;p&gt;Here are some useful links!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Craftinginterpreters.com&lt;/em&gt; This link helped me with the basic knowledge I know, so go check it out: &lt;a href="https://craftinginterpreters.com"&gt;https://craftinginterpreters.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;PieLang&lt;/em&gt; Want to see the progress that I am making with my language? Here is the github link: &lt;a href="https://github.com/elipie/PieLang"&gt;https://github.com/elipie/PieLang&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, the most useful link I could give you is: &lt;a href="https://google.com"&gt;https://google.com&lt;/a&gt; Google and any browser is a great source of ideas, and help.&lt;/p&gt;

&lt;h1&gt;
  
  
  Found something?
&lt;/h1&gt;

&lt;p&gt;Found a bug, error, typo, or something thats not true? Put it in the comments&lt;/p&gt;

&lt;h1&gt;
  
  
  Happy coding, and stay safe.
&lt;/h1&gt;

</description>
      <category>lexing</category>
      <category>parsing</category>
      <category>cpp</category>
      <category>python</category>
    </item>
  </channel>
</rss>
