assignement word lexing parsing

This commit is contained in:
ariard@student.42.fr 2017-02-24 21:00:38 +01:00
parent a3c750494f
commit f703185a3a
17 changed files with 67 additions and 14 deletions

View file

@ -6,7 +6,7 @@
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
# Updated: 2017/02/24 18:49:55 by ariard ### ########.fr #
# Updated: 2017/02/24 20:51:33 by ariard ### ########.fr #
# #
# **************************************************************************** #
@ -189,6 +189,7 @@ lexer/lexer_lex.c\
lexer/lexer_newline.c\
lexer/lexer_number.c\
lexer/lexer_paren.c\
lexer/lexer_assignement_word.c\
lexer/lexer_quote.c\
lexer/lexer_sep.c\
lexer/lexer_word.c\

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
/* Updated: 2017/02/21 21:12:01 by ariard ### ########.fr */
/* Updated: 2017/02/24 20:45:05 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -40,6 +40,7 @@ enum e_lexstate
DQUOTE_BQUOTE,
BACKSLASH,
PAREN,
ASSIGNEMENT_WORD,
// VAR,
// SPECIAL,
COMMENT,
@ -111,6 +112,7 @@ int lexer_dquote(t_list **alst, t_lexer *lexer);
int lexer_bquote(t_list **alst, t_lexer *lexer);
int lexer_backslash(t_list **alst, t_lexer *lexer);
int lexer_paren(t_list **alst, t_lexer *lexer);
int lexer_assignement_word(t_list **alst, t_lexer *lexer);
int lexer_comment(t_list **alst, t_lexer *lexer);
int lexer_end(t_list **alst, t_lexer *lexer);

View file

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

View file

@ -0,0 +1,4 @@
hello() {
ls | cat
pwd ; cd
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */
/* Updated: 2017/02/20 20:48:53 by ariard ### ########.fr */
/* Updated: 2017/02/24 20:45:37 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -33,6 +33,8 @@ t_lexstate get_state_global(t_lexer *lexer)
return (BQUOTE);
else if (c == '(' || c == ')')
return (PAREN);
else if (c == '=')
return (ASSIGNEMENT_WORD);
else if (c == 0)
return (END);
return (0);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 20:37:28 by jhalford #+# #+# */
/* Updated: 2017/02/09 20:39:11 by jhalford ### ########.fr */
/* Updated: 2017/02/24 20:44:40 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexer_assignement_word.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/24 20:28:13 by ariard #+# #+# */
/* Updated: 2017/02/24 21:00:13 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h"
int lexer_assignement_word(t_list **alst, t_lexer *lexer)
{
t_token *token;
char c;
token = (*alst)->content;
if (token->type != TK_WORD && token->type != TK_ASSIGNEMENT_WORD)
{
token_append(token, lexer, 0, 0);
lexer->pos++;
return (lexer_lex(alst, lexer));
}
token->type = TK_ASSIGNEMENT_WORD;
token_append(token, lexer, 0, 0);
lexer->pos++;
c = lexer->str[lexer->pos];
if ((lexer->state = get_state_global(lexer)))
return (lexer_lex(alst, lexer));
if ((lexer->state = get_state_redir(lexer)))
return (lexer_lex(alst, lexer));
lexer->state = ft_isdigit(c) ? NUMBER : ASSIGNEMENT_WORD;
return(lexer_lex(alst, lexer));
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 18:36:21 by jhalford #+# #+# */
/* Updated: 2017/02/21 22:40:44 by ariard ### ########.fr */
/* Updated: 2017/02/24 20:43:56 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */
/* Updated: 2017/02/21 22:44:37 by ariard ### ########.fr */
/* Updated: 2017/02/24 20:51:04 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -31,6 +31,7 @@ int (*g_lexer[])(t_list **alst, t_lexer *lexer) =
&lexer_bquote,
&lexer_backslash,
&lexer_paren,
&lexer_assignement_word,
&lexer_comment,
&lexer_end,
};

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */
/* Updated: 2017/02/20 20:54:32 by ariard ### ########.fr */
/* Updated: 2017/02/24 21:00:15 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/11 17:18:42 by jhalford #+# #+# */
/* Updated: 2017/02/21 21:34:55 by ariard ### ########.fr */
/* Updated: 2017/02/24 20:33:59 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 18:18:04 by jhalford #+# #+# */
/* Updated: 2017/02/24 19:06:19 by ariard ### ########.fr */
/* Updated: 2017/02/24 20:59:07 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,6 +16,8 @@ char *ft_putast(void *nodein)
{
t_astnode *node;
node = nodein;
if (node->type == TK_ASSIGNEMENT_WORD)
return ("ASSIGNEMENT_WORD");
if (node->type == SUBSHELL)
return ("SUBSHELL");
if (node->type == TK_NAME)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
/* Updated: 2017/02/24 18:39:09 by ariard ### ########.fr */
/* Updated: 2017/02/24 20:58:33 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
/* Updated: 2017/02/24 19:31:18 by ariard ### ########.fr */
/* Updated: 2017/02/24 19:40:07 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 19:12:07 by ariard #+# #+# */
/* Updated: 2017/02/24 18:54:09 by ariard ### ########.fr */
/* Updated: 2017/02/24 19:40:12 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 18:32:59 by ariard #+# #+# */
/* Updated: 2017/02/24 19:27:32 by ariard ### ########.fr */
/* Updated: 2017/02/24 20:59:49 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -38,6 +38,7 @@ t_treematch g_treematch[] =
{TK_PAREN_OPEN, &add_cmd},
{TK_PAREN_CLOSE, &add_cmd},
{TK_FOR, &add_cmd},
{TK_ASSIGNEMENT_WORD, &add_cmd},
{SUBSHELL, &add_cmd},
{0, NULL},
};

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 15:32:10 by ariard #+# #+# */
/* Updated: 2017/02/21 20:39:13 by ariard ### ########.fr */
/* Updated: 2017/02/24 20:57:40 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,6 +14,8 @@
char *read_state(t_sym current)
{
if (current == TK_ASSIGNEMENT_WORD)
return ("TK_ASSIGNEMENT_WORD");
if (current == CASE_CLAUSE)
return ("CASE_CLAUSE");
if (current == CASE_LIST_NS)