I can't think of any reason that "and" and "or" shouldn't be
short-circuit operators, so change them to do what "and then" and "or
else" currently do, and discard the latter.
Signed-off-by: NeilBrown <neil@brown.name>
print "error is ", target - guess * guess
for j:=0; then j = j+3 ; while j < 10:
print "error is ", target - guess * guess
for j:=0; then j = j+3 ; while j < 10:
- if j != 0 and then 20 / j > 3:
+ if j != 0 and 20 / j > 3:
print "20 /", j," =", 20 / j
else
print "I won't calculate 20 /", j
pi ::= 3.1415926535897
print "20 /", j," =", 20 / j
else
print "I won't calculate 20 /", j
pi ::= 3.1415926535897
- if 355/113 == pi or else +(pi - 355/113) < 0.001:
+ if 355/113 == pi or +(pi - 355/113) < 0.001:
print "Close enough"
print "lower" if 355/113 < pi else "higher"
print "higher" if 355/113 > pi else "lower"
print "Close enough"
print "lower" if 355/113 < pi else "higher"
print "higher" if 355/113 > pi else "lower"
func insert(list:@linkage; new:string)
p:=list
func insert(list:@linkage; new:string)
p:=list
- while ?p.next and then p.next.this < new:
+ while ?p.next and p.next.this < new:
p = p.next.list
t:@node = @new()
t.list.next = p.next
p = p.next.list
t:@node = @new()
t.list.next = p.next
Some operators that have only recently been added, and so have not
generated all that much experience yet are "and then" and "or else" as
Some operators that have only recently been added, and so have not
generated all that much experience yet are "and then" and "or else" as
-short-circuit Boolean operators, and the "if ... else" trinary
-operator which can select between two expressions based on a third
-(which appears syntactically in the middle).
+short-circuit Boolean operators (which have since been remove), and the
+"if ... else" trinary operator which can select between two expressions
+based on a third (which appears syntactically in the middle).
The "func" clause currently only allows a "main" function to be
declared. That will be extended when proper function support is added.
The "func" clause currently only allows a "main" function to be
declared. That will be extended when proper function support is added.
### Expressions: Boolean
The next class of expressions to use the `binode` will be Boolean
### Expressions: Boolean
The next class of expressions to use the `binode` will be Boolean
-expressions. "`and then`" and "`or else`" are similar to `and` and `or`
-have same corresponding precendence. The difference is that they don't
+expressions. `and` and `or` are short-circuit operators that don't
evaluate the second expression if not necessary.
###### Binode types
And,
evaluate the second expression if not necessary.
###### Binode types
And,
Not,
###### declare terminals
Not,
###### declare terminals
b->right = $<3;
$0 = b;
} }$
b->right = $<3;
$0 = b;
} }$
- | Expression or else Expression ${ {
- struct binode *b = new(binode);
- b->op = OrElse;
- b->left = $<1;
- b->right = $<4;
- $0 = b;
- } }$
-
| Expression and Expression ${ {
struct binode *b = new(binode);
b->op = And;
| Expression and Expression ${ {
struct binode *b = new(binode);
b->op = And;
b->right = $<3;
$0 = b;
} }$
b->right = $<3;
$0 = b;
} }$
- | Expression and then Expression ${ {
- struct binode *b = new(binode);
- b->op = AndThen;
- b->left = $<1;
- b->right = $<4;
- $0 = b;
- } }$
-
| not Expression ${ {
struct binode *b = new(binode);
b->op = Not;
| not Expression ${ {
struct binode *b = new(binode);
b->op = Not;
print_exec(b->right, -1, bracket);
if (bracket) printf(")");
break;
print_exec(b->right, -1, bracket);
if (bracket) printf(")");
break;
- case AndThen:
- if (bracket) printf("(");
- print_exec(b->left, -1, bracket);
- printf(" and then ");
- print_exec(b->right, -1, bracket);
- if (bracket) printf(")");
- break;
case Or:
if (bracket) printf("(");
print_exec(b->left, -1, bracket);
case Or:
if (bracket) printf("(");
print_exec(b->left, -1, bracket);
print_exec(b->right, -1, bracket);
if (bracket) printf(")");
break;
print_exec(b->right, -1, bracket);
if (bracket) printf(")");
break;
- case OrElse:
- if (bracket) printf("(");
- print_exec(b->left, -1, bracket);
- printf(" or else ");
- print_exec(b->right, -1, bracket);
- if (bracket) printf(")");
- break;
case Not:
if (bracket) printf("(");
printf("not ");
case Not:
if (bracket) printf("(");
printf("not ");
###### propagate binode cases
case And:
###### propagate binode cases
case And:
case Not:
/* both must be Tbool, result is Tbool */
propagate_types(b->left, c, perr, Tbool, 0);
case Not:
/* both must be Tbool, result is Tbool */
propagate_types(b->left, c, perr, Tbool, 0);
###### interp binode cases
case And:
###### interp binode cases
case And:
- rv = interp_exec(c, b->left, &rvtype);
- right = interp_exec(c, b->right, &rtype);
- rv.bool = rv.bool && right.bool;
- break;
- case AndThen:
rv = interp_exec(c, b->left, &rvtype);
if (rv.bool)
rv = interp_exec(c, b->right, NULL);
break;
case Or:
rv = interp_exec(c, b->left, &rvtype);
if (rv.bool)
rv = interp_exec(c, b->right, NULL);
break;
case Or:
- rv = interp_exec(c, b->left, &rvtype);
- right = interp_exec(c, b->right, &rtype);
- rv.bool = rv.bool || right.bool;
- break;
- case OrElse:
rv = interp_exec(c, b->left, &rvtype);
if (!rv.bool)
rv = interp_exec(c, b->right, NULL);
rv = interp_exec(c, b->left, &rvtype);
if (!rv.bool)
rv = interp_exec(c, b->right, NULL);
a : number
a = A;
b:number = B
a : number
a = A;
b:number = B
- if a > 0 and then b > 0:
while a != b:
if a < b:
b = b - a
while a != b:
if a < b:
b = b - a