<?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>DEV Community: Oguzhan Yagci</title>
    <description>The latest articles on DEV Community by Oguzhan Yagci (@oyagci).</description>
    <link>https://dev.to/oyagci</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%2F1045%2Faf074dcf-596b-4b61-a5ea-40eeda6ddd6d.png</url>
      <title>DEV Community: Oguzhan Yagci</title>
      <link>https://dev.to/oyagci</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/oyagci"/>
    <language>en</language>
    <item>
      <title>How to read a documentation?</title>
      <dc:creator>Oguzhan Yagci</dc:creator>
      <pubDate>Fri, 12 Jan 2018 23:20:07 +0000</pubDate>
      <link>https://dev.to/oyagci/how-to-read-a-documentation-368p</link>
      <guid>https://dev.to/oyagci/how-to-read-a-documentation-368p</guid>
      <description>&lt;p&gt;My biggest issue so far as a software developer is reading a doc. How many times did I open the docs of a new tool I am learning only to end up on Google asking how to do this and that.&lt;/p&gt;

&lt;p&gt;Man pages are a bit easier to understand because usually I use them on specific functions. But for a frameworks like ExpressJS or bigger ones like Qt I am completely lost.&lt;/p&gt;

&lt;p&gt;What are your tips to read a documentation efficiently?&lt;/p&gt;

</description>
      <category>help</category>
      <category>documentation</category>
      <category>learn</category>
    </item>
    <item>
      <title>Shell redirections explained</title>
      <dc:creator>Oguzhan Yagci</dc:creator>
      <pubDate>Sat, 04 Nov 2017 21:38:15 +0000</pubDate>
      <link>https://dev.to/oyagci/shell-redirections-explained-2h9</link>
      <guid>https://dev.to/oyagci/shell-redirections-explained-2h9</guid>
      <description>&lt;p&gt;As a student I have to use my shell everyday to get my work done. A shell can be an extremely powerful tool in everyday life if you know how to use it.&lt;/p&gt;

&lt;p&gt;Shell redirections are something you have to use in order to accomplish many tasks without pain. &lt;/p&gt;

&lt;h1&gt;
  
  
  How a program outputs its content on the terminal.
&lt;/h1&gt;

&lt;p&gt;To output text on the terminal a program must write it's output into a file. The classical way to manipulate files on a UNIX-like operating system is by requesting to the OS a file descriptor (fd). An fd is an unsigned integer given by the OS that identifies a given file on the system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;File descriptors are numbers that represent a way to access files.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By default your program gets 3 file descriptors that are called &lt;code&gt;stdin&lt;/code&gt;, &lt;code&gt;stdout&lt;/code&gt; and &lt;code&gt;stderr&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The first fd &lt;code&gt;stdin&lt;/code&gt; is the file used by your program to read input. It's default value is &lt;code&gt;0&lt;/code&gt;. If you start a program like &lt;code&gt;cat&lt;/code&gt; without arguments it reads its input from &lt;code&gt;stdin&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The second fd &lt;code&gt;stdout&lt;/code&gt; is used to output content for the user (like "Hello World!"). It's default value is &lt;code&gt;1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The third fd open by default is &lt;code&gt;stderr&lt;/code&gt;. This one works exactly like &lt;code&gt;stdout&lt;/code&gt; except we mostly use it to output error messages. It's default value is &lt;code&gt;2&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Shell redirections operators
&lt;/h1&gt;

&lt;p&gt;In a shell, there are a few operators to perform redirections. Those are &lt;code&gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;&lt;/code&gt;, &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt;, &lt;code&gt;&amp;gt;&amp;amp;&lt;/code&gt;, &lt;code&gt;&amp;lt;&amp;amp;&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt;, and &lt;code&gt;&amp;lt;&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Those 3 operators have one main thing in common: They interact with input/output files.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; are used to redirect output from a program into a file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$&amp;gt; cat my_file.txt &amp;gt; my_new_file.txt # The output from cat is redirect to a file caled my_new_file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(If the file does not exist, it is created)&lt;/p&gt;

&lt;p&gt;The difference between &lt;code&gt;&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; is that &lt;code&gt;&amp;gt;&lt;/code&gt; truncates the file it is outputing to and &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; appends to the output file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$&amp;gt; echo Hello World! &amp;gt; greeting.txt # Creates a file with 'Hello World!' as the content

$&amp;gt; echo How are you? &amp;gt;&amp;gt; greeting.txt # Append 'How are you?' to greeting.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;&amp;lt;&lt;/code&gt; allows you to use a file as input. So &lt;code&gt;stdin&lt;/code&gt; becomes the file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$&amp;gt; base64 &amp;lt; greeting.txt # base64 will use stdin as input which is redirected to greeting.txt by the shell
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also combine multiple redirection operators:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$&amp;gt; cat &amp;lt; a.txt &amp;gt; b.txt # Reads from a.txt and outputs to b.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  And &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;That one is a bit like the three above, except that it does not interact with files. Instead it is used to get input from the user's keyboard line by line.&lt;/p&gt;

&lt;p&gt;So when you do something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$&amp;gt; cat &amp;lt;&amp;lt;EOF
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;... and press enter, the shell will expect input.&lt;br&gt;
So you can continue:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$&amp;gt; cat &amp;lt;&amp;lt;EOF
&amp;gt; Hello World!
&amp;gt; How are you?
&amp;gt; Do you know the answer to the ultimate question?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And when you want to stop the input you either press &lt;code&gt;Ctrl+D&lt;/code&gt; or type the word which is on the right side of the &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; operator (In this case &lt;code&gt;EOF&lt;/code&gt;) and press enter (it must be on an empty line):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$&amp;gt; cat &amp;lt;&amp;lt; EOF
&amp;gt; Hello World!
&amp;gt; How are you?
&amp;gt; Do you know the answer to the ultimate question?
&amp;gt; EOF
Hello World!
How are you?
Do you know the answer to the ultimate question?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Immediatly after the input has been stoppedt the shell runs the program with what you have typed as the content in &lt;code&gt;stdin&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;&amp;gt;&amp;amp;&lt;/code&gt; and &lt;code&gt;&amp;lt;&amp;amp;&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Those two do not act on files but file descriptors.&lt;/p&gt;

&lt;p&gt;Their left side can be either ignored or be a number (the target fd).&lt;br&gt;
The left side MUST be attached to the operator.&lt;/p&gt;

&lt;p&gt;If I want to redirect &lt;code&gt;stdout&lt;/code&gt; to &lt;code&gt;stderr&lt;/code&gt; I can do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$&amp;gt; cat ft_strdup.c 1&amp;gt;&amp;amp;2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$&amp;gt; cat ft_strdup.c &amp;gt;&amp;amp;2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also use &lt;code&gt;&amp;gt;&amp;amp;&lt;/code&gt; and &lt;code&gt;&amp;lt;&amp;amp;&lt;/code&gt; to close a file descriptor (If you want to ignore error messages, 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;$&amp;gt; find / -name 'lost_file' 2&amp;gt;&amp;amp;- # If you don't want to see messages like 'Permision denied'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The only difference between &lt;code&gt;&amp;gt;&amp;amp;&lt;/code&gt; and &lt;code&gt;&amp;lt;&amp;amp;&lt;/code&gt; is the default file descriptor used in case of a not given left fd.&lt;br&gt;
&lt;code&gt;&amp;gt;&amp;amp;&lt;/code&gt; is for &lt;code&gt;stdout&lt;/code&gt; and &lt;code&gt;&amp;lt;&amp;amp;&lt;/code&gt; is for &lt;code&gt;stdin&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Also, if you put a space between the left side of the operator and the operator itself the shell will think that the left side is actually an argument to pass to the program and will use the default left side fd number.&lt;/p&gt;
&lt;h2&gt;
  
  
  One last thing
&lt;/h2&gt;

&lt;p&gt;Those operators can be used anywhere on the command line&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$&amp;gt; &amp;lt; input_file cat

$&amp;gt; &amp;gt;output_file echo hello world

$&amp;gt; ls 2&amp;gt;&amp;amp;- -R /
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But you should put the them either on the beginning of the command or the ending to avoid confusion.&lt;/p&gt;

&lt;p&gt;I hope this article has been helpful to you. :)&lt;/p&gt;

</description>
      <category>shell</category>
      <category>bash</category>
      <category>sh</category>
    </item>
    <item>
      <title>Generating a parse tree from a shell grammar</title>
      <dc:creator>Oguzhan Yagci</dc:creator>
      <pubDate>Sat, 04 Nov 2017 16:19:02 +0000</pubDate>
      <link>https://dev.to/oyagci/generating-a-parse-tree-from-a-shell-grammar-f1</link>
      <guid>https://dev.to/oyagci/generating-a-parse-tree-from-a-shell-grammar-f1</guid>
      <description>&lt;p&gt;As a student at 42 one of the first projects you have to accomplish by yourself is the reimplementation of a shell. There are many things to do to have a working shell so today I will only focus on the parse tree.&lt;/p&gt;

&lt;p&gt;A parse tree is what represents the syntactic structure of our commands and will allow us to easily perform those commands typed by the user.&lt;/p&gt;

&lt;p&gt;So we want to be able to translate something like this:&lt;br&gt;
&lt;code&gt;ls | cat -e&lt;/code&gt;&lt;br&gt;
Into a shell job that we will be able to execute as a whole command.&lt;/p&gt;

&lt;p&gt;The first step is to transform the text input into &lt;em&gt;tokens&lt;/em&gt;. That way we will have 4 tokens that represents our text input in a more easier way to process.&lt;/p&gt;

&lt;p&gt;Each token has a value (the text input) and a type (if it is an operator or a command argument):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ls -&amp;gt; WORD
| -&amp;gt; PIPE
cat -&amp;gt; WORD
-e -&amp;gt; WORD
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once parsed, we expect to have something that could be rendered 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;              pipe_sequence
              /          \
simple_command      simple_command    
      |              /          \
   cmd_name       cmd_name     cmd_suffix
      |              |             |
     'ls'          'cat'        cmd_word
                                   |
                                 '-e'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the second step is to come up with a grammar. A grammar is a set of rules to be followed by the parser to generate the parse tree.&lt;/p&gt;

&lt;p&gt;This is a simple version of the grammar of &lt;code&gt;sh&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipe_sequence    : simple_command
                 | pipe_sequence '|' simple_command
                 ;
cmd_suffix       : cmd_word
                 | cmd_word cmd_word
                 ;
simple_command   : cmd_name
                 | cmd_name cmd_suffix
                 ;
cmd_name         : WORD                   
                 ;
cmd_word         : WORD
                 ;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What this grammar tells us is that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;code&gt;pipe_sequence&lt;/code&gt; is a &lt;code&gt;simple_command&lt;/code&gt; followed by 0 or more &lt;code&gt;simple_command&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;cmd_suffix&lt;/code&gt; is one or more &lt;code&gt;cmd_word&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;simple_command&lt;/code&gt; is a &lt;code&gt;cmd_name&lt;/code&gt; followed or not by a &lt;code&gt;cmd_suffix&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;cmd_name&lt;/code&gt; or &lt;code&gt;cmd_word&lt;/code&gt; is a WORD token&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each rule will be implemented as a function.&lt;/p&gt;

&lt;p&gt;Let's start with &lt;code&gt;cmd_word&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="cm"&gt;/*
** struct s_parser is a data type containing informations about the current parser
** (like the tokens list)
*/&lt;/span&gt;
&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;s_cmd_word&lt;/span&gt;    &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nf"&gt;cmd_word&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;s_parser&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;s_cmd_word&lt;/span&gt;    &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="cm"&gt;/*
    ** p-&amp;gt;tokens is a linked list containing all the tokens
    ** p-&amp;gt;tokens-&amp;gt;type is an enum corresponding to the token's type
    */&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;tokens&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;type&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;T_WORD&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;malloc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;sizeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;s_cmd_word&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
        &lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;strdup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;tokens&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;tokens&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;next&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;        
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;NULL&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;Really simple so far. If the current token is a &lt;code&gt;WORD&lt;/code&gt; then we return a &lt;code&gt;struct s_cmd_word *&lt;/code&gt; containing the actual data. But if the current token is not a word (it could be an operator) we return &lt;code&gt;NULL&lt;/code&gt;. And we should not forget to advance to the next token once we used it.&lt;/p&gt;

&lt;p&gt;What about &lt;code&gt;pipe_sequence&lt;/code&gt;?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;s_pipe_sequence&lt;/span&gt;    &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nf"&gt;pipe_sequence&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;s_parser&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;s_pipe_sequence&lt;/span&gt;    &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;ps&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;s_simple_command&lt;/span&gt;   &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;sc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;ps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;malloc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;sizeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;s_pipe_sequence&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;simple_command&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="cm"&gt;/* This function pushes a new element into a linked list */&lt;/span&gt;
        &lt;span class="n"&gt;ft_lstpush&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;ps&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;simple_commands&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;tokens&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;type&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;T_PIPE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;tokens&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;tokens&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ps&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;sc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ps&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;free&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ps&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;NULL&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;The other functions should be as easy to write as the above one.&lt;/p&gt;

&lt;p&gt;At the end you should have a parse tree based on the grammar above.&lt;/p&gt;

&lt;p&gt;Of course this is a very simplified version of the actual shell grammar but really this is all it takes to be able to generate by hand a parse tree.&lt;/p&gt;

&lt;p&gt;If you want to implement a shell you should first visit &lt;a href="http://pubs.opengroup.org/onlinepubs/9699919799/"&gt;this website&lt;/a&gt;. It's THE place to read first to understand how a shell like &lt;code&gt;sh&lt;/code&gt; behaves.&lt;/p&gt;

&lt;p&gt;Thanks for reading :)&lt;/p&gt;

</description>
      <category>c</category>
      <category>shell</category>
      <category>ast</category>
      <category>parser</category>
    </item>
  </channel>
</rss>
