1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2024-06-26 06:29:28 +00:00

Make sure ternary op has lower precedence than AND and OR

This commit is contained in:
David Schmenk 2020-01-20 11:39:58 -08:00
parent e0d688a45a
commit 1a208ef30a
2 changed files with 29 additions and 10 deletions

View File

@ -685,7 +685,7 @@ t_opseq *parse_value(t_opseq *codeseq, int rvalue, int *stackdepth)
}
return (cat_seq(codeseq, valseq));
}
t_opseq *parse_expr(t_opseq *codeseq, int *stackdepth)
t_opseq *parse_subexpr(t_opseq *codeseq, int *stackdepth)
{
int prevmatch;
int matchop = 0;
@ -744,7 +744,7 @@ t_opseq *parse_expr(t_opseq *codeseq, int *stackdepth)
parse_error("AND must evaluate to single value");
tag_and = tag_new(BRANCH_TYPE);
codeseq = gen_brand(codeseq, tag_and);
codeseq = parse_expr(codeseq, &stackdepth1);
codeseq = parse_subexpr(codeseq, &stackdepth1);
if (stackdepth1 != *stackdepth)
parse_error("Inconsistent AND value counts");
codeseq = gen_codetag(codeseq, tag_and);
@ -761,12 +761,24 @@ t_opseq *parse_expr(t_opseq *codeseq, int *stackdepth)
parse_error("OR must evaluate to single value");
tag_or = tag_new(BRANCH_TYPE);
codeseq = gen_bror(codeseq, tag_or);
codeseq = parse_expr(codeseq, &stackdepth1);
codeseq = parse_subexpr(codeseq, &stackdepth1);
if (stackdepth1 != *stackdepth)
parse_error("Inconsistent AND value counts");
codeseq = gen_codetag(codeseq, tag_or);
}
else if (scantoken == TERNARY_TOKEN)
return (codeseq);
}
t_opseq *parse_expr(t_opseq *codeseq, int *stackdepth)
{
int prevmatch;
int matchop = 0;
int optos = opsptr;
int i, valdepth;
int prevtype, type = 0;
t_opseq *valseq;
codeseq = parse_subexpr(codeseq, stackdepth);
if (scantoken == TERNARY_TOKEN)
{
int tag_else, tag_endtri;
int stackdepth1;
@ -790,8 +802,7 @@ t_opseq *parse_expr(t_opseq *codeseq, int *stackdepth)
codeseq = gen_codetag(codeseq, tag_endtri);
}
return (codeseq);
}
t_opseq *parse_set(t_opseq *codeseq)
}t_opseq *parse_set(t_opseq *codeseq)
{
char *setptr = tokenstr;
int lparms = 0, rparms = 0;

View File

@ -493,7 +493,7 @@ def parse_value(codeseq, r_val)#2
fin
return cat_seq(codeseq, valseq), stackdepth
end
def parse_expr(codeseq)#2
def parse_subexpr(codeseq)#2
byte stackdepth, matchdepth, stkdepth1, prevmatch, matchop, i
word optos
word tag_else, tag_endop
@ -530,17 +530,25 @@ def parse_expr(codeseq)#2
if stackdepth <> 1; exit_err(ERR_OVER|ERR_SYNTAX); fin
tag_endop = new_tag(RELATIVE_FIXUP)
codeseq = gen_oprel(codeseq, BRAND_CODE, tag_endop)
codeseq, stkdepth1 = parse_expr(codeseq)
codeseq, stkdepth1 = parse_subexpr(codeseq)
if stkdepth1 <> stackdepth; exit_err(ERR_INVAL|ERR_CODE); fin
codeseq = gen_ctag(codeseq, tag_endop)
elsif token == LOGIC_OR_TKN
if stackdepth <> 1; exit_err(ERR_OVER|ERR_SYNTAX); fin
tag_endop = new_tag(RELATIVE_FIXUP)
codeseq = gen_oprel(codeseq, BROR_CODE, tag_endop)
codeseq, stkdepth1 = parse_expr(codeseq)
codeseq, stkdepth1 = parse_subexpr(codeseq)
if stkdepth1 <> stackdepth; exit_err(ERR_INVAL|ERR_CODE); fin
codeseq = gen_ctag(codeseq, tag_endop)
elsif token == TERNARY_TKN
fin
return codeseq, stackdepth
end
def parse_expr(codeseq)#2
byte stackdepth, stkdepth1
word tag_else, tag_endop
codeseq, stackdepth = parse_subexpr(codeseq)
if token == TERNARY_TKN
if stackdepth <> 1; exit_err(ERR_OVER|ERR_SYNTAX); fin
tag_else = new_tag(RELATIVE_FIXUP)
tag_endop = new_tag(RELATIVE_FIXUP)