Mercurial > projects > dil
annotate trunk/src/Parser.d @ 107:722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
- Added 'alias srcText identifier' to Token for Identifiers.
- Replaced all instances of token.srcText with token.identifier where applicable.
author | aziz |
---|---|
date | Sun, 08 Jul 2007 15:22:03 +0000 |
parents | 441962b0f526 |
children | 469188935d56 |
rev | line source |
---|---|
0 | 1 /++ |
2 Author: Aziz Köksal | |
3 License: GPL2 | |
4 +/ | |
65 | 5 module Parser; |
69
24db7c5522d5
- Added module Information for compiler messages like warnings, info and errors to the user.
aziz
parents:
68
diff
changeset
|
6 import Lexer; |
71 | 7 import Token; |
8 import Messages; | |
9 import Information; | |
102 | 10 import Declarations; |
11 import Statements; | |
70 | 12 import Expressions; |
94 | 13 import Types; |
65 | 14 |
95 | 15 |
16 class Argument | |
68
7eb83dd38901
- Simplified suffix rule and added a few more numbers to unittest.
aziz
parents:
65
diff
changeset
|
17 { |
95 | 18 StorageClass stc; |
19 Type type; | |
20 string ident; | |
21 Expression assignExpr; | |
22 | |
23 this(StorageClass stc, Type type, string ident, Expression assignExpr) | |
24 { | |
25 this.stc = stc; | |
26 this.type = type; | |
27 this.ident = ident; | |
28 this.assignExpr = assignExpr; | |
29 } | |
30 | |
31 bool isVariadic() | |
32 { | |
33 return !!(stc & StorageClass.Variadic); | |
34 } | |
35 | |
36 bool isOnlyVariadic() | |
37 { | |
38 return stc == StorageClass.Variadic; | |
39 } | |
68
7eb83dd38901
- Simplified suffix rule and added a few more numbers to unittest.
aziz
parents:
65
diff
changeset
|
40 } |
7eb83dd38901
- Simplified suffix rule and added a few more numbers to unittest.
aziz
parents:
65
diff
changeset
|
41 |
71 | 42 private alias TOK T; |
43 | |
65 | 44 class Parser |
45 { | |
71 | 46 Lexer lx; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
47 Token* token; |
71 | 48 |
49 Information[] errors; | |
50 | |
51 this(char[] srcText, string fileName) | |
52 { | |
53 lx = new Lexer(srcText, fileName); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
54 } |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
55 |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
56 void nT() |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
57 { |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
58 lx.nextToken(); |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
59 token = &lx.token; |
71 | 60 } |
70 | 61 |
102 | 62 void skipToOnePast(TOK tok) |
63 { | |
64 for (; token.type != tok && token.type != T.EOF; nT()) | |
65 {} | |
66 nT(); | |
67 } | |
105 | 68 |
106 | 69 ReturnType try_(ReturnType)(lazy ReturnType parseMethod, out bool failed) |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
70 { |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
71 auto len = errors.length; |
105 | 72 auto lexerState = lx.getState(); |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
73 auto result = parseMethod(); |
105 | 74 // If the length of the array changed we know an error occurred. |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
75 if (errors.length != len) |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
76 { |
105 | 77 lexerState.restore(); // Restore state of the Lexer object. |
78 errors = errors[0..len]; // Remove errors that were added when parseMethod() was called. | |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
79 failed = true; |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
80 } |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
81 return result; |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
82 } |
105 | 83 |
102 | 84 /++++++++++++++++++++++++++++++ |
85 + Declaration parsing methods + | |
86 ++++++++++++++++++++++++++++++/ | |
87 | |
88 Declaration[] parseModule() | |
89 { | |
90 Declaration[] decls; | |
91 | |
92 if (token.type == T.Module) | |
93 { | |
94 nT(); | |
95 string[] idents; | |
96 do | |
97 { | |
98 nT(); | |
99 if (token.type == T.Identifier) | |
100 { | |
101 nT(); | |
102 idents ~= token.srcText; | |
103 } | |
104 else | |
105 { | |
106 errorIfNot(T.Identifier); | |
107 skipToOnePast(T.Semicolon); | |
108 goto Lreturn; | |
109 } | |
110 } while (token.type == T.Dot) | |
111 require(T.Semicolon); | |
112 decls ~= new ModuleDeclaration(idents); | |
113 } | |
114 decls ~= parseDeclarations(); | |
115 Lreturn: | |
116 return decls; | |
117 } | |
118 | |
119 Declaration[] parseDeclarations() | |
120 { | |
121 Declaration[] decls; | |
122 while (token.type != T.EOF) | |
123 decls ~= parseDeclaration(); | |
124 return decls; | |
125 } | |
126 | |
127 Declaration parseDeclaration() | |
128 { | |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
129 Declaration decl; |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
130 switch (token.type) |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
131 { |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
132 case T.Extern, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
133 T.Align, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
134 T.Pragma, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
135 T.Deprecated, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
136 T.Private, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
137 T.Package, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
138 T.Protected, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
139 T.Public, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
140 T.Export, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
141 //T.Static, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
142 T.Final, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
143 T.Override, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
144 T.Abstract, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
145 T.Const, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
146 T.Auto, |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
147 T.Scope: |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
148 case_AttributeSpecifier: |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
149 decl = parseAttributeSpecifier(); |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
150 break; |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
151 case T.Static: |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
152 Token t; |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
153 lx.peek(t); |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
154 if (t.type != T.Import) |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
155 goto case_AttributeSpecifier; |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
156 //goto case T.Import; |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
157 case T.Import: |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
158 decl = parseImportDeclaration(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
159 case T.Enum: |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
160 decl = parseEnumDeclaration(); |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
161 case T.Module: |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
162 // Error: module is optional and can only appear once at the top of the source file. |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
163 default: |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
164 } |
102 | 165 return null; |
166 } | |
167 | |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
168 Declaration parseAttributeSpecifier() |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
169 { |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
170 // Attribute : |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
171 // Attribute DeclarationBlock |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
172 return null; |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
173 } |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
174 |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
175 Declaration parseImportDeclaration() |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
176 { |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
177 assert(token.type == T.Import || token.type == T.Static); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
178 |
103
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
179 Declaration decl; |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
180 bool isStatic; |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
181 |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
182 if (token.type == T.Static) |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
183 { |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
184 isStatic = true; |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
185 nT(); |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
186 } |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
187 |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
188 return decl; |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
189 } |
511a1aa25896
- Added reportErrors member to Lexer. Moved peek() down and rewrote it a bit making use of reportErrors. error() uses reportErrors too.
aziz
parents:
102
diff
changeset
|
190 |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
191 Declaration parseEnumDeclaration() |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
192 { |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
193 assert(token.type == T.Enum); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
194 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
195 string enumName; |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
196 Type baseType; |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
197 string[] members; |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
198 Expression[] values; |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
199 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
200 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
201 if (token.type == T.Identifier) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
202 { |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
203 enumName = token.srcText; |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
204 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
205 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
206 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
207 if (token.type == T.Colon) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
208 { |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
209 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
210 baseType = parseBasicType(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
211 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
212 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
213 if (token.type == T.LBrace) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
214 { |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
215 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
216 do |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
217 { |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
218 if (token.type == T.Identifier) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
219 { |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
220 members ~= token.identifier; |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
221 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
222 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
223 else |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
224 errorIfNot(T.Identifier); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
225 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
226 if (token.type == T.Assign) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
227 { |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
228 values ~= parseAssignExpression(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
229 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
230 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
231 else |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
232 values ~= null; |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
233 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
234 if (token.type == T.Comma) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
235 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
236 else if (token.type != T.RBrace) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
237 errorIfNot(T.RBrace); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
238 } while (token.type != T.RBrace) |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
239 nT(); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
240 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
241 |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
242 return new EnumDeclaration(enumName, baseType, members, values); |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
243 } |
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
244 |
102 | 245 /+++++++++++++++++++++++++++++ |
246 + Expression parsing methods + | |
247 +++++++++++++++++++++++++++++/ | |
248 | |
72 | 249 Expression parseExpression() |
250 { | |
251 auto e = parseAssignExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
252 while (token.type == TOK.Comma) |
81 | 253 e = new CommaExpression(e, parseAssignExpression()); |
72 | 254 return e; |
255 } | |
256 | |
71 | 257 Expression parseAssignExpression() |
258 { | |
259 auto e = parseCondExpression(); | |
72 | 260 while (1) |
71 | 261 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
262 switch (token.type) |
72 | 263 { |
264 case T.Assign: | |
265 nT(); e = new AssignExpression(e, parseAssignExpression()); | |
266 break; | |
267 case T.LShiftAssign: | |
268 nT(); e = new LShiftAssignExpression(e, parseAssignExpression()); | |
269 break; | |
270 case T.RShiftAssign: | |
271 nT(); e = new RShiftAssignExpression(e, parseAssignExpression()); | |
272 break; | |
273 case T.URShiftAssign: | |
274 nT(); e = new URShiftAssignExpression(e, parseAssignExpression()); | |
275 break; | |
276 case T.OrAssign: | |
277 nT(); e = new OrAssignExpression(e, parseAssignExpression()); | |
278 break; | |
279 case T.AndAssign: | |
280 nT(); e = new AndAssignExpression(e, parseAssignExpression()); | |
281 break; | |
282 case T.PlusAssign: | |
283 nT(); e = new PlusAssignExpression(e, parseAssignExpression()); | |
284 break; | |
285 case T.MinusAssign: | |
286 nT(); e = new MinusAssignExpression(e, parseAssignExpression()); | |
287 break; | |
288 case T.DivAssign: | |
289 nT(); e = new DivAssignExpression(e, parseAssignExpression()); | |
290 break; | |
291 case T.MulAssign: | |
292 nT(); e = new MulAssignExpression(e, parseAssignExpression()); | |
293 break; | |
294 case T.ModAssign: | |
295 nT(); e = new ModAssignExpression(e, parseAssignExpression()); | |
296 break; | |
297 case T.XorAssign: | |
298 nT(); e = new XorAssignExpression(e, parseAssignExpression()); | |
299 break; | |
300 case T.CatAssign: | |
301 nT(); e = new CatAssignExpression(e, parseAssignExpression()); | |
302 break; | |
303 default: | |
304 break; | |
305 } | |
71 | 306 break; |
307 } | |
308 return e; | |
309 } | |
72 | 310 |
71 | 311 Expression parseCondExpression() |
312 { | |
72 | 313 auto e = parseOrOrExpression(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
314 if (token.type == T.Question) |
72 | 315 { |
316 nT(); | |
317 auto iftrue = parseExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
318 require(T.Colon); |
72 | 319 auto iffalse = parseCondExpression(); |
320 e = new CondExpression(e, iftrue, iffalse); | |
321 } | |
322 return e; | |
323 } | |
324 | |
325 Expression parseOrOrExpression() | |
326 { | |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
327 alias parseAndAndExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
328 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
329 if (token.type == T.OrLogical) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
330 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
331 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
332 e = new OrOrExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
333 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
334 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
335 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
336 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
337 Expression parseAndAndExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
338 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
339 alias parseOrExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
340 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
341 if (token.type == T.AndLogical) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
342 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
343 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
344 e = new AndAndExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
345 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
346 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
347 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
348 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
349 Expression parseOrExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
350 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
351 alias parseXorExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
352 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
353 if (token.type == T.OrBinary) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
354 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
355 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
356 e = new OrExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
357 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
358 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
359 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
360 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
361 Expression parseXorExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
362 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
363 alias parseAndExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
364 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
365 if (token.type == T.Xor) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
366 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
367 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
368 e = new XorExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
369 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
370 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
371 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
372 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
373 Expression parseAndExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
374 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
375 alias parseCmpExpression parseNext; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
376 auto e = parseNext(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
377 if (token.type == T.AndBinary) |
73
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
378 { |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
379 nT(); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
380 e = new AndExpression(e, parseNext()); |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
381 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
382 return e; |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
383 } |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
384 |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
385 Expression parseCmpExpression() |
11572f4a138c
- Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents:
72
diff
changeset
|
386 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
387 TOK operator = token.type; |
74 | 388 |
389 auto e = parseShiftExpression(); | |
390 | |
391 switch (operator) | |
392 { | |
393 case T.Equal, T.NotEqual: | |
394 nT(); | |
395 e = new EqualExpression(e, parseShiftExpression(), operator); | |
396 break; | |
397 case T.Not: | |
398 Token t; | |
399 lx.peek(t); | |
400 if (t.type != T.Is) | |
401 break; | |
402 nT(); | |
403 operator = T.NotIdentity; | |
404 goto LNotIdentity; | |
405 case T.Identity: | |
406 operator = T.Identity; | |
407 LNotIdentity: | |
408 nT(); | |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
409 e = new IdentityExpression(e, parseShiftExpression(), operator); |
74 | 410 break; |
411 case T.LessEqual, T.Less, T.GreaterEqual, T.Greater, | |
412 T.Unordered, T.UorE, T.UorG, T.UorGorE, | |
413 T.UorL, T.UorLorE, T.LorEorG, T.LorG: | |
414 nT(); | |
415 e = new RelExpression(e, parseShiftExpression(), operator); | |
416 break; | |
417 case T.In: | |
418 nT(); | |
419 e = new InExpression(e, parseShiftExpression(), operator); | |
420 break; | |
421 default: | |
422 } | |
423 return e; | |
424 } | |
425 | |
426 Expression parseShiftExpression() | |
427 { | |
75 | 428 auto e = parseAddExpression(); |
429 while (1) | |
430 { | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
431 switch (token.type) |
75 | 432 { |
433 case T.LShift: nT(); e = new LShiftExpression(e, parseAddExpression()); break; | |
434 case T.RShift: nT(); e = new RShiftExpression(e, parseAddExpression()); break; | |
435 case T.URShift: nT(); e = new URShiftExpression(e, parseAddExpression()); break; | |
436 default: break; | |
437 } | |
438 break; | |
439 } | |
440 return e; | |
441 } | |
442 | |
443 Expression parseAddExpression() | |
444 { | |
76 | 445 auto e = parseMulExpression(); |
446 while (1) | |
447 { | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
448 switch (token.type) |
76 | 449 { |
450 case T.Plus: nT(); e = new PlusExpression(e, parseMulExpression()); break; | |
451 case T.Minus: nT(); e = new MinusExpression(e, parseMulExpression()); break; | |
452 case T.Tilde: nT(); e = new CatExpression(e, parseMulExpression()); break; | |
453 default: break; | |
454 } | |
455 break; | |
456 } | |
457 return new Expression(); | |
458 } | |
459 | |
460 Expression parseMulExpression() | |
461 { | |
77 | 462 auto e = parseUnaryExpression(); |
463 while (1) | |
464 { | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
465 switch (token.type) |
77 | 466 { |
467 case T.Mul: nT(); e = new MulExpression(e, parseUnaryExpression()); break; | |
468 case T.Div: nT(); e = new DivExpression(e, parseUnaryExpression()); break; | |
469 case T.Mod: nT(); e = new ModExpression(e, parseUnaryExpression()); break; | |
470 default: break; | |
471 } | |
472 break; | |
473 } | |
74 | 474 return new Expression(); |
71 | 475 } |
476 | |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
477 Expression parseUnaryExpression() |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
478 { |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
479 Expression e; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
480 switch (token.type) |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
481 { |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
482 case T.AndBinary: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
483 nT(); e = new AddressExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
484 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
485 case T.PlusPlus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
486 nT(); e = new PreIncrExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
487 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
488 case T.MinusMinus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
489 nT(); e = new PreDecrExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
490 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
491 case T.Mul: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
492 nT(); e = new DerefExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
493 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
494 case T.Minus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
495 case T.Plus: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
496 nT(); e = new SignExpression(parseUnaryExpression(), token.type); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
497 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
498 case T.Not: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
499 nT(); e = new NotExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
500 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
501 case T.Tilde: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
502 nT(); e = new CompExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
503 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
504 case T.New: |
102 | 505 // TODO: parseNewExpression(); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
506 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
507 case T.Delete: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
508 nT(); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
509 e = new DeleteExpression(parseUnaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
510 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
511 case T.Cast: |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
512 requireNext(T.LParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
513 auto type = parseType(); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
514 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
515 e = new CastExpression(parseUnaryExpression(), type); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
516 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
517 case T.LParen: |
102 | 518 // ( Type ) . Identifier |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
519 auto type = parseType(); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
520 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
521 require(T.Dot); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
522 string ident; |
102 | 523 if (token.type == T.Identifier) |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
524 { |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
525 ident = token.identifier; |
102 | 526 nT(); |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
527 } |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
528 else |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
529 errorIfNot(T.Identifier); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
530 e = new TypeDotIdExpression(type, ident); |
91
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
531 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
532 default: |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
533 e = parsePostExpression(parsePrimaryExpression()); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
534 break; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
535 } |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
536 assert(e !is null); |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
537 return e; |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
538 } |
ac8610aaf622
- Moved parseUnaryExpression() one place up in the method list.
aziz
parents:
90
diff
changeset
|
539 |
90
a02950cb7036
- Fixed order of parsing unary, post and primary expressions.
aziz
parents:
89
diff
changeset
|
540 Expression parsePostExpression(Expression e) |
77 | 541 { |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
542 while (1) |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
543 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
544 switch (token.type) |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
545 { |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
546 case T.Dot: |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
547 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
548 if (token.type == T.Identifier) |
92 | 549 { |
81 | 550 e = new DotIdExpression(e); |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
551 break; |
92 | 552 } |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
553 else if (token.type == T.New) |
81 | 554 e = parseNewExpression(e); |
92 | 555 else |
556 errorIfNot(T.Identifier); | |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
557 continue; |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
558 case T.PlusPlus: |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
559 e = new PostIncrExpression(e); |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
560 break; |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
561 case T.MinusMinus: |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
562 e = new PostDecrExpression(e); |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
563 break; |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
564 case T.LParen: |
81 | 565 e = new CallExpression(e, parseArgumentList(T.LParen)); |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
566 continue; |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
567 case T.LBracket: |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
568 // parse Slice- and IndexExpression |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
569 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
570 if (token.type == T.RBracket) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
571 { |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
572 e = new SliceExpression(e, null, null); |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
573 break; |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
574 } |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
575 |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
576 Expression[] es = [parseAssignExpression()]; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
577 |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
578 if (token.type == T.Slice) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
579 { |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
580 nT(); |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
581 e = new SliceExpression(e, es[0], parseAssignExpression()); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
582 require(T.RBracket); |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
583 continue; |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
584 } |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
585 else if (token.type == T.Comma) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
586 { |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
587 es ~= parseArgumentList(T.RBracket); |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
588 } |
85 | 589 else |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
590 require(T.RBracket); |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
591 |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
592 e = new IndexExpression(e, es); |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
593 continue; |
92 | 594 default: |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
595 return e; |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
596 } |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
597 nT(); |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
598 } |
93
9f8b6c205ecc
- Made fixes to the way the while loop in parsePostExpression() works.
aziz
parents:
92
diff
changeset
|
599 assert(0); |
79
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
600 } |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
601 |
df4e5c7ad58a
- Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents:
78
diff
changeset
|
602 Expression parsePrimaryExpression() |
78
f043759fb59a
- Added code to parseUnaryExpression(); not fully implemented.
aziz
parents:
77
diff
changeset
|
603 { |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
604 Expression e; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
605 switch (token.type) |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
606 { |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
607 case T.Identifier: |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
608 e = new IdentifierExpression(token.identifier); |
89 | 609 nT(); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
610 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
611 case T.Dot: |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
612 requireNext(T.Identifier); |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
613 e = new GlobalIdExpression(token.identifier); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
614 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
615 case T.This: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
616 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
617 e = new ThisExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
618 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
619 case T.Super: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
620 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
621 e = new SuperExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
622 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
623 case T.Null: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
624 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
625 e = new NullExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
626 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
627 case T.True, T.False: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
628 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
629 e = new BoolExpression(token.type == T.True ? true : false); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
630 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
631 case T.Dollar: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
632 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
633 e = new DollarExpression(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
634 break; |
97
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
635 case T.Int32, T.Int64, T.Uint32, T.Uint64: |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
636 nT(); |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
637 e = new IntNumberExpression(token.type, token.ulong_); |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
638 break; |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
639 case T.Float32, T.Float64, T.Float80, |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
640 T.Imaginary32, T.Imaginary64, T.Imaginary80: |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
641 nT(); |
1a83e5070a84
- Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents:
96
diff
changeset
|
642 e = new RealNumberExpression(token.type, token.real_); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
643 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
644 case T.CharLiteral, T.WCharLiteral, T.DCharLiteral: |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
645 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
646 e = new CharLiteralExpression(token.type); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
647 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
648 case T.String: |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
649 char[] buffer = token.str; |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
650 char postfix = token.pf; |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
651 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
652 while (token.type == T.String) |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
653 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
654 string tmp = token.str; |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
655 // if (postfix != token.pf) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
656 // error(); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
657 if (tmp.length > 1) |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
658 { |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
659 buffer[$-1] = tmp[0]; // replace '\0' |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
660 buffer ~= tmp[1..$]; // append the rest |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
661 } |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
662 nT(); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
663 } |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
664 e = new StringLiteralExpression(buffer); |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
665 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
666 case T.LBracket: |
85 | 667 Expression[] values; |
668 | |
669 nT(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
670 if (token.type != T.RBracket) |
85 | 671 { |
672 e = parseAssignExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
673 if (token.type == T.Colon) |
85 | 674 goto LparseAssocArray; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
675 else if (token.type == T.Comma) |
85 | 676 values = [e] ~ parseArgumentList(T.RBracket); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
677 else |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
678 require(T.RBracket); |
85 | 679 } |
680 | |
681 e = new ArrayLiteralExpression(values); | |
682 break; | |
683 | |
684 LparseAssocArray: | |
685 Expression[] keys; | |
686 | |
687 keys ~= e; | |
688 nT(); // Skip colon. | |
689 values ~= parseAssignExpression(); | |
690 | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
691 if (token.type != T.RBracket) |
88 | 692 { |
693 require(T.Comma); | |
85 | 694 while (1) |
695 { | |
696 keys ~= parseAssignExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
697 if (token.type != T.Colon) |
85 | 698 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
699 errorIfNot(T.Colon); |
85 | 700 values ~= null; |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
701 if (token.type == T.RBracket) |
85 | 702 break; |
703 else | |
704 continue; | |
705 } | |
706 nT(); | |
707 values ~= parseAssignExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
708 if (token.type == T.RBracket) |
85 | 709 break; |
88 | 710 require(T.Comma); |
85 | 711 } |
88 | 712 } |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
713 assert(token.type == T.RBracket); |
85 | 714 nT(); |
715 e = new AssocArrayLiteralExpression(keys, values); | |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
716 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
717 case T.LBrace: |
102 | 718 // TODO: parse delegate literals: FunctionBody |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
719 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
720 case T.Function, T.Delegate: |
102 | 721 // TODO: parse delegate/function literals: |
722 // function Type? ( ArgumentList ) FunctionBody | |
723 // function FunctionBody | |
724 // delegate Type? ( ArgumentList ) FunctionBody | |
725 // delegate FunctionBody | |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
726 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
727 case T.Assert: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
728 Expression msg; |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
729 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
730 e = parseAssignExpression(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
731 if (token.type == T.Comma) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
732 { |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
733 nT(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
734 msg = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
735 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
736 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
737 e = new AssertExpression(e, msg); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
738 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
739 case T.Mixin: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
740 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
741 e = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
742 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
743 e = new MixinExpression(e); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
744 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
745 case T.Import: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
746 requireNext(T.LParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
747 e = parseAssignExpression(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
748 require(T.RParen); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
749 e = new ImportExpression(e); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
750 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
751 case T.Typeid: |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
752 requireNext(T.LParen); |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
753 auto type = parseType(); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
754 require(T.RParen); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
755 e = new TypeidExpression(type); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
756 break; |
101 | 757 case T.Typeof: |
758 requireNext(T.LParen); | |
759 auto type = new TypeofType(parseExpression()); | |
760 require(T.RParen); | |
761 if (token.type == T.Dot) | |
762 { | |
763 nT(); | |
764 string ident; | |
765 if (token.type == T.Identifier) | |
766 { | |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
767 ident = token.identifier; |
102 | 768 nT(); |
101 | 769 } |
770 else | |
771 errorIfNot(T.Identifier); | |
772 e = new TypeDotIdExpression(type, ident); | |
773 } | |
774 else | |
775 e = new TypeofExpression(type); | |
776 break; | |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
777 case T.Is: |
100 | 778 requireNext(T.LParen); |
779 | |
780 Type type; | |
781 SpecializationType specType; | |
782 string ident; // optional Identifier | |
783 | |
784 type = parseDeclarator(ident, true); | |
785 | |
786 switch (token.type) | |
787 { | |
788 case T.Colon, T.Equal: | |
789 TOK specTok = token.type; | |
790 nT(); | |
791 switch (token.type) | |
792 { | |
793 case T.Typedef, | |
794 T.Struct, | |
795 T.Union, | |
796 T.Class, | |
797 T.Interface, | |
798 T.Enum, | |
799 T.Function, | |
800 T.Delegate, | |
801 T.Super, | |
802 T.Return: | |
102 | 803 nT(); |
100 | 804 specType = new SpecializationType(specTok, token.type); |
805 break; | |
806 default: | |
807 specType = new SpecializationType(specTok, parseType()); | |
808 } | |
809 default: | |
810 } | |
102 | 811 require(T.RParen); |
100 | 812 e = new IsExpression(type, ident, specType); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
813 break; |
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
814 case T.LParen: |
102 | 815 // TODO: parse ( ArgumentList ) FunctionBody type delegates |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
816 nT(); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
817 e = parseExpression(); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
818 require(T.RParen); |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
819 break; |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
820 // BasicType . Identifier |
94 | 821 case T.Void, T.Char, T.Wchar, T.Dchar, T.Bool, |
822 T.Byte, T.Ubyte, T.Short, T.Ushort, | |
823 T.Int, T.Uint, T.Long, T.Ulong, | |
824 T.Float, T.Double, T.Real, | |
825 T.Ifloat, T.Idouble, T.Ireal, | |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
826 T.Cfloat, T.Cdouble, T.Creal: |
94 | 827 auto type = new Type(token.type); |
88 | 828 |
94 | 829 requireNext(T.Dot); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
830 |
94 | 831 string ident; |
832 if (token.type == T.Identifier) | |
833 { | |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
834 ident = token.identifier; |
94 | 835 nT(); |
836 } | |
837 else | |
838 errorIfNot(T.Identifier); | |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
839 |
94 | 840 e = new TypeDotIdExpression(type, ident); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
841 break; |
84
ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents:
83
diff
changeset
|
842 default: |
102 | 843 // TODO: issue error msg and decide what to return. |
83
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
844 } |
9e6d66f647c9
- Fix: IsExpression was created instead of IdentityExpression.
aziz
parents:
81
diff
changeset
|
845 return e; |
77 | 846 } |
847 | |
81 | 848 Expression parseNewExpression(Expression e) |
849 { | |
102 | 850 // TODO: implement this method. |
81 | 851 return null; |
852 } | |
853 | |
854 Expression[] parseArgumentList(TOK terminator) | |
855 { | |
856 Expression[] es; | |
857 | |
858 nT(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
859 if (token.type == terminator) |
81 | 860 { |
861 nT(); | |
862 return null; | |
863 } | |
864 | |
865 while (1) | |
866 { | |
867 es ~= parseAssignExpression(); | |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
868 if (token.type == terminator) |
81 | 869 break; |
88 | 870 require(T.Comma); |
81 | 871 } |
872 nT(); | |
873 return es; | |
874 } | |
875 | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
876 Type parseType() |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
877 { |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
878 return parseBasicType2(parseBasicType()); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
879 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
880 |
94 | 881 Type parseBasicType() |
882 { | |
883 Type t; | |
884 IdentifierType tident; | |
885 | |
886 switch (token.type) | |
887 { | |
888 case T.Void, T.Char, T.Wchar, T.Dchar, T.Bool, | |
889 T.Byte, T.Ubyte, T.Short, T.Ushort, | |
890 T.Int, T.Uint, T.Long, T.Ulong, | |
891 T.Float, T.Double, T.Real, | |
892 T.Ifloat, T.Idouble, T.Ireal, | |
893 T.Cfloat, T.Cdouble, T.Creal: | |
894 t = new Type(token.type); | |
895 nT(); | |
896 break; | |
897 case T.Identifier, T.Dot: | |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
898 tident = new IdentifierType([token.identifier]); |
94 | 899 nT(); |
102 | 900 // TODO: parse template instance |
94 | 901 // if (token.type == T.Not) |
902 // parse template instance | |
903 Lident: | |
904 while (token.type == T.Dot) | |
905 { | |
906 nT(); | |
907 if (token.type == T.Identifier) | |
908 { | |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
909 tident ~= token.identifier; |
94 | 910 } |
911 else | |
912 errorIfNot(T.Identifier); | |
913 nT(); | |
102 | 914 // TODO: parse template instance |
94 | 915 // if (token.type == T.Not) |
916 // parse template instance | |
917 } | |
918 t = tident; | |
919 break; | |
920 case T.Typeof: | |
921 requireNext(T.LParen); | |
922 tident = new TypeofType(parseExpression()); | |
923 require(T.RParen); | |
924 goto Lident; | |
925 default: | |
102 | 926 // TODO: issue error msg and return UndefinedType. |
94 | 927 } |
928 return t; | |
929 } | |
930 | |
95 | 931 Type parseBasicType2(Type t) |
932 { | |
933 while (1) | |
934 { | |
935 switch (token.type) | |
936 { | |
937 case T.Mul: | |
938 t = new PointerType(t); | |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
939 nT(); |
95 | 940 break; |
941 case T.LBracket: | |
106 | 942 t = parseArrayType(t); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
943 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
944 case T.Function, T.Delegate: |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
945 TOK tok = token.type; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
946 nT(); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
947 auto args = parseParameters(); |
102 | 948 // TODO: create appropriate Type. |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
949 // if (tok == T.Function) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
950 // t = new FunctionType(); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
951 // else |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
952 // t = new DelegateType(); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
953 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
954 default: |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
955 return t; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
956 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
957 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
958 assert(0); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
959 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
960 |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
961 Type parseDeclaratorSuffix(Type t) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
962 { |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
963 while (1) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
964 { |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
965 switch (token.type) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
966 { |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
967 case T.LBracket: |
106 | 968 t = parseArrayType(t); |
95 | 969 continue; |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
970 case T.LParen: |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
971 auto params = parseParameters(); |
102 | 972 // TODO: create FunctionType. |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
973 // new FunctionType(params); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
974 break; |
100 | 975 default: |
976 break; | |
95 | 977 } |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
978 break; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
979 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
980 return t; |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
981 } |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
982 |
106 | 983 Type parseArrayType(Type t) |
984 { | |
985 assert(token.type == T.LBracket); | |
986 nT(); | |
987 if (token.type == T.RBracket) | |
988 { | |
989 t = new ArrayType(t); | |
990 nT(); | |
991 } | |
992 else | |
993 { | |
994 bool failed; | |
995 auto assocType = try_(parseType(), failed); | |
996 if (!failed) | |
997 t = new ArrayType(t, assocType); | |
998 else | |
999 { | |
1000 Expression e = parseExpression(), e2; | |
1001 if (token.type == T.Slice) | |
1002 { | |
1003 nT(); | |
1004 e2 = parseExpression(); | |
1005 } | |
1006 t = new ArrayType(t, e, e2); | |
1007 } | |
1008 require(T.RBracket); | |
1009 } | |
1010 return t; | |
1011 } | |
1012 | |
100 | 1013 Type parseDeclarator(ref string ident, bool identOptional = false) |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1014 { |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
1015 auto t = parseType(); |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1016 |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1017 if (token.type == T.Identifier) |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1018 { |
107
722c05bbd5eb
- Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents:
106
diff
changeset
|
1019 ident = token.identifier; |
95 | 1020 nT(); |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
1021 t = parseDeclaratorSuffix(t); |
95 | 1022 } |
100 | 1023 else if (!identOptional) |
98
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1024 errorIfNot(T.Identifier); |
aec3b16144fe
- Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents:
97
diff
changeset
|
1025 |
104
b535016f8c3f
- DeclaratorSuffix must be parsed after an Identifier.
aziz
parents:
103
diff
changeset
|
1026 return t; |
95 | 1027 } |
1028 | |
1029 Argument[] parseParameters() | |
96 | 1030 out(args) |
1031 { | |
1032 if (args.length > 1) | |
1033 foreach (arg; args[0..$-1]) | |
1034 { | |
1035 if (arg.isVariadic()) | |
1036 assert(0, "variadic arguments can only appear at the end of the parameter list."); | |
1037 } | |
1038 } | |
1039 body | |
95 | 1040 { |
1041 require(T.LParen); | |
1042 | |
1043 if (token.type == T.RParen) | |
1044 { | |
1045 nT(); | |
1046 return null; | |
1047 } | |
1048 | |
1049 Argument[] args; | |
1050 StorageClass stc; | |
1051 | |
1052 while (1) | |
1053 { | |
1054 stc = StorageClass.In; | |
1055 switch (token.type) | |
1056 { | |
1057 case T.In: stc = StorageClass.In; nT(); goto default; | |
1058 case T.Out: stc = StorageClass.Out; nT(); goto default; | |
1059 case T.Ref: stc = StorageClass.Ref; nT(); goto default; | |
1060 case T.Lazy: stc = StorageClass.Lazy; nT(); goto default; | |
1061 case T.Ellipses: | |
1062 args ~= new Argument(StorageClass.Variadic, null, null, null); | |
1063 break; | |
1064 default: | |
1065 string ident; | |
99
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1066 auto type = parseDeclarator(ident); |
6b8c248f5911
- Added member type to classes CastExpression and TypeidExpression.
aziz
parents:
98
diff
changeset
|
1067 |
95 | 1068 Expression assignExpr; |
1069 if (token.type == T.Assign) | |
1070 { | |
1071 nT(); | |
1072 assignExpr = parseAssignExpression(); | |
1073 } | |
1074 | |
1075 if (token.type == T.Ellipses) | |
1076 { | |
1077 stc |= StorageClass.Variadic; | |
1078 args ~= new Argument(stc, type, ident, assignExpr); | |
1079 nT(); | |
1080 break; | |
1081 } | |
1082 | |
1083 args ~= new Argument(stc, type, ident, assignExpr); | |
1084 if (token.type == T.Comma) | |
1085 { | |
1086 nT(); | |
1087 continue; | |
1088 } | |
1089 break; | |
1090 } | |
1091 break; | |
1092 } | |
1093 require(T.RParen); | |
1094 return args; | |
1095 } | |
1096 | |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1097 void errorIfNot(TOK tok) |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1098 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1099 if (token.type != tok) |
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1100 error(MID.ExpectedButFound, tok, token.srcText); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1101 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1102 |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1103 void require(TOK tok) |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1104 { |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1105 if (token.type == tok) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1106 nT(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1107 else |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1108 error(MID.ExpectedButFound, tok, token.srcText); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1109 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1110 |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1111 void requireNext(TOK tok) |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1112 { |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1113 nT(); |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1114 if (token.type == tok) |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1115 nT(); |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1116 else |
87
c9544b7d5c7d
- Added member token and method nT(), which sets token to lx.token.
aziz
parents:
86
diff
changeset
|
1117 error(MID.ExpectedButFound, tok, token.srcText); |
86
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1118 } |
0459c902a370
- Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents:
85
diff
changeset
|
1119 |
71 | 1120 void error(MID id, ...) |
1121 { | |
94 | 1122 errors ~= new Information(InfoType.Parser, id, lx.loc, arguments(_arguments, _argptr)); |
71 | 1123 } |
65 | 1124 } |