This commit is contained in:
rogerl%netscape.com 1999-05-07 22:18:39 +00:00
Родитель 89417fcd5e
Коммит f73b34389c
6 изменённых файлов: 222 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,21 @@
class AssignmentNode extends BinaryNode {
AssignmentNode(String aOp, ExpressionNode aLeft, ExpressionNode aRight)
{
super(aOp, aLeft, aRight);
}
void eval(Environment theEnv)
{
left.evalLHS(theEnv);
right.eval(theEnv);
double dValue = theEnv.theStack.pop().d;
String id = theEnv.theStack.pop().id;
theEnv.theGlobals.put(id, new Double(dValue));
}
}

Просмотреть файл

@ -0,0 +1,49 @@
class ConditionalNode extends ControlNode {
ConditionalNode(ExpressionNode aCondition, ControlNode aTrueCode)
{
super(aCondition);
trueCode = aTrueCode;
}
ConditionalNode(ExpressionNode aCondition, ControlNode aTrueCode, ControlNode aFalseCode)
{
super(aCondition);
trueCode = aTrueCode;
setNext(aFalseCode);
}
ControlNode eval(Environment theEnv)
{
ControlNode n = super.eval(theEnv);
double d = theEnv.theStack.pop().d;
if (d != 0.0)
return trueCode;
else
return n;
}
String print()
{
StringBuffer result = new StringBuffer("ConditionalNode ");
result.append(index);
result.append("\nexpr:\n");
if (expr == null)
result.append("expr = null\n");
else
result.append(expr.print(""));
result.append("true branch:\n");
if (trueCode == null)
result.append("true branch = null\n");
else
result.append("true branch->" + trueCode.index + "\n");
result.append("false branch:\n");
if (next == null)
result.append("false branch = null\n");
else
result.append("false branch->" + next.index + "\n");
return result.toString();
}
protected ControlNode trueCode;
}

Просмотреть файл

@ -0,0 +1,61 @@
import java.util.Vector;
class ControlNode {
private static Vector gList = new Vector();
static String printAll()
{
StringBuffer result = new StringBuffer();
for (int i = 0; i < gList.size(); i++) {
result.append(((ControlNode)(gList.elementAt(i))).print());
}
return result.toString();
}
ControlNode(ExpressionNode anExpr)
{
expr = anExpr;
index = gList.size();
gList.addElement(this);
}
void setNext(ControlNode aNext)
{
next = aNext;
}
ControlNode eval(Environment theEnv)
{
expr.eval(theEnv);
return next;
}
String print()
{
StringBuffer result = new StringBuffer("ControlNode ");
result.append(index);
result.append("\nexpr:\n");
if (expr == null)
result.append("expr = null\n");
else
result.append(expr.print(""));
result.append("next:\n");
if (next == null)
result.append("next = null\n");
else
result.append("next->" + next.index + "\n");
return result.toString();
}
protected ExpressionNode expr;
protected ControlNode next;
protected int index;
}

Просмотреть файл

@ -0,0 +1,57 @@
import java.util.Vector;
class ControlNodeGroup {
ControlNodeGroup(ControlNode aHead)
{
head = aHead;
tails = new Vector();
}
void fixTails(ControlNode butt)
{
int count = tails.size();
for (int i = 0; i < count; i++)
{
ControlNode aNode = (ControlNode)(tails.elementAt(i));
aNode.setNext(butt);
}
tails.removeAllElements();
}
void setHead(ControlNode aHead)
{
head = aHead;
}
ControlNode getHead()
{
return head;
}
void addTail(ControlNode aTail)
{
tails.addElement(aTail);
}
void removeTail(ControlNode aTail)
{
tails.removeElement(aTail);
}
void addTails(ControlNodeGroup aGroup)
{
int count = aGroup.tails.size();
for (int i = 0; i < count; i++)
{
tails.addElement(aGroup.tails.elementAt(i));
}
aGroup.tails.removeAllElements();
}
ControlNode head;
Vector tails;
}

Просмотреть файл

@ -0,0 +1,18 @@
import java.util.Hashtable;
class Environment {
JSStack theStack = new JSStack();
Hashtable theGlobals = new Hashtable();
String print()
{
StringBuffer result = new StringBuffer("Globals contents :\n");
result.append(theGlobals.toString());
result.append("\nStack Top = " + theStack.size());
return result.toString();
}
}

Просмотреть файл

@ -0,0 +1,16 @@
class StackValue {
StackValue(double x)
{
d = x;
}
StackValue(String x)
{
id = x;
}
double d;
String id;
}