Please enable JavaScript.
Coggle requires JavaScript to display documents.
42sh - Coggle Diagram
42sh
Features
Week 2
Redirections
Implement the execution of redirections as described in the SCL
Must work correctly with any command
Pipeline
Implement pipelines as specified by the SCL
Exit status of the pipeline = exit status of the last command
Negation
! reverses the exit status of the pipeline (even if there’s no pipe)
Parser / Lexer
Handle ! in your lexer
Add a new AST node type
Parse and execute it
“While” and “until” commands
Implement the execution of while and until loops, as specified by the SCL
“For” commands
Implement the execution of for loops, as specified by the SCL
Operators
Implement the execution of the “&&” and “||” operators, as specified by the SCL
Double Quotes and Escape Character
Implement the lexing and expansion of double quotes and escape characters, as described in the SCL
Make sure expansion algorithm == lexing algorithm.
Variables
Implement Variable assignment & simple variable subsitutions, as described by the SCL
O
Only the
$name
and
${name}
formats will be
tested
Week 1
Lexer
Build list of tokens
Give it to parser
Lex only : if, then, elif, else, fi, ;, \n, ', words
Parser
Build the AST
Syntaxic analisys
AST evaluation
Pretty print
Print AST
Useful for debugging
--pretty-print
Options parser
42sh [OPTIONS] [SCRIPT] [ARGUMENTS ...]
use of getopt_long
-c [SCRIPT]
directly interpret the argument as a shell
script
Commands
If
The lexer must recognize if, then, elif and else as special token types
Echo
Prints its arguments separated by spaces, and prints a final newline
Does not have to comply with POSIX
-n inhibits printing a newline
-e interprets the \n, \t and \ escapes
Single quote
' '
Preserve the literal value of each character
Week 3
Built-in commands
exit
All resources should be released
cd
Do not have to implement the -L and -P options
Does not have to follow the
required behavior for the CDPATH variable
Update the PWD and OLDPWD environment variables
export
Only the export NAME=VALUE & export NAME will be tested
continue
break
dot
unset
Command blocks
Explicit way to create command lists
Functions
Implement function definition and execution
Command Substitution
Implement command substitution as described by the SCL.
Subshell
Run commands in a new process
Week 4
“Case” commands
Implement the case construct as specified by the SCL
Aliases
Require
Implementing the alias and unalias builtins, also to SCL specification (for alias and for unalias)
Using the alias list for substitutions inside the lexer
Substitutions are performed at the token level
Don’t have to follow the behavior specified in the SCL when the alias ends with trailing spaces.
Field Splitting
Implement Field spliting as specified by the SCL.
Tests
Testsuite
Implements all the needed functions to really test your program
Prevents regressions
Test program
Group tests into categories
Issue only one line per test
Understand the result of the test
Display the global result of tests
Tests format
Test description
Input
Options format
-l and --list: Display the list of test categories
-c <category> and --category <category>: Execute the test suite on the categories passed in argument only.
-s and --sanity: Execute the test suite with sanity checks enabled, e.g. valgrind. Any reported error must make the test fail.
Timeout management
Prerequesites
Data structures
Lexer
List of tokens
Struct token
enum my_token
struct token *next
struct list
union value
enum my_token
Struct list *list
enum option
char *name
struct list *next
Parser
enum my_token
builtin
enum option
Repo structure
/
meson.build
meson_build.txt
src
headers
analysis
parser
lexer
ast_evaluation
utils
environment
variables
operators
io
builtins
tests
README
Tests
Testsuite
Implements all the needed functions to really test your program
Prevents regressions
Test program
Group tests into categories
Issue only one line per test
Understand the result of the test
Display the global result of tests
Tests format
Test description
Input
Options format
-l and --list: Display the list of test categories
-c <category> and --category <category>: Execute the test suite on the categories passed in argument only.
-s and --sanity: Execute the test suite with sanity checks enabled, e.g. valgrind. Any reported error must make the test fail.
Timeout management
Bonus
Additional Features
Tilde expansion
Path expansion
Arithmetic expansion
Here-Document
Going further (Require additional features)
Prompt
Job Control