summaryrefslogtreecommitdiff
path: root/chapter06/src
diff options
context:
space:
mode:
Diffstat (limited to 'chapter06/src')
-rw-r--r--chapter06/src/main/java/com/seaofnodes/simple/Parser.java9
-rw-r--r--chapter06/src/main/java/com/seaofnodes/simple/node/Node.java9
2 files changed, 7 insertions, 11 deletions
diff --git a/chapter06/src/main/java/com/seaofnodes/simple/Parser.java b/chapter06/src/main/java/com/seaofnodes/simple/Parser.java
index 81cb9e57..dec0fa57 100644
--- a/chapter06/src/main/java/com/seaofnodes/simple/Parser.java
+++ b/chapter06/src/main/java/com/seaofnodes/simple/Parser.java
@@ -13,7 +13,6 @@ import java.util.*;
* This is a simple recursive descent parser. All lexical analysis is done here as well.
*/
public class Parser {
-
/**
* A Global Static, unique to each compilation. This is a public, so we
@@ -88,14 +87,14 @@ public class Parser {
public StopNode parse() { return parse(false); }
public StopNode parse(boolean show) {
- _xScopes.push(_scope);
+ _xScopes.push(_scope);
// Enter a new scope for the initial control and arguments
_scope.push();
_scope.define(ScopeNode.CTRL, new ProjNode(START, 0, ScopeNode.CTRL).peephole());
_scope.define(ScopeNode.ARG0, new ProjNode(START, 1, ScopeNode.ARG0).peephole());
parseBlock();
_scope.pop();
- _xScopes.pop();
+ _xScopes.pop();
if (!_lexer.isEOF()) throw error("Syntax error, unexpected " + _lexer.getAnyNextToken());
STOP.peephole();
if( show ) showGraph();
@@ -269,10 +268,10 @@ public class Parser {
var lhs = parseAddition();
if (match("==")) return new BoolNode.EQ(lhs, parseComparison()).peephole();
if (match("!=")) return new NotNode(new BoolNode.EQ(lhs, parseComparison()).peephole()).peephole();
- if (match("<" )) return new BoolNode.LT(lhs, parseComparison()).peephole();
if (match("<=")) return new BoolNode.LE(lhs, parseComparison()).peephole();
- if (match(">" )) return new BoolNode.LT(parseComparison(), lhs).peephole();
+ if (match("<" )) return new BoolNode.LT(lhs, parseComparison()).peephole();
if (match(">=")) return new BoolNode.LE(parseComparison(), lhs).peephole();
+ if (match(">" )) return new BoolNode.LT(parseComparison(), lhs).peephole();
return lhs;
}
diff --git a/chapter06/src/main/java/com/seaofnodes/simple/node/Node.java b/chapter06/src/main/java/com/seaofnodes/simple/node/Node.java
index f5e58284..4fbcf940 100644
--- a/chapter06/src/main/java/com/seaofnodes/simple/node/Node.java
+++ b/chapter06/src/main/java/com/seaofnodes/simple/node/Node.java
@@ -91,10 +91,7 @@ public abstract class Node {
// line (because this is what a debugger typically displays by default) and
// has to be robust with broken graph/nodes.
@Override
- public final String toString() {
- // TODO: This needs a lot of work
- return print();
- }
+ public final String toString() { return print(); }
// This is a *deep* print. This version will fail on cycles, which we will
// correct later when we can parse programs with loops. We print with a
@@ -199,11 +196,11 @@ public abstract class Node {
// Error is 'use' does not exist; ok for 'use' to be null.
protected boolean delUse( Node use ) {
Utils.del(_outputs, Utils.find(_outputs, use));
- return _outputs.size() == 0;
+ return _outputs.isEmpty();
}
// Shortcut for "popping" n nodes. A "pop" is basically a
- // set_def(last,null) followed by lowering the nIns() count.
+ // setDef(last,null) followed by lowering the nIns() count.
void popN(int n) {
for( int i=0; i<n; i++ ) {
Node old_def = _inputs.removeLast();