PRIVATE: code to compare expr

This commit is contained in:
neuromancer 2020-12-30 21:26:15 -03:00 committed by Eugene Sandulenko
parent 6a8adece27
commit b95e920fbc
3 changed files with 66 additions and 2 deletions

View file

@ -132,6 +132,66 @@ int assign() /* assign top value to next value */
return 0; return 0;
} }
int gt()
{
Datum d1, d2;
d2 = pop();
d1 = pop();
d1.val = (int)(d1.val > d2.val);
push(d1);
return 0;
}
int lt()
{
Datum d1, d2;
d2 = pop();
d1 = pop();
d1.val = (int)(d1.val < d2.val);
push(d1);
return 0;
}
int ge()
{
Datum d1, d2;
d2 = pop();
d1 = pop();
d1.val = (int)(d1.val >= d2.val);
push(d1);
return 0;
}
int le()
{
Datum d1, d2;
d2 = pop();
d1 = pop();
d1.val = (int)(d1.val <= d2.val);
push(d1);
return 0;
}
int eq()
{
Datum d1, d2;
d2 = pop();
d1 = pop();
d1.val = (int)(d1.val == d2.val);
push(d1);
return 0;
}
int ne()
{
Datum d1, d2;
d2 = pop();
d1 = pop();
d1.val = (int)(d1.val != d2.val);
push(d1);
return 0;
}
int print() /* pop top value from stack, print it */ int print() /* pop top value from stack, print it */
{ {
Datum d; Datum d;

View file

@ -36,6 +36,10 @@ extern int constpush();
extern int strpush(); extern int strpush();
extern int print(); extern int print();
extern int lt();
extern int gt();
extern void initcode(char *); extern void initcode(char *);
extern void execute(Inst *); extern void execute(Inst *);

View file

@ -101,8 +101,8 @@ expr: value
| value EQ value | value EQ value
| value NEQ value | value NEQ value
| value '+' value { code1(Private::add); } | value '+' value { code1(Private::add); }
| value '<' value | value '<' value { code1(Private::lt); }
| value '>' value | value '>' value { code1(Private::gt); }
| value LTE value | value LTE value
| value GTE value | value GTE value
| value '+' | value '+'