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