Skip to content

Latest commit

 

History

History
123 lines (100 loc) · 3.69 KB

File metadata and controls

123 lines (100 loc) · 3.69 KB

Resources

1. Lex

To create the shell, first we'll have to use a technique called lexical analysis which is the process of taking the raw input string "ls -l /home" and breaking it down into these meaningful (token-type, token-value) pairs.

Each of these pairs (COMMAND, "ls"), (OPTION, "-l"), and (PATH, "/home") – is a lexical token.

Lexical analysis: breaking the input into individual words or “tokens”; Syntax analysis: parsing the phrase structure of the program; Semantic analysis: calculating the inputl;

TOKENS

BUILIN
COMMAND
PATH
REDIRECTION
PIPELINE
SQSTR
DQSTR
cat << EOF > file | wc -c | tr -d " " > file2
                         __ PIPELINE__
                     ___/              \____
                    /                       \
            COMMAND                    __ PIPELINE _
          /        \                  /             \
    ARGUMENTS   REDIRECTIONS      COMMAND         _ COMMAND __
        |          |     |           |           /            \
       cat        <<     >       ARGUMENTS    ARGUMENTS   REDIRECTIONS
                   |     |         |   |      |   |   |        |
                 "..."  file      wc  -c      tr  -d " "       >
                                                               |
                                                             file2

Symbol table

lexem Token class
| PIPE
>>, <<,>.< REDIRECTION
"Testing" SINGLE_QUOTE_STR
testing DOUBLE_QUOTE_STR
echo,cd,pwd,export,unset,env,exit KEYWORD
word abcdef

quote

$ echo testing > b is everything > c
$ cat b
testing is everything
$ cat c
testing is everything
|
||
&&
>> 
>
<
<<
"xxxx"
'xxxxx'
$xxxx
$?
echo
cd
pwd
export
unset
env
exit
*
commandline ::= (empty)
          |  conditional
          |  conditional ";" commandline
          |  conditional "&" commandline

conditional ::=  pipeline
          |   conditional "&&" pipeline
          |   conditional "||" pipeline

pipeline ::=  command
          |   pipeline "|" command

command  ::=  word
          |   redirection
          |   command word
          |   command redirection

redirection  ::=  redirectionop filename
redirectionop  ::=  "<"  |  ">"  |  ">>" | "<<"