%token <str> CONST
%token <str> REGEX
+%token ERR
%token <n> NUM
-%left EQ NEQ GE LE GT LT RE NRE
+%token <str> VAR
+%token KW_IF KW_ELSE KW_PIPE KW_MAIL KW_COPY
+%token '(' ')' '{' '}'
+%left ARROW
+%left EQ NEQ GE LE '<' '>' RE NRE
+%left '+' '-'
+%left '*' '/'
%left '|' '&' '^'
%left '!'
+%left '='
%type <b> boo
%%
| NUM NEQ NUM { $$ = $1 != $3 }
| NUM GE NUM { $$ = $1 >= $3 }
| NUM LE NUM { $$ = $1 <= $3 }
- | NUM GT NUM { $$ = $1 > $3 }
- | NUM LT NUM { $$ = $1 < $3 }
+ | NUM '>' NUM { $$ = $1 > $3 }
+ | NUM '<' NUM { $$ = $1 < $3 }
| boo '|' boo { $$ = $1 || $3 }
| boo '&' boo { $$ = $1 && $3 }
| boo '^' boo { $$ = ($1 || $3) && !($1 && $3) }
return NEQ;
else if (c == '~')
return NRE;
- else
- if (! safe_unget(c))
- return c;
+ else {
+ safe_unget(c);
+ return '!';
+ }
}
if (c == '<'){
if ((c = getchar ()) == '=')
return LE;
- else
- return (safe_unget(c) ? LT : c);
+ else {
+ safe_unget(c);
+ return '<';
+ }
}
if (c == '>'){
if ((c = getchar ()) == '=')
return GE;
- else
- return (safe_unget(c) ? GT : c);
+ else {
+ safe_unget(c);
+ return '>';
+ }
}
if (c == '='){
if ((c = getchar ()) == '=')
return EQ;
- else
- if (! safe_unget(c))
- return c;
+ else {
+ safe_unget(c);
+ return '=';
+ }
}
if (c == '~'){
if ((c = getchar ()) == '~')
return RE;
+ else {
+ safe_unget(c);
+ return ERR;
+ }
+ }
+
+ if (c == '-'){
+ if ((c = getchar ()) == '>')
+ return ARROW;
+ else {
+ safe_unget(c);
+ return '-';
+ }
+ }
+
+ if (c == '$'){
+ int i=0;
+
+ if (!(yylval.str=malloc(BUFSIZE))){
+ puts("Low memory");
+ exit (0);
+ }
+
+ while (isalnum(c = getchar()) || c == '_' || c == '-'){
+ yylval.str[i]=c;
+ i++;
+ if (i >= BUFSIZE)
+ break;
+ }
+
+ return VAR;
+ }
+
+ if (c == '\n' || c == '+' || c == '*' || c == '/' ||
+ c == '(' || c == ')' || c == '{' || c == '}')
+ return c;
+
+#define KLEN 10
+
+ if (isalpha(c)){
+ char buf[KLEN];
+ int i=0;
+
+ ungetc(c,stdin);
+ while (isalpha(c = getchar()) && i<KLEN-1)
+ buf[i++]=c;
+ buf[i]=0;
+
+ if (!strcmp(buf,"if"))
+ return KW_IF;
+ else if (!strcmp(buf,"else"))
+ return KW_ELSE;
+ else if (!strcmp(buf,"pipe"))
+ return KW_COPY;
+ else if (!strcmp(buf,"mail"))
+ return KW_MAIL;
+ else if (!strcmp(buf,"copy"))
+ return KW_COPY;
else
- if (! safe_unget(c))
- return c;
+ return ERR;
}
if (c == EOF)
return 0;
- return c;
+ return ERR;
}
void
int
main(void)
{
+// yydebug=1;
return yyparse ();
}