blob: 74604e55302b447670661b3c200dd4042bd93f9a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ms_parse.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/28 09:00:00 by cacharle #+# #+# */
/* Updated: 2020/02/28 14:57:58 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MS_PARSE_H
# define MS_PARSE_H
# include "minishell.h"
/*
** Context free grammar:
**
** redir_in ::= '<' <string>
** redir_out ::= '>' <string>
** redir_append ::= '>>' <string>
** string ::= '\'' .+ '\'' | '"' .+ '"' | [^ ]+
** sep ::= '&&' | '||' | '|' | ';'
** expr ::= <redir_in> | <redir_out> | <redir_append> | <string>
** sexpr ::= <expr>+
** line ::= <sexpr> <sep> <line> | <sexpr>
*/
/*
** TAG_CMD: command name
** TAG_ARG: command argument
** TAG_ENDCMD: `;`
** TAG_PIPE: `|`
** TAG_AND: `&&`
** TAG_OR: `||`
** TAG_REDIR_OUT: `>`
** TAG_REDIR_IN: `<`
** TAG_REDIR_APPEND: `>>`
*/
typedef enum
{
TAG_CMD,
TAG_ARG,
TAG_ENDCMD,
TAG_PIPE,
TAG_AND,
TAG_OR,
TAG_REDIR_OUT,
TAG_REDIR_IN,
TAG_REDIR_APPEND
} t_tag;
/*
** AST (Abstract Syntax Tree)
** A node of the ast is represented by a tag (his type) and a content associated with it.
** (i.e a TAG_CMD would be paired with the command executable name)
** Each node also has children node which must be evaluated before him
**
** examle: "echo foo bar && ls"
**
** tags:
** TAG_AND
** / \
** / \
** TAG_CMD TAG_CMD
** / \
** TAG_ARG TAG_ARG
**
** content:
** &&
** / \
** / \
** echo ls
** / \
** foo bar
*/
typedef struct s_ast
{
t_tag tag;
char* content;
int children_num;
struct s_ast** children;
} t_ast;
char **ms_lexer(char *input);
/*
** parse.c
*/
t_ast *ms_parse(char *input);
#endif
|