-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.l
62 lines (42 loc) · 785 Bytes
/
shell.l
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
%{
#include "shell.tab.h"
#define MAX 255
extern int yylval;
int n = 0;
char * expresion[ MAX ];
char cmd[ MAX ];
void a_Buffer( char * str )
{
expresion[ n ] = ( char * ) malloc( strlen( str ) + 1 );
strcpy( expresion[ n++ ], str );
}
%}
%s comando
%%
[ \t] ;
\n { return SALTO_DE_LINEA; }
"<" { return ENTRADA; }
">" { return SALIDA; }
">>" { return APPEND; }
& { return BACKGROUND; }
"|" { return TUBERIA; }
<comando>"\""
{
BEGIN(INITIAL);
return COMANDO;
}
<comando>[^\"]* {
cmd[ 0 ] = '\0';
strcat( cmd, yytext );
a_Buffer( cmd );
}
"\"" BEGIN(comando);
"$"[^&">""<"" ""|"\n]+ {
a_Buffer( getenv( yytext + 1 ) );
return COMANDO;
}
[^&">""<"" ""|"\n]+ {
a_Buffer( yytext );
return COMANDO;
}
%%