1 using System;
2 using System.Collections;
3
4
5
6
7
8 namespace System.Lex
9 {
10 public class Lexeme
11 {
12 public Lexeme() :
13 begin(null), end(null)
14 {
15 }
16 public Lexeme(const uchar* begin_, const uchar* end_) :
17 begin(begin_), end(end_)
18 {
19 }
20 public ustring ToString() const
21 {
22 return ustring(begin, end);
23 }
24 public const uchar* begin;
25 public const uchar* end;
26 }
27 public inline bool operator==(const Lexeme& left, const Lexeme& right)
28 {
29 if (left.end - left.begin != right.end - right.begin) return false;
30 const uchar* p = left.begin;
31 const uchar* q = right.begin;
32 while (p != left.end)
33 {
34 if (*p != *q) return false;
35 ++p;
36 ++q;
37 }
38 return true;
39 }
40 public inline bool operator<(const Lexeme& left, const Lexeme& right)
41 {
42 const uchar* p = left.begin;
43 const uchar* q = right.begin;
44 while (p != left.end && q != right.end)
45 {
46 if (*p < *q) return true;
47 if (*p > *q) return false;
48 ++p;
49 ++q;
50 }
51 if (p == left.end) return q != right.end;
52 return false;
53 }
54 }