-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.c
More file actions
42 lines (33 loc) · 825 Bytes
/
parser.c
File metadata and controls
42 lines (33 loc) · 825 Bytes
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
#include <unistd.h>
#include "shell.h"
#include "parser.h"
#include "scanner.h"
#include "node.h"
#include "source.h"
struct node_s *parse_simple_command(struct token_s *tok) {
if(!tok) {
return NULL;
}
struct node_s *cmd = new_node(NODE_COMMAND);
if(!cmd) {
free_token(tok);
return NULL;
}
struct source_s *src = tok->src;
do {
if(tok->text[0] == '\n') {
free_token(tok);
break;
}
struct node_s *word = new_node(NODE_VAR);
if(!word) {
free_node_tree(cmd);
free_token(tok);
return NULL;
}
set_node_val_str(word, tok->text);
add_child_node(cmd, word);
free_token(tok);
} while((tok = tokenize(src)) != &eof_token);
return cmd;
}