struct tree* tr;
}
+%right <n> '!'
%token <str> CONST
%token <n> NUM
%token <str> VAR
-%token <str> KW_DISCARD
-%token <str> KW_PIPE KW_MAIL KW_COPY
+%token <n> KW_DISCARD
+%token <n> KW_PIPE KW_MAIL KW_COPY
%token '(' ')' '{' '}' ';'
%nonassoc KW_IF
%nonassoc KW_ELSE
%left ARROW
%left <n> EQ NEQ GE LE '<' '>' RE NRE
-%left '='
-%left '.'
-%left '+' '-'
-%left '*' '/'
+%left <n> '='
+%left <n> '.'
+%left <n> '+' '-'
+%left <n> '*' '/'
%left <n> '|'
%left <n> '^'
%left <n> '&'
-%left <n> '!'
%type <tr> input
%type <tr> command
%type <tr> next
%type <tr> ass
%type <tr> ass_right
+%type <tr> ass_right_p
%type <tr> cif
%type <tr> arrow
%type <tr> cond
%type <n> rop
-%type <str> left
-%type <str> right
+%type <n> left
+%type <n> right
%type <tr> leaves
%%
$$->pt.cond.op = $2;
$$->pt.cond.type = OP_REL;
}
+ | ass_right {
+ $$ = tree_malloc(ST_COND);
+ $$->pt.cond.left = $1;
+ $$->pt.cond.type = JUST_BOOL;
+ }
;
rop: '>'
;
ass:
- VAR '=' ass_right {
+ VAR '=' ass_right_p {
$$ = tree_malloc(ST_ASS);
$$->pt.ass.left = tree_malloc(ST_LEAF);
arrow: left ARROW right ass_right {
$$ = tree_malloc(ST_ARROW);
$$->pt.arrow.s = $4;
- $$->pt.arrow.kw_left = $1;
- $$->pt.arrow.kw_right = $3;
+ $$->pt.arrow.left = $1;
+ $$->pt.arrow.right = $3;
}
| left ARROW KW_DISCARD { //FIXME: actually left does not make sense here
$$ = tree_malloc(ST_ARROW);
$$->pt.arrow.s = NULL;
- $$->pt.arrow.kw_left = NULL;
- $$->pt.arrow.kw_right = "discard";
+ $$->pt.arrow.left = K_EMPTY;
+ $$->pt.arrow.right = K_DISCARD;
}
;
-left: /* empty */ { $$ = NULL;}
- | KW_COPY { $$ = "copy"; }
+left: /* empty */ { $$ = K_EMPTY;}
+ | KW_COPY { $$ = K_COPY; }
;
-right: /* empty */ { $$ = NULL; }
- | KW_PIPE { $$ = "pipe"; }
- | KW_MAIL { $$ = "mail"; }
+right: /* empty */ { $$ = K_EMPTY; }
+ | KW_PIPE { $$ = K_PIPE; }
+ | KW_MAIL { $$ = K_MAIL; }
+;
+
+ass_right_p: '(' ass_right ')' {$$ = $2; }
+ | ass_right {$$ = $1; }
;
ass_right: leaves
| ass_right '.' ass_right {
$$ = tree_malloc(ST_OP);
- $$->pt.op.op = '.';
+ $$->pt.op.op = $2;
+ $$->pt.op.left = $1;
+ $$->pt.op.right = $3;
+ }
+ | ass_right '+' ass_right {
+ $$ = tree_malloc(ST_OP);
+ $$->pt.op.op = $2;
+ $$->pt.op.left = $1;
+ $$->pt.op.right = $3;
+ }
+ | ass_right '-' ass_right {
+ $$ = tree_malloc(ST_OP);
+ $$->pt.op.op = $2;
+ $$->pt.op.left = $1;
+ $$->pt.op.right = $3;
+ }
+ | ass_right '*' ass_right {
+ $$ = tree_malloc(ST_OP);
+ $$->pt.op.op = $2;
+ $$->pt.op.left = $1;
+ $$->pt.op.right = $3;
+ }
+ | ass_right '/' ass_right {
+ $$ = tree_malloc(ST_OP);
+ $$->pt.op.op = $2;
$$->pt.op.left = $1;
$$->pt.op.right = $3;
}