diff trunk/src/Token.d @ 239:7911f6a92e6e

- Added 'new' and 'delete' declarations to Token and uncommented next and prev members. Added HEAD to TOK. - Tokens are stored in a doubly linked list by the Lexer now. - Added method scanNext() which can be used by peek() and nextToken(). - Saving 'token' in Parser.try_().
author aziz
date Mon, 30 Jul 2007 12:36:04 +0000
parents b7bde6583d3e
children 32d354584b28
line wrap: on
line diff
--- a/trunk/src/Token.d	Sat Jul 28 22:59:03 2007 +0000
+++ b/trunk/src/Token.d	Mon Jul 30 12:36:04 2007 +0000
@@ -3,6 +3,8 @@
   License: GPL2
 +/
 module Token;
+import std.c.stdlib : malloc, free;
+import std.outofmemory;
 
 struct Position
 {
@@ -89,6 +91,7 @@
   Typeof,Ubyte,Ucent,Uint,Ulong,Union,Unittest,
   Ushort,Version,Void,Volatile,Wchar,While,With,
 
+  HEAD, // start of linked list
   EOF
 }
 
@@ -100,7 +103,7 @@
   TOK type;
 //   Position pos;
 
-//   Token* next, prev;
+  Token* next, prev;
 
   char* start;
   char* end;
@@ -144,6 +147,20 @@
   {
     return type == type2;
   }
+
+  new(size_t size)
+  {
+    void* p = malloc(size);
+    if (p is null)
+      throw new OutOfMemoryException();
+    *cast(Token*)p = Token.init;
+    return p;
+  }
+
+  delete(void* p)
+  {
+    free(p);
+  }
 }
 
 string[] tokToString = [