This commit is contained in:
Jack Halford 2017-03-27 18:09:25 +02:00
commit b013ffedbf
47 changed files with 243 additions and 166 deletions

View file

@ -6,7 +6,7 @@
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ # # By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2016/08/29 21:32:58 by wescande #+# #+# # # Created: 2016/08/29 21:32:58 by wescande #+# #+# #
# Updated: 2017/03/27 17:02:38 by gwojda ### ########.fr # # Updated: 2017/03/27 18:08:05 by ariard ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #

2
42sh/sample/again.sh Normal file
View file

@ -0,0 +1,2 @@
echo "echo hello" >> sample/again.sh
echo hello

8
42sh/sample/andor.sh Normal file
View file

@ -0,0 +1,8 @@
pwd > file && pwd >> file || ls | cat && ls | cat >> file || ls
cat -e file
sleep 2
echo "My sample :"
echo
cat sample/andor.sh

View file

@ -1 +0,0 @@
{ ls | cat }

9
42sh/sample/brace.sh Normal file
View file

@ -0,0 +1,9 @@
{ ls ; pwd } > file
cat -e file
sleep 2
echo
echo "My sample :"
sleep 2
echo
cat sample/brace.sh

View file

@ -1,8 +1,16 @@
case van in case toto in
( "bus" ) echo Hello world ;; ( tutu ) echo PERDU ;;
( "velo" ) echo Comment va ;; ( titi ) echo PERDU ;;
( "van" ) case tutu in ( toto ) case lala in
( toto ) pwd ;; ( lolo ) echo PERDU ;;
( tutu ) ls ;; ( lala ) echo GAGNE ;;
esac ;; esac ;;
esac esac > file
cat -e file
sleep 2
echo
echo "My sample :"
sleep 2
echo
cat sample/case.sh

View file

@ -1,2 +1,9 @@
ls # Da comment ls # Da comment
pwd pwd
sleep 2
echo
echo "My sample :"
sleep 2
echo
cat sample/comment.sh

3
42sh/sample/eof.sh Normal file
View file

@ -0,0 +1,3 @@
while [ 1 ]
do
ls

View file

@ -1,4 +1,13 @@
for i in hello bonjour salut comment for i in src/*/*.c
do do
echo $i | cat -e echo $i | cat -e > file
cat -e file >> another_file
cat -e another_file
done done
sleep 2
echo
echo "My sample :"
sleep 2
echo
cat sample/for.sh

View file

@ -1,5 +1,14 @@
hello() ( hello() (
echo HELLO hello() (
echo hello ; hello )
hello
) )
hello hello
sleep 2
echo
echo "My sample :"
sleep 2
echo
cat sample/func.sh

View file

@ -1,9 +1,25 @@
if cat wef4eeef if false
then then
echo Conditon 1 echo PERDU
elif cat yulu elif false
then then
echo Condition 2 echo PERDU
elif true
then
if false
then
echo PERDU
elif
echo GAGNE
fi > file
else else
echo Condition 3 echo PERDU
fi fi
cat -e file
sleep 2
echo
echo "My sample :"
sleep 2
echo
cat sample/if.sh

View file

@ -1,10 +0,0 @@
if ls ;
then
pwd
elif ls
then
pwd
elif ls
then
pwd
fi

View file

@ -1,5 +0,0 @@
if cat yolo ;
then
pwd
else ls
fi

View file

@ -1,11 +0,0 @@
if cat yolo ;
then
pwd
elif ls
then
pwd
elif pwd
then
ls
else ls
fi

View file

@ -1,2 +0,0 @@
echo "echo hello" >> sample/infinite.sh
echo hello

View file

@ -1 +0,0 @@
ls

30
42sh/sample/mix.sh Normal file
View file

@ -0,0 +1,30 @@
VAR=10
if true
then
echo "Salut" ; echo "Correcteur"
while [ $VAR -gt 0 ]
do
until true
do
echo KO SI JE M AFFICHE
done
if true
then
echo OK SI JE M AFFICHE
elif [ -f Makefile ]
then
echo KO SI JE M AFFICHE
else
echo KO SI JE M AFFICHE
fi
echo "Encore un tour"
math VAR - 1
done
fi
sleep 2
echo
echo "My sample :"
sleep 3
echo
cat sample/mix/mix.sh

View file

@ -1,21 +0,0 @@
if ls
then
pwd ; echo "Salut"
while ls
do
until pwd
do
echo KO SI JE M AFFICHE
done
if cat faux
then
echo BONJOUR MAKEFILE
elif [ -f Makefile ]
then
echo BONJOUR MAKEFILE
else
echo KO SI JE M M AFFICHE
fi
echo "Encore une"
done
fi

31
42sh/sample/muchloop.sh Normal file
View file

@ -0,0 +1,31 @@
while [ 1 ]
do
while [ 1 ]
do
while [ 1 ]
do
while [ 1 ]
do
while [ 1 ]
do
while [ 1 ]
do
while [ 1 ]
do
while [ 1 ]
do
while [ 1 ]
do
while [ 1 ]
do
echo "SO MUCH LOOOOP"
done
done
done
done
done
done
done
done
done
done

View file

@ -1,3 +0,0 @@
cat < file1 < file2 > file3 > file4

View file

@ -1 +0,0 @@

16
42sh/sample/script.sh Normal file
View file

@ -0,0 +1,16 @@
clear
YES=y
NO=n
echo "Welcome in 42Zash, new corrector, what is your login ?"
until [ $REP == $YES ]
do
read -p "> " LOGIN
echo
read -p "Ok, fine, your login is $LOGIN, right ?(y/n) " REP
if [ $REP = $NO ]
then
echo
echo "Don't worry let's do it again"
fi
done

View file

@ -1,3 +0,0 @@
cat && ls || ls | cat && ls | cat || ls

View file

@ -8,3 +8,10 @@ echo aaa \
| (echo bbb 7; cat -e ;echo ccc 7) \ | (echo bbb 7; cat -e ;echo ccc 7) \
| (echo bbb 8; cat -e ;echo ccc 8) \ | (echo bbb 8; cat -e ;echo ccc 8) \
| (echo bbb 9; cat -e ;echo ccc 9) | (echo bbb 9; cat -e ;echo ccc 9)
sleep 2
echo "My sample :"
echo
sleep 2
cat sample/subshell.sh

View file

@ -1,2 +0,0 @@
(ls | cat
pwd ; ls)

View file

@ -0,0 +1,4 @@
while [ 1 ]
do
ls
done done

View file

@ -1,8 +1,30 @@
until [ 1 ] VAR1=0
until [ $VAR1 -gt 10 ]
do do
echo LOOP1 VAR2=0
until [ 1 ] until [ $VAR2 -gt 10 ]
do do
echo hello VAR3=0
until [ $VAR3 -gt 10 ]
do
math VAR3 + 1
echo "3rd is $VAR3"
done done
done > file1 math VAR2 + 1
echo "2nd is $VAR2"
done
math VAR1 + 1
echo "1st is $VAR1"
sleep 1
done
echo
echo "VAR1: $VAR1"
echo "VAR2: $VAR2"
echo "VAR3: $VAR3"
sleep 2
echo
echo "My sample :"
sleep 2
echo
cat sample/until.sh

View file

@ -1,11 +0,0 @@
until cat wefwef
do
until ls
do
pwd ; ls
done
until cat eqwfewf
do
ls | cat
done
done

View file

@ -1,11 +0,0 @@
ONE=0
while [ $ONE -le 10 ]
do
TWO=0
while [ $TWO -le 10 ]
do
echo world
math TWO + 1;
done
math ONE + 1;
done > file1

11
42sh/sample/var.sh Normal file
View file

@ -0,0 +1,11 @@
HELLO=WORLD HELLO=SALUT HELLO="BUENOS DIAS"
echo $HELLO
SALUT=$HELLO
echo $SALUT
sleep 2
echo
echo "My sample :"
sleep 2
echo
cat sample/var.sh

View file

@ -1 +0,0 @@
HELLO=WORLD

View file

@ -1,12 +1,24 @@
VAR=10
while while
while while [ $VAR -gt 0 ]
while ls | cat
do do
ls echo "Inside inner loop" | cat -e
math VAR - 1
done done
if [ $VAR -eq -42 ]
then
false
else
true
fi
do do
ls | cat echo "I'm the execution block"
done VAR=-42
do
pwd
done done
sleep 2
echo
echo "My sample :"
sleep 3
echo
cat sample/while.sh

View file

@ -1,11 +0,0 @@
while ls
do
while cat rwgwghe
do
echo Hello World
done
while pwd
do
echo Bonjour ca va
done
done

View file

@ -1,5 +0,0 @@
ls
while [ 1 ] ;
do
ls | cat
done

View file

@ -1,5 +0,0 @@
ls
for HELLLO in yolo ;
do
ls
done > file1

View file

@ -1,16 +0,0 @@
ONE=11
while [ $ONE -gt 1 ]
do
TWO=11
while [ $TWO -gt 1 ]
do
THREE=11
while [ $THREE -gt 1 ]
do
echo hello
((THREE--))
done
((TWO--))
done
((ONE--))
done > file1

View file

@ -1,6 +0,0 @@
echo hello
while ||
do
pwd ;
done
ls | cat

View file

@ -1 +0,0 @@
< A B | ( C 2> D & E < F ) > G ; H=I J K

View file

@ -1 +0,0 @@
< A B | C | D | E > F

View file

@ -1 +0,0 @@
A && B || C && D

View file

@ -1 +0,0 @@
A ; B & C ; D || E

View file

@ -1 +0,0 @@
(A ; B &) | (C || D) && E

View file

@ -1 +0,0 @@

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */ /* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */
/* Updated: 2017/03/27 15:58:12 by jhalford ### ########.fr */ /* Updated: 2017/03/27 18:08:20 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -46,6 +46,7 @@ static int handle_instruction(t_list **token, t_btree **ast)
return (ret); return (ret);
if (do_lexer_routine(token, stream) > 0) if (do_lexer_routine(token, stream) > 0)
continue ; continue ;
token_print(*token);
if ((ret = do_parser_routine(token, ast)) == 1 if ((ret = do_parser_routine(token, ast)) == 1
&& SH_NO_INTERACTIVE(data->opts)) && SH_NO_INTERACTIVE(data->opts))
return (ret); return (ret);

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/11 15:58:38 by ariard #+# #+# */ /* Created: 2017/03/11 15:58:38 by ariard #+# #+# */
/* Updated: 2017/03/24 23:26:22 by ariard ### ########.fr */ /* Updated: 2017/03/27 17:23:36 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -89,6 +89,7 @@ static t_aggrematch g_aggrematch[] =
{NEWLINE_LIST, TK_ELIF, TK_ELIF, TK_ELIF}, {NEWLINE_LIST, TK_ELIF, TK_ELIF, TK_ELIF},
{NEWLINE_LIST, TK_ELSE, TK_ELSE, TK_ELSE}, {NEWLINE_LIST, TK_ELSE, TK_ELSE, TK_ELSE},
{NEWLINE_LIST, TK_WHILE, TK_WHILE, TK_WHILE}, {NEWLINE_LIST, TK_WHILE, TK_WHILE, TK_WHILE},
{NEWLINE_LIST, LOOP, LOOP, LOOP},
{NEWLINE_LIST, TK_LBRACE, TK_LBRACE, TK_LBRACE}, {NEWLINE_LIST, TK_LBRACE, TK_LBRACE, TK_LBRACE},
{NEWLINE_LIST, TK_UNTIL, TK_UNTIL, TK_UNTIL}, {NEWLINE_LIST, TK_UNTIL, TK_UNTIL, TK_UNTIL},
{NEWLINE_LIST, CASE_LIST_NS, CASE_LIST_NS, CASE_LIST_NS}, {NEWLINE_LIST, CASE_LIST_NS, CASE_LIST_NS, CASE_LIST_NS},
@ -148,6 +149,7 @@ static t_aggrematch g_aggrematch[] =
{CMD_SUFFIX, CMD_WORD, SIMPLE_COMMAND, CMD_PREFIX}, {CMD_SUFFIX, CMD_WORD, SIMPLE_COMMAND, CMD_PREFIX},
{CMD_SUFFIX, CMD_NAME, SIMPLE_COMMAND, CMD_NAME}, {CMD_SUFFIX, CMD_NAME, SIMPLE_COMMAND, CMD_NAME},
{CMD_SUFFIX, CMD_SUPERIOR, CMD_SUPERIOR, CMD_SUPERIOR}, {CMD_SUFFIX, CMD_SUPERIOR, CMD_SUPERIOR, CMD_SUPERIOR},
{CMD_SUFFIX, COMPOUND_LIST, COMPOUND_LIST, COMPOUND_LIST},
{CMD_SUFFIX, PIPE_SEMI_SEQUENCE, PIPE_SEMI_SEQUENCE, PIPE_SEMI_SEQUENCE}, {CMD_SUFFIX, PIPE_SEMI_SEQUENCE, PIPE_SEMI_SEQUENCE, PIPE_SEMI_SEQUENCE},
{CMD_SUFFIX, PIPE_CLOSE_SEQUENCE, PIPE_CLOSE_SEQUENCE, PIPE_CLOSE_SEQUENCE}, {CMD_SUFFIX, PIPE_CLOSE_SEQUENCE, PIPE_CLOSE_SEQUENCE, PIPE_CLOSE_SEQUENCE},
{CMD_PREFIX, LINEBREAK, SIMPLE_COMMAND, 0}, {CMD_PREFIX, LINEBREAK, SIMPLE_COMMAND, 0},

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/11 16:11:21 by ariard #+# #+# */ /* Created: 2017/03/11 16:11:21 by ariard #+# #+# */
/* Updated: 2017/03/24 23:26:06 by ariard ### ########.fr */ /* Updated: 2017/03/27 17:29:01 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -605,6 +605,7 @@ static t_stackmatch g_stackmatch[] =
{NEWLINE_LIST, FOR_WORDLIST}, {NEWLINE_LIST, FOR_WORDLIST},
{NEWLINE_LIST, TK_IN}, {NEWLINE_LIST, TK_IN},
{NEWLINE_LIST, TK_WHILE}, {NEWLINE_LIST, TK_WHILE},
{NEWLINE_LIST, LOOP},
{NEWLINE_LIST, FUNC_NAME}, {NEWLINE_LIST, FUNC_NAME},
{NEWLINE_LIST, TK_UNTIL}, {NEWLINE_LIST, TK_UNTIL},
{NEWLINE_LIST, TK_IF}, {NEWLINE_LIST, TK_IF},

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 17:58:34 by ariard #+# #+# */ /* Created: 2017/02/09 17:58:34 by ariard #+# #+# */
/* Updated: 2017/03/23 16:47:59 by ariard ### ########.fr */ /* Updated: 2017/03/27 17:22:10 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -71,7 +71,7 @@ static t_prodmatch g_prodmatch[] =
{TK_ASSIGNMENT_WORD, NEWLINE_LIST, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, NEWLINE_LIST, CMD_PREFIX},
{TK_ASSIGNMENT_WORD, CMD_NAME, CMD_SUFFIX}, {TK_ASSIGNMENT_WORD, CMD_NAME, CMD_SUFFIX},
{TK_ASSIGNMENT_WORD, CMD_SUPERIOR, CMD_SUFFIX}, {TK_ASSIGNMENT_WORD, CMD_SUPERIOR, CMD_SUFFIX},
{TK_ASSIGNMENT_WORD, COMPOUND_LIST, CMD_SUFFIX}, {TK_ASSIGNMENT_WORD, COMPOUND_LIST, CMD_PREFIX},
{TK_ASSIGNMENT_WORD, COMPLETE_CONDITION, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, COMPLETE_CONDITION, CMD_PREFIX},
{TK_ASSIGNMENT_WORD, CONDITION, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, CONDITION, CMD_PREFIX},
{TK_ASSIGNMENT_WORD, AND_OR, CMD_PREFIX}, {TK_ASSIGNMENT_WORD, AND_OR, CMD_PREFIX},
@ -94,6 +94,7 @@ static t_prodmatch g_prodmatch[] =
{TK_NEWLINE, TK_RBRACE, CMD_NAME}, {TK_NEWLINE, TK_RBRACE, CMD_NAME},
{TK_NEWLINE, TK_IN, NEWLINE_LIST}, {TK_NEWLINE, TK_IN, NEWLINE_LIST},
{TK_NEWLINE, TK_WHILE, NEWLINE_LIST}, {TK_NEWLINE, TK_WHILE, NEWLINE_LIST},
{TK_NEWLINE, LOOP, NEWLINE_LIST},
{TK_NEWLINE, TK_UNTIL, NEWLINE_LIST}, {TK_NEWLINE, TK_UNTIL, NEWLINE_LIST},
{TK_NEWLINE, TK_FOR, NEWLINE_LIST}, {TK_NEWLINE, TK_FOR, NEWLINE_LIST},
{TK_NEWLINE, TK_IF, NEWLINE_LIST}, {TK_NEWLINE, TK_IF, NEWLINE_LIST},