Skip to content

Commit 6677246

Browse files
committed
added parens around unary operator expressions. added runrun target to make that parses the unparse output of a parse (for error checking purposes).
1 parent a2d91e5 commit 6677246

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

parser/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Errors.class: Errors.java
4545
# clean
4646
###
4747
clean:
48-
rm -f *~ *.class parser.java Little.jlex.java sym.java
48+
rm -f *~ *.class parser.java Little.jlex.java sym.java *.c
4949

5050
###
5151
# run provided parser
@@ -58,3 +58,7 @@ test:
5858
###
5959
run: P3.class
6060
java -classpath ${CP} P3 test.Little test.c
61+
62+
runrun: P3.class
63+
java -classpath ${CP} P3 test.Little test.c
64+
java -classpath ${CP} P3 test.c testtest.c

parser/ast.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,8 +762,10 @@ public PlusPlusNode(IdNode id) {
762762

763763
// ** unparse **
764764
public void unparse(PrintWriter p, int indent) {
765+
p.print("(");
765766
myExp.unparse(p, indent);
766767
p.print("++");
768+
p.print(")");
767769
}
768770
}
769771

@@ -774,8 +776,10 @@ public MinusMinusNode(IdNode id) {
774776

775777
// ** unparse **
776778
public void unparse(PrintWriter p, int indent) {
779+
p.print("(");
777780
myExp.unparse(p, indent);
778781
p.print("--");
782+
p.print(")");
779783
}
780784
}
781785

@@ -786,8 +790,10 @@ public UnaryMinusNode(ExpNode exp) {
786790

787791
// ** unparse **
788792
public void unparse(PrintWriter p, int indent) {
793+
p.print("(");
789794
p.print("-");
790795
myExp.unparse(p, indent);
796+
p.print(")");
791797
}
792798
}
793799

@@ -798,8 +804,10 @@ public NotNode(ExpNode exp) {
798804

799805
// ** unparse **
800806
public void unparse(PrintWriter p, int indent) {
807+
p.print("(");
801808
p.print("!");
802809
myExp.unparse(p, indent);
810+
p.print(")");
803811
}
804812
}
805813

parser/test.Little

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,20 @@ double myfunc3() {
4747
int g;
4848

4949
/* nested if statements */
50-
if(1 < 2) {}
50+
if(1 < 2) {
51+
while(a < b) {
52+
int swiss;
53+
double havarti;
54+
55+
if(1 < 2) {
56+
int d;
57+
int e;
58+
}
59+
60+
swiss = 10;
61+
havarti = 0.4 + swiss;
62+
}
63+
}
5164
f = f + a;
5265
}
5366
else {

0 commit comments

Comments
 (0)