Created
November 27, 2014 08:10
-
-
Save tommy351/7323c949d55d4e63b600 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import exp.*; | |
import flowd.*; | |
class P99 extends FunNode { | |
P99(){ | |
super("P99"); | |
Var i = addVar("i"); | |
Var j = addVar("j"); | |
addBeginNode("L0"); | |
addExpNode("L1", new SetByOp(i, new Lit(0))); // i = 1 | |
Next1Node L2 = addExpNode("L2", new SetByOp(j, new Lit(1))); // j = 1 | |
Next1Node L3 = addExpNode("L3", new AddByOp(i, new Lit(1))); // i++ | |
Next2Node L4 = addBranchNode("L4", new LtOp(i, new Lit(10))); // i < 10 | |
Next2Node L5 = addBranchNode("L5", new LtOp(j, new Lit(10))); // j < 10 | |
Next2Node L6 = addBranchNode("L6", new EqOp(j, new Lit(9))); // j == 9 | |
Next1Node L7 = addPrintlnNode("L7", new MulOp(i, j)); // println(i * j) | |
Next1Node L8 = addPrintspNode("L8", new MulOp(i, j)); // print(i * j) | |
Next1Node L9 = addExpNode("L9", new AddByOp(j, new Lit(1))); // j++ | |
Next0Node L10 = addEndNode("L10"); | |
setStraightNext(); | |
L4.setNext(L5, L10); | |
L5.setNext(L6, L2); | |
L6.setNext(L7, L8); | |
L7.setNext(L9); | |
L9.setNext(L5); | |
} | |
public static void main(String[] args){ | |
FunNode p99 = new P99(); | |
p99.print(); | |
p99.execute(); | |
} | |
} | |
/* | |
D:\exam>javac *.java && java P99 | |
P99() | |
VAR i, j | |
L0 BEGIN GOTO L1 | |
L1 (i=0.0) GOTO L2 | |
L2 (j=1.0) GOTO L3 | |
L3 (i+=1.0) GOTO L4 | |
L4 IF (i<10.0) L5 ELSE L10 | |
L5 IF (j<10.0) L6 ELSE L2 | |
L6 IF (j==9.0) L7 ELSE L8 | |
L7 PRINTLN (i*j) GOTO L9 | |
L8 PRINTSP (i*j) GOTO L9 | |
L9 (j+=1.0) GOTO L5 | |
L10 END | |
1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 | |
2.0 4.0 6.0 8.0 10.0 12.0 14.0 16.0 18.0 | |
3.0 6.0 9.0 12.0 15.0 18.0 21.0 24.0 27.0 | |
4.0 8.0 12.0 16.0 20.0 24.0 28.0 32.0 36.0 | |
5.0 10.0 15.0 20.0 25.0 30.0 35.0 40.0 45.0 | |
6.0 12.0 18.0 24.0 30.0 36.0 42.0 48.0 54.0 | |
7.0 14.0 21.0 28.0 35.0 42.0 49.0 56.0 63.0 | |
8.0 16.0 24.0 32.0 40.0 48.0 56.0 64.0 72.0 | |
9.0 18.0 27.0 36.0 45.0 54.0 63.0 72.0 81.0 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment