aboutsummaryrefslogtreecommitdiffstats
path: root/syntax.y
diff options
context:
space:
mode:
authorWe-unite <3205135446@qq.com>2024-06-07 15:24:12 +0800
committerWe-unite <3205135446@qq.com>2024-06-25 22:39:18 +0800
commit6151327eb4456e82047b93fab2f9defdec0b36ad (patch)
treeb8195e13f119f2962d43250f257ea2713edfb736 /syntax.y
parent1b5748544f06d8bbcab8f1b12ac9ea65a53f154e (diff)
downloadbcsh-master.tar.gz
bcsh-master.zip
Add STR type and can "<params>" now.HEADmaster
In bash, we can use args with space in it by quote the arg itself, like `grep "test C"` or `cd "dir 1"`. I make it. Add a STR type in flex, and deal with it specially while append it as an argument (malloc a new str space, copy the content of STR into it, then free the STR string, add the new str as an argument).
Diffstat (limited to 'syntax.y')
-rw-r--r--syntax.y20
1 files changed, 12 insertions, 8 deletions
diff --git a/syntax.y b/syntax.y
index a53537a..7f6745e 100644
--- a/syntax.y
+++ b/syntax.y
@@ -2,6 +2,7 @@
2#include "cmd.h" 2#include "cmd.h"
3#include "lex.yy.c" 3#include "lex.yy.c"
4#include <stdio.h> 4#include <stdio.h>
5
5%} 6%}
6 7
7%union { 8%union {
@@ -65,16 +66,19 @@ separator:
65part: 66part:
66 part WORD { 67 part WORD {
67 $$ = $1; 68 $$ = $1;
68 $$->argc++; 69 argInsert($$, $2, false);
69 $$->args = realloc($$->args, ($$->argc + 1) * sizeof(char *));
70 $$->args[$$->argc - 1] = $2;
71 $$->args[$$->argc] = NULL;
72 } 70 }
73 | WORD { 71 | WORD {
74 $$ = newCmd(); 72 $$ = newCmd();
75 $$->args = malloc(2 * sizeof(char *)); 73 argInsert($$, $1, false);
76 $$->args[$$->argc++] = $1; 74 }
77 $$->args[$$->argc] = NULL; 75 | part STRING {
76 $$ = $1;
77 argInsert($$, $2, true);
78 }
79 | STRING {
80 $$ = newCmd();
81 argInsert($$, $1, true);
78 } 82 }
79 | part REDIRECT_IN WORD { 83 | part REDIRECT_IN WORD {
80 $$ = $1; 84 $$ = $1;
@@ -99,4 +103,4 @@ part:
99 } 103 }
100 ; 104 ;
101 105
102%% 106%% \ No newline at end of file