diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2017-02-28 06:24:31 -0500 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2017-02-28 06:24:31 -0500 |
| commit | 6ed83507953322c35a456d64d89f8f4f9cb0a6a1 (patch) | |
| tree | 2ebb6fcf5ae72d3f5be4bcade5a1e00c6371dea4 /dice-lang/src | |
| parent | e36e3b56b9b736d7a5caa889f280f90688eb9ad7 (diff) | |
Fix unary operators
I'm not entirely happy with how they work. I may just move to a
'immediate' operator mode sort of like how a forth would.
Diffstat (limited to 'dice-lang/src')
| -rw-r--r-- | dice-lang/src/bjc/dicelang/v2/Shunter.java | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/dice-lang/src/bjc/dicelang/v2/Shunter.java b/dice-lang/src/bjc/dicelang/v2/Shunter.java index 41bc388..28dafef 100644 --- a/dice-lang/src/bjc/dicelang/v2/Shunter.java +++ b/dice-lang/src/bjc/dicelang/v2/Shunter.java @@ -41,7 +41,7 @@ public class Shunter { unaryAdverbs = new HashSet<>(); unaryGerunds = new HashSet<>(); - unaryAdjectives.add(COERCE); + unaryAdverbs.add(COERCE); ops.put(ADD, 0 + MATH_PREC); ops.put(SUBTRACT, 0 + MATH_PREC); @@ -60,7 +60,9 @@ public class Shunter { ops.put(BIND, 1 + EXPR_PREC); } - private boolean isUnary(Token ty) { + private boolean isUnary(Token tk) { + Token.Type ty = tk.type; + if(unaryAdjectives.contains(ty)) return true; if(unaryAdverbs.contains(ty)) return true; if(unaryGerunds.contains(ty)) return true; @@ -104,7 +106,7 @@ public class Shunter { if(tk.type == TAGOP) { newTok.tokenValues = tk.tokenValues; } else { - newTok.tokenValues = new FunctionalList<>(); + newTok.tokenValues = new FunctionalList<>(tk); } newTok.tokenValues.add(unaryOp); @@ -112,7 +114,23 @@ public class Shunter { return true; } else if(unaryAdverbs.contains(unaryType)) { - + if(!isOp(tk)) { + Errors.inst.printError(EK_SHUNT_NOTADJ, unaryOp.toString(), tk.toString()); + return false; + } + + Token newTok = new Token(TAGOPR); + + if(tk.type == TAGOP) { + newTok.tokenValues = tk.tokenValues; + } else { + newTok.tokenValues = new FunctionalList<>(tk); + } + + newTok.tokenValues.add(unaryOp); + opStack.push(newTok); + + return true; } } |
