Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Expressions and Compilers

1 view
Skip to first unread message

Realist

unread,
Dec 21, 2009, 12:32:27 PM12/21/09
to
Formally, expressions in any programming language would be arbitrarily
complicate. However, a compiler imposes restrictions because of the
stack size reserved for internal representation of an expression. It
could be easily estimated with the simple program:
TEST:PROC OPTIONS(MAIN);
DCL X FLOAT;
X=1E0;
X=X+X+X+…+X;
PUT LIST(X);
END TEST;

You should add “+X” (one after another) instead of “…” until the
compiler returns a message like “EXPRESSION OVERFLOW”. For example,
antique compiler DR PL/I-86 allows to write program which would print
3.200000E+01 because the depth of the stack for expressions is very
small. The compiler which I use has a stack storing 1024 internal
operations. Therefore it allows a program which would print 3.400000E
+02. (Every addition operation includes 3 internal operations for one
addition. Thus 340 addition operations require 1020 internal
operations and 2 internal operations for one assignment. The sum total
is 1022.)
It would be interesting to check other compilers.

robin

unread,
Dec 21, 2009, 7:11:07 PM12/21/09
to
Realist wrote in message <5dcff639-e04d-45bd...@d21g2000yqn.googlegroups.com>...

A lot would depend on the extent of optimisation.
It's possible that the expression is optimised to
X = 1022;


0 new messages