A demanding project at 42 School that, once completed, marks a significant improvement in programming skills. The premise is rather simple, create a program that recreates a shell, including its most commonly used features such as pipes, redirections, signals and built-ins using exclusively C language.
This project takes a closer look at the functioning of the commands and interface we use everyday to move ourselves through the computer.
The work was divided into two main components: the lexer and the parser. The lexer is responsible for analyzing and validating the input provided by the user or from a file descriptor. It detects syntax errors, such as incorrect use of quotes (" or ') or other special symbols, and tokenizes the input into structured elementsβtypically separating the command from its arguments and redirections. This organization allows the parser to efficiently interpret and execute the commands, without worrying about low-level input validation.
Input: echo "Hello $USER" > greeting.txt
β
βΌ
βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ
β Lexer β --> β Parser β --> β Executor β β Output β
β---------------β β---------------β β---------------β β---------------β
β - Tokenize β β - Validate β β - Run command β β greeting.txt β
β - Detect "" β β - Expand vars β β - Builtin β β contains: β
β - Separate β β - Redirectionsβ β - Redirect > β β "Hello <USER>"β
βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ
