summaryrefslogtreecommitdiff
path: root/dice-lang/src/bjc/dicelang/expr
diff options
context:
space:
mode:
authorbjculkin <bjculkin@mix.wvu.edu>2017-04-11 17:51:13 -0400
committerbjculkin <bjculkin@mix.wvu.edu>2017-04-11 17:51:13 -0400
commit40858cee415643769ee5f6216b0cd4335996ff2f (patch)
tree86b1c334fa2e5b79cddc16984f5ad43c3c72e41f /dice-lang/src/bjc/dicelang/expr
parent767ca1b248da19b754d42a814b71b43ef16090be (diff)
General cleanup and fixes
Diffstat (limited to 'dice-lang/src/bjc/dicelang/expr')
-rw-r--r--dice-lang/src/bjc/dicelang/expr/Lexer.java23
-rw-r--r--dice-lang/src/bjc/dicelang/expr/Parser.java4
-rw-r--r--dice-lang/src/bjc/dicelang/expr/Shunter.java18
-rw-r--r--dice-lang/src/bjc/dicelang/expr/Token.java4
-rw-r--r--dice-lang/src/bjc/dicelang/expr/Tokens.java4
5 files changed, 33 insertions, 20 deletions
diff --git a/dice-lang/src/bjc/dicelang/expr/Lexer.java b/dice-lang/src/bjc/dicelang/expr/Lexer.java
index 7c15884..3147463 100644
--- a/dice-lang/src/bjc/dicelang/expr/Lexer.java
+++ b/dice-lang/src/bjc/dicelang/expr/Lexer.java
@@ -3,7 +3,8 @@ package bjc.dicelang.expr;
import java.util.LinkedList;
import java.util.List;
-import bjc.utils.parserutils.splitter.SimpleTokenSplitter;
+import bjc.utils.funcdata.IList;
+import bjc.utils.parserutils.splitter.ConfigurableTokenSplitter;
/**
* Implements the lexer for simple expression operations.
@@ -12,18 +13,18 @@ import bjc.utils.parserutils.splitter.SimpleTokenSplitter;
*/
public class Lexer {
/*
- * Spliter we use
+ * Splitter we use.
*/
- private SimpleTokenSplitter split;
+ private ConfigurableTokenSplitter split;
/**
* Create a new expression lexer.
*/
public Lexer() {
- split = new SimpleTokenSplitter();
+ split = new ConfigurableTokenSplitter(true);
- split.addDelimiter("(", ")");
- split.addDelimiter("+", "-", "*", "/");
+ split.addSimpleDelimiters("(", ")");
+ split.addSimpleDelimiters("+", "-", "*", "/");
}
/**
@@ -31,8 +32,9 @@ public class Lexer {
*
* @param inp
* The input command.
+ *
* @param tks
- * The token state
+ * The token state.
*
* @return A series of infix tokens representing the command.
*/
@@ -42,11 +44,10 @@ public class Lexer {
List<Token> tokens = new LinkedList<>();
for(String spacedToken : spacedTokens) {
- String[] rawTokens = split.split(spacedToken);
+ IList<String> splitTokens = split.split(spacedToken);
+ IList<Token> rawTokens = splitTokens.map(tok -> tks.lexToken(tok, spacedToken));
- for(String tok : rawTokens) {
- tokens.add(tks.lexToken(tok, spacedToken));
- }
+ rawTokens.forEach(tokens::add);
}
return tokens.toArray(new Token[0]);
diff --git a/dice-lang/src/bjc/dicelang/expr/Parser.java b/dice-lang/src/bjc/dicelang/expr/Parser.java
index e806a6f..71a88fc 100644
--- a/dice-lang/src/bjc/dicelang/expr/Parser.java
+++ b/dice-lang/src/bjc/dicelang/expr/Parser.java
@@ -119,7 +119,7 @@ public class Parser {
if(ast.getChildrenCount() == 0)
/*
- * Handle leaf nodes
+ * Handle leaf nodes.
*/
return data.toExpr();
else {
@@ -150,4 +150,4 @@ public class Parser {
return leftExpr + " " + data.toExpr() + " " + rightExpr;
}
}
-}
+} \ No newline at end of file
diff --git a/dice-lang/src/bjc/dicelang/expr/Shunter.java b/dice-lang/src/bjc/dicelang/expr/Shunter.java
index 5d8cb7c..bbece0f 100644
--- a/dice-lang/src/bjc/dicelang/expr/Shunter.java
+++ b/dice-lang/src/bjc/dicelang/expr/Shunter.java
@@ -39,7 +39,12 @@ public class Shunter {
* respecting their left associativity.
*/
int leftPriority = tok.type.operatorPriority;
- int rightPriority = curOp == null ? 0 : curOp.type.operatorPriority;
+
+ int rightPriority;
+ if(curOp == null)
+ rightPriority = 0;
+ else
+ rightPriority = curOp.type.operatorPriority;
boolean isHigherPrec = leftPriority >= rightPriority;
@@ -53,7 +58,11 @@ public class Shunter {
curOp = opStack.peek();
leftPriority = tok.type.operatorPriority;
- rightPriority = curOp == null ? 0 : curOp.type.operatorPriority;
+
+ if(curOp == null)
+ rightPriority = 0;
+ else
+ rightPriority = curOp.type.operatorPriority;
isHigherPrec = leftPriority >= rightPriority;
}
@@ -65,7 +74,8 @@ public class Shunter {
Token curOp = opStack.peek();
/*
- * Pop things until we find the matching paren.
+ * Pop things until we find the matching
+ * parenthesis.
*/
while(curOp.type != TokenType.OPAREN) {
Token tk = opStack.pop();
@@ -92,4 +102,4 @@ public class Shunter {
return postfixTokens.toArray(new Token[0]);
}
-}
+} \ No newline at end of file
diff --git a/dice-lang/src/bjc/dicelang/expr/Token.java b/dice-lang/src/bjc/dicelang/expr/Token.java
index b02f6c9..2a73d0b 100644
--- a/dice-lang/src/bjc/dicelang/expr/Token.java
+++ b/dice-lang/src/bjc/dicelang/expr/Token.java
@@ -33,8 +33,10 @@ public class Token {
*
* @param type
* The type of this token.
+ *
* @param raw
* The string this token came from.
+ *
* @param toks
* The state for this token
*/
@@ -84,4 +86,4 @@ public class Token {
return "???";
}
}
-}
+} \ No newline at end of file
diff --git a/dice-lang/src/bjc/dicelang/expr/Tokens.java b/dice-lang/src/bjc/dicelang/expr/Tokens.java
index 08e7197..88bd99e 100644
--- a/dice-lang/src/bjc/dicelang/expr/Tokens.java
+++ b/dice-lang/src/bjc/dicelang/expr/Tokens.java
@@ -26,7 +26,7 @@ public class Tokens {
public final Map<Integer, String> symbolTable;
/*
- * Next index into the symbol table
+ * Next index into the symbol table.
*/
private int nextSym;
@@ -60,7 +60,7 @@ public class Tokens {
* Convert the string representation of a token into a token.
*
* @param tok
- * The string repr. of the token.
+ * The string representation of the token.
* @param raw
* The original string the token came from.
*