diff options
| author | Cliff Click <cliffc@acm.org> | 2026-09-17 16:39:32 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-09-17 16:39:32 -0700 |
| commit | 200162345900136663027b6deae21d72cf30818c (patch) | |
| tree | a9b26f38b5f920f61837327ab56f97c5f9a01016 /chapter18/src/main/java/com | |
| parent | 42681f41318796afc58bc14ce04620b7c5c7eb18 (diff) | |
| download | Simple-200162345900136663027b6deae21d72cf30818c.tar.gz Simple-200162345900136663027b6deae21d72cf30818c.zip | |
Backport string escapes and many op-assign
Diffstat (limited to 'chapter18/src/main/java/com')
| -rw-r--r-- | chapter18/src/main/java/com/seaofnodes/simple/Parser.java | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/chapter18/src/main/java/com/seaofnodes/simple/Parser.java b/chapter18/src/main/java/com/seaofnodes/simple/Parser.java index ad617b2b..24f0806a 100644 --- a/chapter18/src/main/java/com/seaofnodes/simple/Parser.java +++ b/chapter18/src/main/java/com/seaofnodes/simple/Parser.java @@ -1107,11 +1107,17 @@ public class Parser { // flt + flt ==>> use float op Node op = switch(ch) { case 1, (char)-1, - '+' -> new AddNode(lhs,rhs); - case '-' -> new SubNode(lhs,rhs); - case '*' -> new MulNode(lhs,rhs); - case '/' -> new DivNode(lhs,rhs); - default -> throw Utils.TODO(); + '+' -> new AddNode(lhs,rhs); + case '-' -> new SubNode(lhs,rhs); + case '*' -> new MulNode(lhs,rhs); + case '/' -> new DivNode(lhs,rhs); + case '&' -> new AndNode(loc(),lhs,rhs); + case '|' -> new OrNode(loc(),lhs,rhs); + case '^' -> new XorNode(loc(),lhs,rhs); + case Lexer.SHL -> new ShlNode(loc(),lhs,rhs); + case Lexer.SAR -> new SarNode(loc(),lhs,rhs); + case Lexer.SHR -> new ShrNode(loc(),lhs,rhs); + default -> throw Utils.TODO(); }; // Convert to float ops, or narrow int types; error if not declared type. // Also, if postfix LHS is still keep() @@ -1700,8 +1706,14 @@ public class Parser { // Next oper= character, or 0. // As a convenience, mark "++" as a char 1 and "--" as char -1 (65535) + // Distinct tags for the multi-character compound operators. + static final char SHL = 2, SAR = 3, SHR = 4; + public char matchOperAssign() { skipWhiteSpace(); + if( match("<<=" ) ) return SHL; + if( match(">>>=") ) return SHR; + if( match(">>=" ) ) return SAR; if( _position+2 >= _input.length ) return 0; char ch0 = (char)_input[_position]; if( "+-/*&|^".indexOf(ch0) == -1 ) return 0; |
