changeset 8:2e1069ee21af

Added Ne, Lt, Le, Gt, Ge and Not in lexer
author johnsen@johnsen-desktop
date Fri, 18 Apr 2008 12:33:03 +0200
parents 606a57c90a0b
children a0a3223a76c3
files lexer/Lexer.d lexer/Token.d test.td
diffstat 3 files changed, 29 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/lexer/Lexer.d	Fri Apr 18 12:24:14 2008 +0200
+++ b/lexer/Lexer.d	Fri Apr 18 12:33:03 2008 +0200
@@ -85,8 +85,20 @@
                 return Token(Tok.Comma, Location(position - 1, this.source), 1);
             case '=':
                 if(source.data[position] == '=')
-                    return Token(Tok.Equals, Location(position++ - 1, this.source), 2);
+                    return Token(Tok.Eq, Location(position++ - 1, this.source), 2);
                 return Token(Tok.Assign, Location(position - 1, this.source), 1);
+            case '!':
+                if(source.data[position] == '=')
+                    return Token(Tok.Ne, Location(position++ - 1, this.source), 2);
+                return Token(Tok.Not, Location(position - 1, this.source), 1);
+            case '<':
+                if(source.data[position] == '=')
+                    return Token(Tok.Le, Location(position++ - 1, this.source), 2);
+                return Token(Tok.Lt, Location(position - 1, this.source), 1);
+            case '>':
+                if(source.data[position] == '=')
+                    return Token(Tok.Ge, Location(position++ - 1, this.source), 2);
+                return Token(Tok.Gt, Location(position - 1, this.source), 1);
             case '+':
                 return Token(Tok.Add, Location(position - 1, this.source), 1);
             case '-':
@@ -200,6 +212,9 @@
             case ';':
             case ',':
             case '=':
+            case '!':
+            case '<':
+            case '>':
             case '+':
             case '-':
             case '*':
--- a/lexer/Token.d	Fri Apr 18 12:24:14 2008 +0200
+++ b/lexer/Token.d	Fri Apr 18 12:33:03 2008 +0200
@@ -59,8 +59,12 @@
     CloseBrace,
     Seperator,
 
-    /* Boolean operators */
-    Equals, NotEquals,
+    /* Comparator operators */
+    Eq, Ne,
+    Lt, Gt,
+    Le, Ge,
+
+    Not,
 
     /* Keywords */
     Byte, Ubyte,
@@ -90,8 +94,12 @@
         Tok.Int:"Int",
         Tok.Long:"Long",
         Tok.Bool:"Bool",
-        Tok.Equals:"Equals",
-        Tok.NotEquals:"NotEquals",
+        Tok.Eq:"Eq",
+        Tok.Ne:"Ne",
+        Tok.Lt:"Lt",
+        Tok.Le:"Le",
+        Tok.Gt:"Gt",
+        Tok.Ge:"Ge",
         Tok.OpenParentheses:"OpenParentheses",
         Tok.CloseParentheses:"CloseParentheses",
         Tok.OpenBrace:"OpenBrace",
--- a/test.td	Fri Apr 18 12:24:14 2008 +0200
+++ b/test.td	Fri Apr 18 12:33:03 2008 +0200
@@ -11,7 +11,7 @@
 int nice(long s, short t)
 {
     byte x = 5 + t;
-    if (x == 0)
+    if (x > 0)
         if (s)
             t = 5 + 1 * 5 * s + t;
     return 2 * (t + -1) - x;