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