Mercurial > projects > dang
annotate lexer/Token.d @ 5:2c5a8f4c254a
Added very simple if support.
* No else
* Still no logical operators, always tests != 0
author | Anders Halager <halager@gmail.com> |
---|---|
date | Fri, 18 Apr 2008 11:46:00 +0200 |
parents | 2168f4cb73f1 |
children | 606a57c90a0b |
rev | line source |
---|---|
1 | 1 module lexer.Token; |
2 | |
3 public | |
4 import misc.Location; | |
5 | |
6 import Integer = tango.text.convert.Integer; | |
7 | |
8 struct Token | |
9 { | |
10 Tok type; | |
11 Location location; | |
12 uint length; | |
13 | |
14 static Token opCall (Tok type, Location location, uint length) | |
15 { | |
16 Token t; | |
17 t.type = type; | |
18 t.location = location; | |
19 t.length = length; | |
20 return t; | |
21 } | |
22 | |
23 char[] getType () | |
24 { | |
25 return typeToString[this.type]; | |
26 } | |
27 | |
28 char[] toString () | |
29 { | |
30 return this.getType()~": Len: "~Integer.toString(this.length) | |
31 ~", Loc: "~location.toString; | |
32 } | |
33 | |
34 char[] get () | |
35 { | |
36 return location.get(length); | |
37 } | |
38 } | |
39 | |
40 enum Tok : ushort | |
41 { | |
42 /* Non-code related tokens */ | |
43 EOF, | |
44 | |
45 /* Basic types */ | |
46 Identifier, | |
47 Integer, | |
48 | |
49 /* Basic operators */ | |
50 Assign, | |
51 Add, Sub, | |
52 Mul, Div, | |
53 Comma, | |
54 | |
55 /* Symbols */ | |
56 OpenParentheses, | |
57 CloseParentheses, | |
58 OpenBrace, | |
59 CloseBrace, | |
60 Seperator, | |
61 | |
62 /* Keywords */ | |
63 Byte, Ubyte, | |
64 Short, Ushort, | |
65 Int, Uint, | |
66 Long, Ulong, | |
67 | |
68 Float, Double, | |
69 | |
5
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
70 Bool, |
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
71 |
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
72 If, |
1 | 73 Return, |
74 | |
75 } | |
76 | |
77 public char[][Tok] typeToString; | |
78 | |
79 static this() | |
80 { | |
81 typeToString = | |
82 [ | |
83 Tok.EOF:"EOF"[], | |
84 Tok.Identifier:"Identifier", | |
85 Tok.Byte:"Byte", | |
86 Tok.Short:"Short", | |
87 Tok.Int:"Int", | |
88 Tok.Long:"Long", | |
5
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
89 Tok.Bool:"Bool", |
1 | 90 Tok.OpenParentheses:"OpenParentheses", |
91 Tok.CloseParentheses:"CloseParentheses", | |
92 Tok.OpenBrace:"OpenBrace", | |
93 Tok.CloseBrace:"CloseBrace", | |
94 Tok.Assign:"Assign", | |
95 Tok.Add:"Add", | |
96 Tok.Sub:"Sub", | |
97 Tok.Mul:"Mul", | |
98 Tok.Div:"Div", | |
5
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
99 Tok.Integer:"Integer", |
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
100 Tok.If:"If", |
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
101 Tok.Return:"Return", |
1 | 102 Tok.Seperator:"Seperator" |
103 ]; | |
104 } |