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