summaryrefslogtreecommitdiff
path: root/base/src/bjc/dicelang/expr
diff options
context:
space:
mode:
Diffstat (limited to 'base/src/bjc/dicelang/expr')
-rw-r--r--base/src/bjc/dicelang/expr/Lexer.java8
-rw-r--r--base/src/bjc/dicelang/expr/Parser.java22
-rw-r--r--base/src/bjc/dicelang/expr/Shunter.java19
-rw-r--r--base/src/bjc/dicelang/expr/Token.java8
-rw-r--r--base/src/bjc/dicelang/expr/TokenType.java21
-rw-r--r--base/src/bjc/dicelang/expr/Tokens.java9
6 files changed, 38 insertions, 49 deletions
diff --git a/base/src/bjc/dicelang/expr/Lexer.java b/base/src/bjc/dicelang/expr/Lexer.java
index dfa0f76..a8fbcaa 100644
--- a/base/src/bjc/dicelang/expr/Lexer.java
+++ b/base/src/bjc/dicelang/expr/Lexer.java
@@ -33,10 +33,10 @@ public class Lexer {
* Convert a string from a input command to a series of infix tokens.
*
* @param inp
- * The input command.
+ * The input command.
*
* @param tks
- * The token state.
+ * The token state.
*
* @return A series of infix tokens representing the command.
*/
@@ -44,14 +44,14 @@ public class Lexer {
/* Split tokens on whitespace. */
final String[] spacedTokens = inp.split("[ \t]");
/* Tokens to return. */
- final List<Token> tokens = new LinkedList<>();
+ final List<Token> tokens = new LinkedList<>();
/* Process each token. */
for (final String spacedToken : spacedTokens) {
/* Split on operators. */
final IList<String> splitTokens = split.split(spacedToken);
/* Convert strings to tokens. */
- final IList<Token> rawTokens = splitTokens.map(tok -> tks.lexToken(tok, spacedToken));
+ final IList<Token> rawTokens = splitTokens.map(tok -> tks.lexToken(tok, spacedToken));
/* Add tokens to results. */
rawTokens.forEach(tokens::add);
diff --git a/base/src/bjc/dicelang/expr/Parser.java b/base/src/bjc/dicelang/expr/Parser.java
index 5fa2d3d..3dc10ea 100644
--- a/base/src/bjc/dicelang/expr/Parser.java
+++ b/base/src/bjc/dicelang/expr/Parser.java
@@ -14,14 +14,14 @@ import bjc.utils.parserutils.TreeConstructor;
*/
public class Parser {
/*
- * @TODO 10/08/17 Ben Culkin :MainSeperation
- * This main method should be moved to its own class.
+ * @TODO 10/08/17 Ben Culkin :MainSeperation This main method should be moved to
+ * its own class.
*/
/**
* Main method.
*
* @param args
- * Unused CLI args.
+ * Unused CLI args.
*/
public static void main(final String[] args) {
/* Create our objects. */
@@ -76,12 +76,10 @@ public class Parser {
System.out.println();
/* Construct a list from the array of tokens. */
- final FunctionalList<Token> tokList = new FunctionalList<>(
- Arrays.asList(postfixTokens));
+ final FunctionalList<Token> tokList = new FunctionalList<>(Arrays.asList(postfixTokens));
/* Construct a tree from the list of postfixed tokens. */
- final ITree<Token> ast = TreeConstructor.constructTree(tokList,
- tok -> tok.typ.isOperator);
+ final ITree<Token> ast = TreeConstructor.constructTree(tokList, tok -> tok.typ.isOperator);
/* Print the tree, then the canonical expression for it. */
System.out.println("Parsed tree");
@@ -103,8 +101,8 @@ public class Parser {
}
/*
- * Convert an expression to one that uses the smallest necessary amount
- * of parens.
+ * Convert an expression to one that uses the smallest necessary amount of
+ * parens.
*/
private static String toCanonicalExpr(final ITree<Token> ast) {
final Token data = ast.getHead();
@@ -115,11 +113,11 @@ public class Parser {
}
/* The left/right children. */
- final ITree<Token> left = ast.getChild(0);
+ final ITree<Token> left = ast.getChild(0);
final ITree<Token> right = ast.getChild(1);
/* Recursively canonicalize them. */
- String leftExpr = toCanonicalExpr(left);
+ String leftExpr = toCanonicalExpr(left);
String rightExpr = toCanonicalExpr(right);
/* Add parens if the left was higher priority. */
@@ -135,7 +133,7 @@ public class Parser {
/* Add parens if the right was higher priority. */
if (right.getChildrenCount() == 0) {
int rightPriority = right.getHead().typ.operatorPriority;
- int dataPriority = data.typ.operatorPriority;
+ int dataPriority = data.typ.operatorPriority;
if (rightPriority >= dataPriority) {
rightExpr = String.format("(%s)", rightExpr);
diff --git a/base/src/bjc/dicelang/expr/Shunter.java b/base/src/bjc/dicelang/expr/Shunter.java
index 213e473..031962a 100644
--- a/base/src/bjc/dicelang/expr/Shunter.java
+++ b/base/src/bjc/dicelang/expr/Shunter.java
@@ -12,15 +12,13 @@ import java.util.List;
*/
public class Shunter {
/*
- * @NOTE
- * Why does this method return an array, and not the list of
- * tokens?
+ * @NOTE Why does this method return an array, and not the list of tokens?
*/
/**
* Convert a infix series of tokens to a postfix series of tokens.
*
* @param infixTokens
- * The tokens in infix order.
+ * The tokens in infix order.
*
* @return The tokens in postfix order.
*/
@@ -38,12 +36,9 @@ public class Shunter {
Token curOp = opStack.peek();
/*
- * Check if an operator is higher priority,
- * respecting their left associativity.
+ * Check if an operator is higher priority, respecting their left associativity.
*
- * @NOTE
- * Should this be factored out into a
- * method?
+ * @NOTE Should this be factored out into a method?
*/
int leftPriority = tok.typ.operatorPriority;
int rightPriority;
@@ -57,8 +52,7 @@ public class Shunter {
boolean isHigherPrec = leftPriority >= rightPriority;
/*
- * Pop all operators that are lower precedence
- * than us.
+ * Pop all operators that are lower precedence than us.
*/
while (!opStack.isEmpty() && isHigherPrec) {
postfixTokens.add(opStack.pop());
@@ -81,8 +75,7 @@ public class Shunter {
Token curOp = opStack.peek();
/*
- * Pop things until we find the matching
- * parenthesis.
+ * Pop things until we find the matching parenthesis.
*/
while (curOp.typ != TokenType.OPAREN) {
final Token tk = opStack.pop();
diff --git a/base/src/bjc/dicelang/expr/Token.java b/base/src/bjc/dicelang/expr/Token.java
index bf92f97..dc6247b 100644
--- a/base/src/bjc/dicelang/expr/Token.java
+++ b/base/src/bjc/dicelang/expr/Token.java
@@ -32,13 +32,13 @@ public class Token {
* Create a new token.
*
* @param type
- * The type of this token.
+ * The type of this token.
*
* @param raw
- * The string this token came from.
+ * The string this token came from.
*
* @param toks
- * The state for this token
+ * The state for this token
*/
public Token(final TokenType type, final String raw, final Tokens toks) {
this.typ = type;
@@ -50,7 +50,7 @@ public class Token {
@Override
public String toString() {
String typeStr = typ.toString();
- typeStr = String.format("%s (%s)", typeStr, typ.name());
+ typeStr = String.format("%s (%s)", typeStr, typ.name());
if (typ == TokenType.VREF) {
typeStr += " (ind. " + intValue;
diff --git a/base/src/bjc/dicelang/expr/TokenType.java b/base/src/bjc/dicelang/expr/TokenType.java
index ad01917..9462139 100644
--- a/base/src/bjc/dicelang/expr/TokenType.java
+++ b/base/src/bjc/dicelang/expr/TokenType.java
@@ -6,21 +6,20 @@ package bjc.dicelang.expr;
* @author Ben Culkin
*/
public enum TokenType {
- /*
- * @NOTE
- * Do we want to switch to auto-numbering the tokens? They were
- * manually numbered because this was an assignment for PoPL and
- * that was what Dr. Naz wanted.
+ /*
+ * @NOTE Do we want to switch to auto-numbering the tokens? They were manually
+ * numbered because this was an assignment for PoPL and that was what Dr. Naz
+ * wanted.
*/
/** Represents + */
- ADD( 14, true, 0),
+ ADD(14, true, 0),
/** Represents - */
SUBTRACT(15, true, 0),
/** Represents * */
MULTIPLY(16, true, 1),
/** Represents / */
- DIVIDE( 17, true, 1),
+ DIVIDE(17, true, 1),
/** Represents variable names. */
VREF(11),
@@ -34,14 +33,14 @@ public enum TokenType {
public final int nVal;
/** Whether or not this type of token is an operator. */
- public final boolean isOperator;
+ public final boolean isOperator;
/** The priority of this operator, if it is one. */
- public final int operatorPriority;
+ public final int operatorPriority;
/* Create a new token. */
private TokenType(final int num, final boolean isOp, final int priority) {
- nVal = num;
- isOperator = isOp;
+ nVal = num;
+ isOperator = isOp;
operatorPriority = priority;
}
diff --git a/base/src/bjc/dicelang/expr/Tokens.java b/base/src/bjc/dicelang/expr/Tokens.java
index 287d2b4..0e31ebf 100644
--- a/base/src/bjc/dicelang/expr/Tokens.java
+++ b/base/src/bjc/dicelang/expr/Tokens.java
@@ -37,11 +37,10 @@ public class Tokens {
/* Set sym ID. */
nextSym = 0;
- /*
+ /*
* Setup literal mappings.
*
- * @NOTE
- * Should this be a static member?
+ * @NOTE Should this be a static member?
*/
litTokens = new HashMap<>();
litTokens.put("+", TokenType.ADD);
@@ -56,9 +55,9 @@ public class Tokens {
* Convert the string representation of a token into a token.
*
* @param tok
- * The string representation of the token.
+ * The string representation of the token.
* @param raw
- * The original string the token came from.
+ * The original string the token came from.
*
* @return The token the string represents.
*/