annotate trunk/src/dil/Parser.d @ 483:180711cc4b66

Fixed parsing of C-style function pointers. Renamed some labels. Added calls to set().
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sun, 25 Nov 2007 20:48:10 +0100
parents cac9c8d637ad
children 265c0b655f18
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
8ba2570de175 Initial import.
aziz
parents:
diff changeset
1 /++
8ba2570de175 Initial import.
aziz
parents:
diff changeset
2 Author: Aziz Köksal
249
32d354584b28 - Upgraded license notices to GPL3.
aziz
parents: 248
diff changeset
3 License: GPL3
0
8ba2570de175 Initial import.
aziz
parents:
diff changeset
4 +/
326
4a7359b88c11 - Added package 'dil' to module declarations.
aziz
parents: 325
diff changeset
5 module dil.Parser;
327
a48a987f7515 - Added package dil to import declarations.
aziz
parents: 326
diff changeset
6 import dil.Lexer;
a48a987f7515 - Added package dil to import declarations.
aziz
parents: 326
diff changeset
7 import dil.SyntaxTree;
a48a987f7515 - Added package dil to import declarations.
aziz
parents: 326
diff changeset
8 import dil.Token;
a48a987f7515 - Added package dil to import declarations.
aziz
parents: 326
diff changeset
9 import dil.Messages;
a48a987f7515 - Added package dil to import declarations.
aziz
parents: 326
diff changeset
10 import dil.Information;
a48a987f7515 - Added package dil to import declarations.
aziz
parents: 326
diff changeset
11 import dil.Declarations;
a48a987f7515 - Added package dil to import declarations.
aziz
parents: 326
diff changeset
12 import dil.Statements;
a48a987f7515 - Added package dil to import declarations.
aziz
parents: 326
diff changeset
13 import dil.Expressions;
a48a987f7515 - Added package dil to import declarations.
aziz
parents: 326
diff changeset
14 import dil.Types;
391
33b566df6af4 Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 379
diff changeset
15 import common;
65
6c21ae79fbb3 - Renamed function Token.span to Token.srcText.
aziz
parents: 0
diff changeset
16
71
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
17 private alias TOK T;
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
18
368
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
19 class ImportParser : Parser
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
20 {
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
21 this(char[] srcText, string fileName)
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
22 {
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
23 super(srcText, fileName);
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
24 }
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
25
369
27767e203d64 - Added override attribute to ImportParser.start().
aziz
parents: 368
diff changeset
26 override Declarations start()
368
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
27 {
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
28 auto decls = new Declarations;
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
29 super.init();
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
30 if (token.type == T.Module)
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
31 decls ~= parseModuleDeclaration();
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
32 while (token.type != T.EOF)
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
33 {
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
34 if (token.type == T.Import)
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
35 {
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
36 auto decl = parseImportDeclaration();
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
37 assert(decl && decl.kind == NodeKind.ImportDeclaration);
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
38 super.imports ~= cast(ImportDeclaration)cast(void*)decl;
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
39 decls ~= decl;
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
40 }
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
41 else
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
42 nT();
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
43 }
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
44 return decls;
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
45 }
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
46 }
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
47
65
6c21ae79fbb3 - Renamed function Token.span to Token.srcText.
aziz
parents: 0
diff changeset
48 class Parser
6c21ae79fbb3 - Renamed function Token.span to Token.srcText.
aziz
parents: 0
diff changeset
49 {
71
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
50 Lexer lx;
318
a1c9d93a66e3 - Added member prevToken to Parser.
aziz
parents: 314
diff changeset
51 Token* token; /// Current non-whitespace token.
a1c9d93a66e3 - Added member prevToken to Parser.
aziz
parents: 314
diff changeset
52 Token* prevToken; /// Previous non-whitespace token.
71
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
53
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
54 Information[] errors;
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
55
364
1059295c2727 - Every command module has an execute method now.
aziz
parents: 359
diff changeset
56 ImportDeclaration[] imports;
1059295c2727 - Every command module has an execute method now.
aziz
parents: 359
diff changeset
57
423
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
58 this(char[] srcText, string filePath)
71
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
59 {
423
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
60 lx = new Lexer(srcText, filePath);
87
c9544b7d5c7d - Added member token and method nT(), which sets token to lx.token.
aziz
parents: 86
diff changeset
61 }
c9544b7d5c7d - Added member token and method nT(), which sets token to lx.token.
aziz
parents: 86
diff changeset
62
368
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
63 private void init()
206
f9f5c0949a06 - Added method start().
aziz
parents: 205
diff changeset
64 {
f9f5c0949a06 - Added method start().
aziz
parents: 205
diff changeset
65 nT();
318
a1c9d93a66e3 - Added member prevToken to Parser.
aziz
parents: 314
diff changeset
66 prevToken = token;
206
f9f5c0949a06 - Added method start().
aziz
parents: 205
diff changeset
67 }
f9f5c0949a06 - Added method start().
aziz
parents: 205
diff changeset
68
87
c9544b7d5c7d - Added member token and method nT(), which sets token to lx.token.
aziz
parents: 86
diff changeset
69 void nT()
c9544b7d5c7d - Added member token and method nT(), which sets token to lx.token.
aziz
parents: 86
diff changeset
70 {
318
a1c9d93a66e3 - Added member prevToken to Parser.
aziz
parents: 314
diff changeset
71 prevToken = token;
132
c97a3f683d13 - Skipping comments in nT().
aziz
parents: 131
diff changeset
72 do
c97a3f683d13 - Skipping comments in nT().
aziz
parents: 131
diff changeset
73 {
c97a3f683d13 - Skipping comments in nT().
aziz
parents: 131
diff changeset
74 lx.nextToken();
239
7911f6a92e6e - Added 'new' and 'delete' declarations to Token and uncommented next and prev members. Added HEAD to TOK.
aziz
parents: 238
diff changeset
75 token = lx.token;
314
ebd21bbf296e - Added Whitespace, Sheband and Hashline to enum TOK. TOK.Whitespace is a flag and tokens that are considered whitespace are flagged as such.
aziz
parents: 313
diff changeset
76 } while (token.isWhitespace) // Skip whitespace
71
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
77 }
423
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
78 /+
102
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
79 void skipToOnePast(TOK tok)
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
80 {
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
81 for (; token.type != tok && token.type != T.EOF; nT())
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
82 {}
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
83 nT();
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
84 }
423
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
85 +/
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
86 uint trying;
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
87 uint errorCount;
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
88
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
89 /++
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
90 This method executes the delegate parseMethod and when an error occurred
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
91 the state of the lexer and parser are restored.
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
92 +/
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
93 ReturnType try_(ReturnType)(ReturnType delegate() parseMethod, out bool success)
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
94 {
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
95 ++trying;
423
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
96 auto oldToken = this.token;
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
97 auto oldPrevToken = this.prevToken;
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
98 auto oldCount = this.errorCount;
434
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
99 auto lexerState = this.lx.getState();
423
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
100
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
101 auto result = parseMethod();
423
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
102
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
103 // Check if an error occurred.
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
104 if (errorCount != oldCount)
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
105 {
423
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
106 // Restore members.
434
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
107 lx.restoreState(lexerState);
423
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
108 token = oldToken;
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
109 prevToken = oldPrevToken;
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
110 lx.token = oldToken;
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
111 errorCount = oldCount;
214
45fc474c1678 - Changed 'failed' parameter of try_() to 'success'.
aziz
parents: 213
diff changeset
112 success = false;
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
113 }
214
45fc474c1678 - Changed 'failed' parameter of try_() to 'success'.
aziz
parents: 213
diff changeset
114 else
45fc474c1678 - Changed 'failed' parameter of try_() to 'success'.
aziz
parents: 213
diff changeset
115 success = true;
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
116 --trying;
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
117 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
118 }
105
df34ec47fb81 - Added getState() method and State struct to Lexer.
aziz
parents: 104
diff changeset
119
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
120 Class set(Class)(Class node, Token* begin)
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
121 {
318
a1c9d93a66e3 - Added member prevToken to Parser.
aziz
parents: 314
diff changeset
122 node.setTokens(begin, this.prevToken);
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
123 return node;
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
124 }
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
125
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
126 TOK peekNext()
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
127 {
434
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
128 auto state = lx.getState();
239
7911f6a92e6e - Added 'new' and 'delete' declarations to Token and uncommented next and prev members. Added HEAD to TOK.
aziz
parents: 238
diff changeset
129 Token* next = token;
296
3a2afc425ceb - Fix in peekNext(): need to skip comments.
aziz
parents: 295
diff changeset
130 do
3a2afc425ceb - Fix in peekNext(): need to skip comments.
aziz
parents: 295
diff changeset
131 lx.peek(next);
314
ebd21bbf296e - Added Whitespace, Sheband and Hashline to enum TOK. TOK.Whitespace is a flag and tokens that are considered whitespace are flagged as such.
aziz
parents: 313
diff changeset
132 while (next.isWhitespace) // Skip whitespace
434
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
133 lx.restoreState(state);
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
134 return next.type;
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
135 }
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
136
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
137 TOK peekAfter(ref Token* next)
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
138 {
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
139 assert(next !is null);
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
140 auto state = lx.getState();
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
141 do
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
142 lx.peek(next);
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
143 while (next.isWhitespace) // Skip whitespace
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
144 lx.restoreState(state);
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
145 return next.type;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
146 }
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
147
102
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
148 /++++++++++++++++++++++++++++++
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
149 + Declaration parsing methods +
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
150 ++++++++++++++++++++++++++++++/
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
151
368
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
152 Declarations start()
102
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
153 {
368
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
154 init();
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 304
diff changeset
155 auto decls = new Declarations;
102
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
156 if (token.type == T.Module)
368
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
157 decls ~= parseModuleDeclaration();
110
2fb631daaaae - Renamed methods.
aziz
parents: 109
diff changeset
158 decls ~= parseDeclarationDefinitions();
102
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
159 return decls;
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
160 }
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
161
368
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
162 Declaration parseModuleDeclaration()
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
163 {
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
164 auto begin = token;
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
165 ModuleFQN moduleFQN;
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
166 do
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
167 {
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
168 nT();
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
169 moduleFQN ~= requireId();
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
170 } while (token.type == T.Dot)
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
171 require(T.Semicolon);
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
172 return set(new ModuleDeclaration(moduleFQN), begin);
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
173 }
2adf808343d6 - Renamed method start() to init() in Parser.
aziz
parents: 367
diff changeset
174
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 304
diff changeset
175 Declarations parseDeclarationDefinitions()
102
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
176 {
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 304
diff changeset
177 auto decls = new Declarations;
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
178 while (token.type != T.EOF)
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
179 decls ~= parseDeclarationDefinition();
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
180 return decls;
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
181 }
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
182
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
183 /*
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
184 DeclDefsBlock:
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
185 { }
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
186 { DeclDefs }
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
187 */
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 304
diff changeset
188 Declarations parseDeclarationDefinitionsBlock()
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
189 {
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 304
diff changeset
190 auto decls = new Declarations;
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
191 require(T.LBrace);
122
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
192 while (token.type != T.RBrace && token.type != T.EOF)
161
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
193 decls ~= parseDeclarationDefinition();
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
194 require(T.RBrace);
102
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
195 return decls;
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
196 }
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
197
110
2fb631daaaae - Renamed methods.
aziz
parents: 109
diff changeset
198 Declaration parseDeclarationDefinition()
102
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
199 {
262
0f22269e76ff - Changed some string types to Token*.
aziz
parents: 261
diff changeset
200 auto begin = token;
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
201 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
202 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
203 {
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
204 case T.Align,
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
205 T.Pragma,
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
206 // Protection attributes
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
207 T.Export,
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
208 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
209 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
210 T.Protected,
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
211 T.Public:
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
212 decl = parseAttributeSpecifier();
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
213 break;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
214 // Storage classes
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
215 case T.Extern,
203
4f949a3a394b - synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents: 202
diff changeset
216 T.Deprecated,
4f949a3a394b - synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents: 202
diff changeset
217 T.Override,
4f949a3a394b - synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents: 202
diff changeset
218 T.Abstract,
4f949a3a394b - synchronized is parsed as an Attribute in parseDeclarationDefinition() now.
aziz
parents: 202
diff changeset
219 T.Synchronized,
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
220 //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
221 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
222 T.Const,
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
223 //T.Invariant, // D 2.0
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
224 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
225 T.Scope:
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
226 case_StaticAttribute:
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
227 case_InvariantAttribute: // D 2.0
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
228 decl = parseStorageAttribute();
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
229 break;
191
3ce110cefbc5 - Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents: 190
diff changeset
230 case T.Alias:
3ce110cefbc5 - Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents: 190
diff changeset
231 nT();
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
232 // TODO: parse StorageClasses?
226
aa38e1401217 - Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents: 225
diff changeset
233 decl = new AliasDeclaration(parseDeclaration());
191
3ce110cefbc5 - Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents: 190
diff changeset
234 break;
3ce110cefbc5 - Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents: 190
diff changeset
235 case T.Typedef:
3ce110cefbc5 - Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents: 190
diff changeset
236 nT();
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
237 // TODO: parse StorageClasses?
226
aa38e1401217 - Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents: 225
diff changeset
238 decl = new TypedefDeclaration(parseDeclaration());
191
3ce110cefbc5 - Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents: 190
diff changeset
239 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
240 case T.Static:
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
241 switch (peekNext())
125
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
242 {
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
243 case T.Import:
429
052cbacb1642 Fix: removed infinite loop when parsing static imports.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 424
diff changeset
244 goto case_Import;
125
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
245 case T.This:
119
363cd39022f9 - Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents: 118
diff changeset
246 decl = parseStaticConstructorDeclaration();
125
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
247 break;
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
248 case T.Tilde:
119
363cd39022f9 - Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents: 118
diff changeset
249 decl = parseStaticDestructorDeclaration();
125
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
250 break;
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
251 case T.If:
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
252 decl = parseStaticIfDeclaration();
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
253 break;
127
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
254 case T.Assert:
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
255 decl = parseStaticAssertDeclaration();
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
256 break;
125
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
257 default:
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
258 goto case_StaticAttribute;
125
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
259 }
228
a4c5ee9527b7 - Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents: 227
diff changeset
260 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
261 case T.Import:
429
052cbacb1642 Fix: removed infinite loop when parsing static imports.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 424
diff changeset
262 case_Import:
107
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
263 decl = parseImportDeclaration();
364
1059295c2727 - Every command module has an execute method now.
aziz
parents: 359
diff changeset
264 assert(decl && decl.kind == NodeKind.ImportDeclaration);
1059295c2727 - Every command module has an execute method now.
aziz
parents: 359
diff changeset
265 imports ~= cast(ImportDeclaration)cast(void*)decl;
109
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
266 break;
107
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
267 case T.Enum:
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
268 decl = parseEnumDeclaration();
109
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
269 break;
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
270 case T.Class:
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
271 decl = parseClassDeclaration();
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
272 break;
112
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
273 case T.Interface:
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
274 decl = parseInterfaceDeclaration();
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
275 break;
113
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
276 case T.Struct, T.Union:
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
277 decl = parseAggregateDeclaration();
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
278 break;
117
79857de26e86 - Moved class Parameter to module Types. Added struct Parameters.
aziz
parents: 116
diff changeset
279 case T.This:
79857de26e86 - Moved class Parameter to module Types. Added struct Parameters.
aziz
parents: 116
diff changeset
280 decl = parseConstructorDeclaration();
79857de26e86 - Moved class Parameter to module Types. Added struct Parameters.
aziz
parents: 116
diff changeset
281 break;
118
379f33cbd521 - Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents: 117
diff changeset
282 case T.Tilde:
379f33cbd521 - Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents: 117
diff changeset
283 decl = parseDestructorDeclaration();
379f33cbd521 - Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents: 117
diff changeset
284 break;
120
e5329dac0405 - Added parseInvariantDeclaration().
aziz
parents: 119
diff changeset
285 case T.Invariant:
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
286 version(D2)
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
287 {
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
288 auto next = token;
434
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
289 if (peekAfter(next) == T.LParen)
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
290 {
434
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
291 if (peekAfter(next) != T.RParen)
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
292 goto case_Declaration;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
293 }
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
294 else
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
295 goto case_InvariantAttribute;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
296 }
120
e5329dac0405 - Added parseInvariantDeclaration().
aziz
parents: 119
diff changeset
297 decl = parseInvariantDeclaration();
e5329dac0405 - Added parseInvariantDeclaration().
aziz
parents: 119
diff changeset
298 break;
121
030933c6b5f0 - Added parseUnittestDeclaration().
aziz
parents: 120
diff changeset
299 case T.Unittest:
030933c6b5f0 - Added parseUnittestDeclaration().
aziz
parents: 120
diff changeset
300 decl = parseUnittestDeclaration();
030933c6b5f0 - Added parseUnittestDeclaration().
aziz
parents: 120
diff changeset
301 break;
122
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
302 case T.Debug:
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
303 decl = parseDebugDeclaration();
140
64d7186b087c - Implemented parseTemplateParameters().
aziz
parents: 139
diff changeset
304 break;
146
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
305 case T.Version:
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
306 decl = parseVersionDeclaration();
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
307 break;
140
64d7186b087c - Implemented parseTemplateParameters().
aziz
parents: 139
diff changeset
308 case T.Template:
64d7186b087c - Implemented parseTemplateParameters().
aziz
parents: 139
diff changeset
309 decl = parseTemplateDeclaration();
64d7186b087c - Implemented parseTemplateParameters().
aziz
parents: 139
diff changeset
310 break;
141
7ab33ee1a641 - Implemented parseNew- and DeleteDeclaration().
aziz
parents: 140
diff changeset
311 case T.New:
7ab33ee1a641 - Implemented parseNew- and DeleteDeclaration().
aziz
parents: 140
diff changeset
312 decl = parseNewDeclaration();
7ab33ee1a641 - Implemented parseNew- and DeleteDeclaration().
aziz
parents: 140
diff changeset
313 break;
7ab33ee1a641 - Implemented parseNew- and DeleteDeclaration().
aziz
parents: 140
diff changeset
314 case T.Delete:
7ab33ee1a641 - Implemented parseNew- and DeleteDeclaration().
aziz
parents: 140
diff changeset
315 decl = parseDeleteDeclaration();
7ab33ee1a641 - Implemented parseNew- and DeleteDeclaration().
aziz
parents: 140
diff changeset
316 break;
146
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
317 case T.Mixin:
256
8f27920ae17a - Made parseMixinDeclaration() a template.
aziz
parents: 255
diff changeset
318 decl = parseMixin!(MixinDeclaration)();
146
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
319 break;
129
a9244d409652 - Added class EmptyDeclaration.
aziz
parents: 128
diff changeset
320 case T.Semicolon:
a9244d409652 - Added class EmptyDeclaration.
aziz
parents: 128
diff changeset
321 nT();
a9244d409652 - Added class EmptyDeclaration.
aziz
parents: 128
diff changeset
322 decl = new EmptyDeclaration();
a9244d409652 - Added class EmptyDeclaration.
aziz
parents: 128
diff changeset
323 break;
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
324 // Declaration
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
325 case T.Identifier, T.Dot, T.Typeof:
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
326 // IntegralType
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
327 case T.Char, T.Wchar, T.Dchar, T.Bool,
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
328 T.Byte, T.Ubyte, T.Short, T.Ushort,
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
329 T.Int, T.Uint, T.Long, T.Ulong,
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
330 T.Float, T.Double, T.Real,
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
331 T.Ifloat, T.Idouble, T.Ireal,
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
332 T.Cfloat, T.Cdouble, T.Creal, T.Void:
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
333 case_Declaration:
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
334 return parseDeclaration();
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
335 /+case T.Module:
150
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
336 // TODO: Error: module is optional and can appear only once at the top of the source file.
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
337 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
338 default:
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
339 error(MID.ExpectedButFound, "Declaration", token.srcText);
292
076152e945e0 - Added member Node[] children to class Node.
aziz
parents: 291
diff changeset
340 decl = new IllegalDeclaration(token);
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
341 nT();
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
342 }
262
0f22269e76ff - Changed some string types to Token*.
aziz
parents: 261
diff changeset
343 set(decl, begin);
129
a9244d409652 - Added class EmptyDeclaration.
aziz
parents: 128
diff changeset
344 return decl;
102
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
345 }
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
346
122
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
347 /*
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
348 DeclarationsBlock:
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
349 : DeclDefs
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
350 { }
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
351 { DeclDefs }
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
352 DeclDef
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
353 */
404
fe46b5ea7a18 Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 400
diff changeset
354 Declaration parseDeclarationsBlock(bool noColon = false)
122
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
355 {
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 304
diff changeset
356 Declaration d;
122
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
357 switch (token.type)
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
358 {
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
359 case T.LBrace:
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 304
diff changeset
360 d = parseDeclarationDefinitionsBlock();
122
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
361 break;
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
362 case T.Colon:
404
fe46b5ea7a18 Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 400
diff changeset
363 if (noColon == true)
fe46b5ea7a18 Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 400
diff changeset
364 goto default;
122
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
365 nT();
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 304
diff changeset
366 auto decls = new Declarations;
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
367 while (token.type != T.RBrace && token.type != T.EOF)
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
368 decls ~= parseDeclarationDefinition();
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 304
diff changeset
369 d = decls;
122
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
370 break;
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
371 default:
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 304
diff changeset
372 d = parseDeclarationDefinition();
122
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
373 }
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 304
diff changeset
374 return d;
122
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
375 }
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
376
404
fe46b5ea7a18 Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 400
diff changeset
377 Declaration parseDeclarationsBlockNoColon()
fe46b5ea7a18 Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 400
diff changeset
378 {
fe46b5ea7a18 Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 400
diff changeset
379 return parseDeclarationsBlock(true);
fe46b5ea7a18 Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 400
diff changeset
380 }
fe46b5ea7a18 Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 400
diff changeset
381
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
382 /++
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
383 Parses either a VariableDeclaration or a FunctionDeclaration.
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
384 Params:
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
385 stc = the previously parsed storage classes
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
386 optionalParameterList = a hint for how to parse C-style function pointers
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
387 +/
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
388 Declaration parseDeclaration(StorageClass stc = StorageClass.None, bool optionalParameterList = true)
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
389 {
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
390 auto begin = token;
202
8aecf8925c5f - Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents: 201
diff changeset
391 Type type;
262
0f22269e76ff - Changed some string types to Token*.
aziz
parents: 261
diff changeset
392 Token* ident;
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
393
202
8aecf8925c5f - Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents: 201
diff changeset
394 // Check for AutoDeclaration
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
395 if (stc != StorageClass.None &&
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
396 token.type == T.Identifier &&
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
397 peekNext() == T.Assign)
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
398 {
262
0f22269e76ff - Changed some string types to Token*.
aziz
parents: 261
diff changeset
399 ident = token;
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
400 nT();
202
8aecf8925c5f - Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents: 201
diff changeset
401 }
8aecf8925c5f - Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents: 201
diff changeset
402 else
8aecf8925c5f - Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents: 201
diff changeset
403 {
8aecf8925c5f - Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents: 201
diff changeset
404 type = parseType();
8aecf8925c5f - Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents: 201
diff changeset
405 if (token.type == T.LParen)
8aecf8925c5f - Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents: 201
diff changeset
406 {
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
407 // C-style function pointers make the grammar ambiguous.
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
408 // We have to treat them specially at function scope.
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
409 // Example:
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
410 // void foo() {
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
411 // // A pointer to a function taking an integer and returning 'some_type'.
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
412 // some_type (*p_func)(int);
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
413 // // In the following case precedence is given to a CallExpression.
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
414 // something(*p); // 'something' may be a function/method or an object having opCall overloaded.
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
415 // }
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
416 // // A pointer to a function taking no parameters and returning 'something'.
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
417 // something(*p);
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
418 type = parseCFunctionPointerType(type, ident, optionalParameterList);
415
b18b0cd8f8cd Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 414
diff changeset
419 }
b18b0cd8f8cd Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 414
diff changeset
420 else
b18b0cd8f8cd Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 414
diff changeset
421 {
b18b0cd8f8cd Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 414
diff changeset
422 ident = requireId();
b18b0cd8f8cd Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 414
diff changeset
423 // Type FunctionName ( ParameterList ) FunctionBody
b18b0cd8f8cd Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 414
diff changeset
424 if (token.type == T.LParen)
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
425 {
415
b18b0cd8f8cd Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 414
diff changeset
426 // It's a function declaration
b18b0cd8f8cd Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 414
diff changeset
427 TemplateParameters tparams;
b18b0cd8f8cd Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 414
diff changeset
428 if (tokenAfterParenIs(T.LParen))
b18b0cd8f8cd Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 414
diff changeset
429 {
b18b0cd8f8cd Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 414
diff changeset
430 // ( TemplateParameterList ) ( ParameterList )
b18b0cd8f8cd Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 414
diff changeset
431 tparams = parseTemplateParameterList();
b18b0cd8f8cd Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 414
diff changeset
432 }
b18b0cd8f8cd Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 414
diff changeset
433
b18b0cd8f8cd Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 414
diff changeset
434 auto params = parseParameterList();
b18b0cd8f8cd Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 414
diff changeset
435 // ReturnType FunctionName ( ParameterList )
b18b0cd8f8cd Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 414
diff changeset
436 auto funcBody = parseFunctionBody();
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
437 return set(new FunctionDeclaration(type, ident, tparams, params, funcBody), begin);
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
438 }
415
b18b0cd8f8cd Fixed parsing C function pointers in declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 414
diff changeset
439 type = parseDeclaratorSuffix(type);
202
8aecf8925c5f - Added code for parsing AutoDeclaration in parseDeclaration().
aziz
parents: 201
diff changeset
440 }
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
441 }
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
442
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
443 // It's a variable declaration.
262
0f22269e76ff - Changed some string types to Token*.
aziz
parents: 261
diff changeset
444 Token*[] idents = [ident];
194
b3604b237292 - Implemented parsing variable declarations.
aziz
parents: 193
diff changeset
445 Expression[] values;
199
a95fee6e4b7e - Fix: parseDeclaration(): appending null to values when no initializer present.
aziz
parents: 198
diff changeset
446 goto LenterLoop; // We've already parsed an identifier. Jump to if statement and check for initializer.
194
b3604b237292 - Implemented parsing variable declarations.
aziz
parents: 193
diff changeset
447 while (token.type == T.Comma)
b3604b237292 - Implemented parsing variable declarations.
aziz
parents: 193
diff changeset
448 {
222
4f31e4671e06 - Fix: nT() wasn't called in while loop to skip T.Comma.
aziz
parents: 220
diff changeset
449 nT();
262
0f22269e76ff - Changed some string types to Token*.
aziz
parents: 261
diff changeset
450 idents ~= requireId();
194
b3604b237292 - Implemented parsing variable declarations.
aziz
parents: 193
diff changeset
451 LenterLoop:
b3604b237292 - Implemented parsing variable declarations.
aziz
parents: 193
diff changeset
452 if (token.type == T.Assign)
b3604b237292 - Implemented parsing variable declarations.
aziz
parents: 193
diff changeset
453 {
b3604b237292 - Implemented parsing variable declarations.
aziz
parents: 193
diff changeset
454 nT();
b3604b237292 - Implemented parsing variable declarations.
aziz
parents: 193
diff changeset
455 values ~= parseInitializer();
b3604b237292 - Implemented parsing variable declarations.
aziz
parents: 193
diff changeset
456 }
199
a95fee6e4b7e - Fix: parseDeclaration(): appending null to values when no initializer present.
aziz
parents: 198
diff changeset
457 else
a95fee6e4b7e - Fix: parseDeclaration(): appending null to values when no initializer present.
aziz
parents: 198
diff changeset
458 values ~= null;
194
b3604b237292 - Implemented parsing variable declarations.
aziz
parents: 193
diff changeset
459 }
b3604b237292 - Implemented parsing variable declarations.
aziz
parents: 193
diff changeset
460 require(T.Semicolon);
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
461 return set(new VariableDeclaration(type, idents, values), begin);
194
b3604b237292 - Implemented parsing variable declarations.
aziz
parents: 193
diff changeset
462 }
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
463
194
b3604b237292 - Implemented parsing variable declarations.
aziz
parents: 193
diff changeset
464 Expression parseInitializer()
b3604b237292 - Implemented parsing variable declarations.
aziz
parents: 193
diff changeset
465 {
198
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
466 if (token.type == T.Void)
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
467 {
266
fea4e8b6cea5 - Added begin variables and calls to set().
aziz
parents: 265
diff changeset
468 auto begin = token;
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
469 auto next = peekNext();
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
470 if (next == T.Comma || next == T.Semicolon)
198
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
471 {
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
472 nT();
266
fea4e8b6cea5 - Added begin variables and calls to set().
aziz
parents: 265
diff changeset
473 return set(new VoidInitializer(), begin);
198
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
474 }
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
475 }
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
476 return parseNonVoidInitializer();
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
477 }
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
478
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
479 Expression parseNonVoidInitializer()
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
480 {
266
fea4e8b6cea5 - Added begin variables and calls to set().
aziz
parents: 265
diff changeset
481 auto begin = token;
198
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
482 Expression init;
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
483 switch (token.type)
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
484 {
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
485 case T.LBracket:
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
486 // ArrayInitializer:
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
487 // [ ]
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
488 // [ ArrayMemberInitializations ]
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
489 Expression[] keys;
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
490 Expression[] values;
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
491
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
492 nT();
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
493 while (token.type != T.RBracket)
198
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
494 {
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
495 auto e = parseNonVoidInitializer();
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
496 if (token.type == T.Colon)
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
497 {
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
498 nT();
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
499 keys ~= e;
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
500 values ~= parseNonVoidInitializer();
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
501 }
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
502 else
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
503 {
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
504 keys ~= null;
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
505 values ~= e;
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
506 }
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
507
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
508 if (token.type != T.Comma)
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
509 break;
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
510 nT();
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
511 }
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
512 require(T.RBracket);
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
513 init = new ArrayInitializer(keys, values);
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
514 break;
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
515 case T.LBrace:
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
516 // StructInitializer:
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
517 // { }
198
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
518 // { StructMemberInitializers }
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
519 Expression parseStructInitializer()
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
520 {
263
ebcf7941f1db - Changed some string types to Token*.
aziz
parents: 262
diff changeset
521 Token*[] idents;
198
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
522 Expression[] values;
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
523
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
524 nT();
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
525 while (token.type != T.RBrace)
198
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
526 {
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
527 if (token.type == T.Identifier)
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
528 {
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
529 // Peek for colon to see if this is a member identifier.
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
530 if (peekNext() == T.Colon)
198
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
531 {
263
ebcf7941f1db - Changed some string types to Token*.
aziz
parents: 262
diff changeset
532 idents ~= token;
198
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
533 nT();
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
534 nT();
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
535 }
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
536 }
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
537 // NonVoidInitializer
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
538 values ~= parseNonVoidInitializer();
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
539
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
540 if (token.type != T.Comma)
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
541 break;
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
542 nT();
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
543 }
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
544 require(T.RBrace);
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
545 return new StructInitializer(idents, values);
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
546 }
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
547
214
45fc474c1678 - Changed 'failed' parameter of try_() to 'success'.
aziz
parents: 213
diff changeset
548 bool success;
423
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
549 auto si = try_(&parseStructInitializer, success);
214
45fc474c1678 - Changed 'failed' parameter of try_() to 'success'.
aziz
parents: 213
diff changeset
550 if (success)
200
61f60112ac63 - Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents: 199
diff changeset
551 {
198
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
552 init = si;
200
61f60112ac63 - Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents: 199
diff changeset
553 break;
61f60112ac63 - Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents: 199
diff changeset
554 }
216
984d48932bce - Added class EmptyStatement.
aziz
parents: 214
diff changeset
555 assert(token.type == T.LBrace);
200
61f60112ac63 - Fix: parsing AssignExpression when parsing StructInitializer failed.
aziz
parents: 199
diff changeset
556 //goto default;
198
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
557 default:
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
558 init = parseAssignExpression();
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
559 }
266
fea4e8b6cea5 - Added begin variables and calls to set().
aziz
parents: 265
diff changeset
560 set(init, begin);
198
88c1777a9e51 - Implemented parseInitializer() and parseNonVoidInitializer().
aziz
parents: 197
diff changeset
561 return init;
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
562 }
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
563
267
f3dfa6208ed3 - Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents: 266
diff changeset
564 FunctionBody parseFunctionBody()
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
565 {
268
c19b68a4e3db - FunctionBody inherits from Node now.
aziz
parents: 267
diff changeset
566 auto begin = token;
267
f3dfa6208ed3 - Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents: 266
diff changeset
567 auto func = new FunctionBody;
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
568 while (1)
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
569 {
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
570 switch (token.type)
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
571 {
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
572 case T.LBrace:
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
573 func.funcBody = parseStatements();
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
574 break;
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
575 case T.Semicolon:
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
576 nT();
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
577 break;
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
578 case T.In:
342
f13d551d7c4f - Added error messages MID.InContract and MID.OutContract.
aziz
parents: 341
diff changeset
579 if (func.inBody)
f13d551d7c4f - Added error messages MID.InContract and MID.OutContract.
aziz
parents: 341
diff changeset
580 error(MID.InContract);
226
aa38e1401217 - Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents: 225
diff changeset
581 nT();
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
582 func.inBody = parseStatements();
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
583 continue;
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
584 case T.Out:
342
f13d551d7c4f - Added error messages MID.InContract and MID.OutContract.
aziz
parents: 341
diff changeset
585 if (func.outBody)
f13d551d7c4f - Added error messages MID.InContract and MID.OutContract.
aziz
parents: 341
diff changeset
586 error(MID.OutContract);
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
587 nT();
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
588 if (token.type == T.LParen)
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
589 {
226
aa38e1401217 - Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents: 225
diff changeset
590 nT();
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
591 func.outIdent = requireId();
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
592 require(T.RParen);
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
593 }
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
594 func.outBody = parseStatements();
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
595 continue;
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
596 case T.Body:
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
597 nT();
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
598 goto case T.LBrace;
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
599 default:
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
600 error(MID.ExpectedButFound, "FunctionBody", token.srcText);
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
601 }
342
f13d551d7c4f - Added error messages MID.InContract and MID.OutContract.
aziz
parents: 341
diff changeset
602 break; // Exit loop.
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
603 }
268
c19b68a4e3db - FunctionBody inherits from Node now.
aziz
parents: 267
diff changeset
604 set(func, begin);
299
559d5d62e0c1 - Added checks for null before adding member to Node.children.
aziz
parents: 298
diff changeset
605 func.finishConstruction();
193
2a2975b6d539 - Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents: 192
diff changeset
606 return func;
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
607 }
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
608
359
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
609 Linkage parseLinkage()
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
610 {
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
611 if (token.type != T.LParen)
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
612 return null;
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
613
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
614 nT(); // Skip (
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
615 if (token.type == T.RParen)
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
616 {
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
617 error(MID.MissingLinkageType);
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
618 nT();
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
619 return null;
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
620 }
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
621
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
622 auto begin = token;
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
623 auto ident = requireId();
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
624
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
625 Linkage.Type linktype;
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
626 switch (ident ? ident.identifier : null)
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
627 {
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
628 case "C":
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
629 if (token.type == T.PlusPlus)
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
630 {
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
631 nT();
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
632 linktype = Linkage.Type.Cpp;
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
633 break;
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
634 }
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
635 linktype = Linkage.Type.C;
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
636 break;
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
637 case "D":
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
638 linktype = Linkage.Type.D;
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
639 break;
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
640 case "Windows":
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
641 linktype = Linkage.Type.Windows;
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
642 break;
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
643 case "Pascal":
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
644 linktype = Linkage.Type.Pascal;
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
645 break;
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
646 case "System":
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
647 linktype = Linkage.Type.System;
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
648 break;
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
649 default:
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
650 error(MID.UnrecognizedLinkageType, token.srcText);
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
651 nT();
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
652 }
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
653 auto linkage = new Linkage(linktype);
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
654 set(linkage, begin);
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
655 require(T.RParen);
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
656 return linkage;
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
657 }
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
658
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
659 Declaration parseStorageAttribute()
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
660 {
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
661 StorageClass stc, tmp;
359
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
662 Linkage.Category link_cat;
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
663
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
664 void addStorageClass()
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
665 {
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
666 if (stc & tmp)
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
667 error(MID.RedundantStorageClass, token.srcText);
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
668 else
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
669 stc |= tmp;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
670 }
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
671
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 304
diff changeset
672 Declaration parse()
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
673 {
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
674 Declaration decl;
359
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
675 auto begin = token;
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
676 switch (token.type)
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
677 {
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
678 case T.Extern:
359
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
679 stc |= StorageClass.Extern;
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
680 nT();
359
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
681 Linkage linkage = parseLinkage();
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
682
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
683 // Check for redundancy.
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
684 Linkage.Category link_cat_tmp = Linkage.getCategory(linkage);
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
685 if (link_cat & link_cat_tmp)
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
686 {
359
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
687 char[] srcText = begin.srcText;
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
688 if (link_cat_tmp == Linkage.Category.MangleSymbol)
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
689 srcText = begin.start[0 .. prevToken.end - begin.start];
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
690 error(MID.RedundantStorageClass, srcText);
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
691 }
359
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
692 else
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
693 link_cat |= link_cat_tmp;
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
694
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
695 decl = set(new ExternDeclaration(linkage, parse()), begin);
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
696 break;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
697 case T.Override:
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
698 tmp = StorageClass.Override;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
699 goto Lcommon;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
700 case T.Deprecated:
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
701 tmp = StorageClass.Deprecated;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
702 goto Lcommon;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
703 case T.Abstract:
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
704 tmp = StorageClass.Abstract;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
705 goto Lcommon;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
706 case T.Synchronized:
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
707 tmp = StorageClass.Synchronized;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
708 goto Lcommon;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
709 case T.Static:
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
710 tmp = StorageClass.Static;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
711 goto Lcommon;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
712 case T.Final:
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
713 tmp = StorageClass.Final;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
714 goto Lcommon;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
715 case T.Const:
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
716 version(D2)
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
717 {
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
718 if (peekNext() == T.LParen)
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
719 goto case_Declaration;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
720 }
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
721 tmp = StorageClass.Const;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
722 goto Lcommon;
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
723 version(D2)
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
724 {
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
725 case T.Invariant: // D 2.0
359
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
726 // TODO: could this be a class invariant?
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
727 if (peekNext() == T.LParen)
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
728 goto case_Declaration;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
729 tmp = StorageClass.Invariant;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
730 goto Lcommon;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
731 }
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
732 case T.Auto:
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
733 tmp = StorageClass.Auto;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
734 goto Lcommon;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
735 case T.Scope:
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
736 tmp = StorageClass.Scope;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
737 goto Lcommon;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
738 Lcommon:
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
739 addStorageClass();
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
740 auto tok = token.type;
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
741 nT();
359
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
742 decl = set(new AttributeDeclaration(tok, parse()), begin);
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
743 break;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
744 case T.Identifier:
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
745 case_Declaration:
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
746 // This could be a normal Declaration or an AutoDeclaration
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
747 decl = parseDeclaration(stc);
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
748 break;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
749 default:
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 304
diff changeset
750 decl = parseDeclarationsBlock();
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
751 }
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 304
diff changeset
752 return decl;
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
753 }
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 304
diff changeset
754 return parse();
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
755 }
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
756
260
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
757 Token* parseAlignAttribute()
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
758 {
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
759 assert(token.type == T.Align);
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
760 nT(); // Skip align keyword.
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
761 Token* tok;
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
762 if (token.type == T.LParen)
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
763 {
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
764 nT();
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
765 if (token.type == T.Int32)
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
766 {
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
767 tok = token;
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
768 nT();
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
769 }
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
770 else
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
771 expected(T.Int32);
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
772 require(T.RParen);
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
773 }
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
774 return tok;
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
775 }
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
776
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
777 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
778 {
146
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
779 Declaration decl;
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
780
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
781 switch (token.type)
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
782 {
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
783 case T.Align:
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
784 int size = -1;
260
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
785 auto intTok = parseAlignAttribute();
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
786 if (intTok)
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
787 size = intTok.int_;
146
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
788 decl = new AlignDeclaration(size, parseDeclarationsBlock());
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
789 break;
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
790 case T.Pragma:
147
e46b3415ec16 - Implemented parsing pragma declarations.
aziz
parents: 146
diff changeset
791 // Pragma:
e46b3415ec16 - Implemented parsing pragma declarations.
aziz
parents: 146
diff changeset
792 // pragma ( Identifier )
e46b3415ec16 - Implemented parsing pragma declarations.
aziz
parents: 146
diff changeset
793 // pragma ( Identifier , ExpressionList )
e46b3415ec16 - Implemented parsing pragma declarations.
aziz
parents: 146
diff changeset
794 // ExpressionList:
e46b3415ec16 - Implemented parsing pragma declarations.
aziz
parents: 146
diff changeset
795 // AssignExpression
e46b3415ec16 - Implemented parsing pragma declarations.
aziz
parents: 146
diff changeset
796 // AssignExpression , ExpressionList
e46b3415ec16 - Implemented parsing pragma declarations.
aziz
parents: 146
diff changeset
797 nT();
245
93d37f874658 - Changed type of pragma identifier to Token*.
aziz
parents: 244
diff changeset
798 Token* ident;
147
e46b3415ec16 - Implemented parsing pragma declarations.
aziz
parents: 146
diff changeset
799 Expression[] args;
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 304
diff changeset
800 Declaration decls;
147
e46b3415ec16 - Implemented parsing pragma declarations.
aziz
parents: 146
diff changeset
801
e46b3415ec16 - Implemented parsing pragma declarations.
aziz
parents: 146
diff changeset
802 require(T.LParen);
245
93d37f874658 - Changed type of pragma identifier to Token*.
aziz
parents: 244
diff changeset
803 ident = requireId();
147
e46b3415ec16 - Implemented parsing pragma declarations.
aziz
parents: 146
diff changeset
804
e46b3415ec16 - Implemented parsing pragma declarations.
aziz
parents: 146
diff changeset
805 if (token.type == T.Comma)
244
829fdb2e2915 - Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents: 243
diff changeset
806 {
829fdb2e2915 - Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents: 243
diff changeset
807 // Parse at least one argument.
829fdb2e2915 - Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents: 243
diff changeset
808 nT();
829fdb2e2915 - Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents: 243
diff changeset
809 args ~= parseAssignExpression();
829fdb2e2915 - Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents: 243
diff changeset
810 }
829fdb2e2915 - Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents: 243
diff changeset
811
829fdb2e2915 - Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents: 243
diff changeset
812 if (token.type == T.Comma)
829fdb2e2915 - Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents: 243
diff changeset
813 args ~= parseArguments(T.RParen);
147
e46b3415ec16 - Implemented parsing pragma declarations.
aziz
parents: 146
diff changeset
814 else
e46b3415ec16 - Implemented parsing pragma declarations.
aziz
parents: 146
diff changeset
815 require(T.RParen);
e46b3415ec16 - Implemented parsing pragma declarations.
aziz
parents: 146
diff changeset
816
e46b3415ec16 - Implemented parsing pragma declarations.
aziz
parents: 146
diff changeset
817 if (token.type == T.Semicolon)
313
1c1adededd8f - Fix: assign new EmptyDeclaration to decls when parsing PragmaStatement.
aziz
parents: 312
diff changeset
818 {
147
e46b3415ec16 - Implemented parsing pragma declarations.
aziz
parents: 146
diff changeset
819 nT();
313
1c1adededd8f - Fix: assign new EmptyDeclaration to decls when parsing PragmaStatement.
aziz
parents: 312
diff changeset
820 decls = new EmptyDeclaration();
1c1adededd8f - Fix: assign new EmptyDeclaration to decls when parsing PragmaStatement.
aziz
parents: 312
diff changeset
821 }
147
e46b3415ec16 - Implemented parsing pragma declarations.
aziz
parents: 146
diff changeset
822 else
e46b3415ec16 - Implemented parsing pragma declarations.
aziz
parents: 146
diff changeset
823 decls = parseDeclarationsBlock();
e46b3415ec16 - Implemented parsing pragma declarations.
aziz
parents: 146
diff changeset
824
e46b3415ec16 - Implemented parsing pragma declarations.
aziz
parents: 146
diff changeset
825 decl = new PragmaDeclaration(ident, args, decls);
e46b3415ec16 - Implemented parsing pragma declarations.
aziz
parents: 146
diff changeset
826 break;
149
37e2e0d06013 - Removed ProtectionDeclaration.
aziz
parents: 148
diff changeset
827 // Protection attributes
146
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
828 case T.Private:
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
829 case T.Package:
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
830 case T.Protected:
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
831 case T.Public:
148
e3e4d3314166 - Implemented parsing protection attributes.
aziz
parents: 147
diff changeset
832 case T.Export:
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
833 auto tok = token.type;
150
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
834 nT();
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
835 decl = new AttributeDeclaration(tok, parseDeclarationsBlock());
149
37e2e0d06013 - Removed ProtectionDeclaration.
aziz
parents: 148
diff changeset
836 break;
146
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
837 default:
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
838 assert(0);
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
839 }
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
840 return decl;
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
841 }
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
842
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
843 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
844 {
107
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
845 assert(token.type == T.Import || token.type == T.Static);
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
846
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
847 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
848
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
849 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
850 {
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
851 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
852 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
853 }
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
854
429
052cbacb1642 Fix: removed infinite loop when parsing static imports.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 424
diff changeset
855 assert(token.type == T.Import);
052cbacb1642 Fix: removed infinite loop when parsing static imports.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 424
diff changeset
856
364
1059295c2727 - Every command module has an execute method now.
aziz
parents: 359
diff changeset
857 ModuleFQN[] moduleFQNs;
263
ebcf7941f1db - Changed some string types to Token*.
aziz
parents: 262
diff changeset
858 Token*[] moduleAliases;
ebcf7941f1db - Changed some string types to Token*.
aziz
parents: 262
diff changeset
859 Token*[] bindNames;
ebcf7941f1db - Changed some string types to Token*.
aziz
parents: 262
diff changeset
860 Token*[] bindAliases;
114
83bb5190c0fc - Completed implementation of parseImportDeclaration().
aziz
parents: 113
diff changeset
861
115
cea36caeec42 - Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents: 114
diff changeset
862 nT(); // Skip import keyword.
298
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
863 while (1)
114
83bb5190c0fc - Completed implementation of parseImportDeclaration().
aziz
parents: 113
diff changeset
864 {
364
1059295c2727 - Every command module has an execute method now.
aziz
parents: 359
diff changeset
865 ModuleFQN moduleFQN;
263
ebcf7941f1db - Changed some string types to Token*.
aziz
parents: 262
diff changeset
866 Token* moduleAlias;
ebcf7941f1db - Changed some string types to Token*.
aziz
parents: 262
diff changeset
867
ebcf7941f1db - Changed some string types to Token*.
aziz
parents: 262
diff changeset
868 moduleAlias = requireId();
115
cea36caeec42 - Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents: 114
diff changeset
869
cea36caeec42 - Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents: 114
diff changeset
870 // AliasName = ModuleName
cea36caeec42 - Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents: 114
diff changeset
871 if (token.type == T.Assign)
114
83bb5190c0fc - Completed implementation of parseImportDeclaration().
aziz
parents: 113
diff changeset
872 {
83bb5190c0fc - Completed implementation of parseImportDeclaration().
aziz
parents: 113
diff changeset
873 nT();
364
1059295c2727 - Every command module has an execute method now.
aziz
parents: 359
diff changeset
874 moduleFQN ~= requireId();
114
83bb5190c0fc - Completed implementation of parseImportDeclaration().
aziz
parents: 113
diff changeset
875 }
115
cea36caeec42 - Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents: 114
diff changeset
876 else // import Identifier [^=]
114
83bb5190c0fc - Completed implementation of parseImportDeclaration().
aziz
parents: 113
diff changeset
877 {
364
1059295c2727 - Every command module has an execute method now.
aziz
parents: 359
diff changeset
878 moduleFQN ~= moduleAlias;
114
83bb5190c0fc - Completed implementation of parseImportDeclaration().
aziz
parents: 113
diff changeset
879 moduleAlias = null;
83bb5190c0fc - Completed implementation of parseImportDeclaration().
aziz
parents: 113
diff changeset
880 }
115
cea36caeec42 - Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents: 114
diff changeset
881
298
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
882 // Identifier(.Identifier)*
114
83bb5190c0fc - Completed implementation of parseImportDeclaration().
aziz
parents: 113
diff changeset
883 while (token.type == T.Dot)
83bb5190c0fc - Completed implementation of parseImportDeclaration().
aziz
parents: 113
diff changeset
884 {
83bb5190c0fc - Completed implementation of parseImportDeclaration().
aziz
parents: 113
diff changeset
885 nT();
364
1059295c2727 - Every command module has an execute method now.
aziz
parents: 359
diff changeset
886 moduleFQN ~= requireId();
114
83bb5190c0fc - Completed implementation of parseImportDeclaration().
aziz
parents: 113
diff changeset
887 }
83bb5190c0fc - Completed implementation of parseImportDeclaration().
aziz
parents: 113
diff changeset
888
83bb5190c0fc - Completed implementation of parseImportDeclaration().
aziz
parents: 113
diff changeset
889 // Push identifiers.
364
1059295c2727 - Every command module has an execute method now.
aziz
parents: 359
diff changeset
890 moduleFQNs ~= moduleFQN;
114
83bb5190c0fc - Completed implementation of parseImportDeclaration().
aziz
parents: 113
diff changeset
891 moduleAliases ~= moduleAlias;
83bb5190c0fc - Completed implementation of parseImportDeclaration().
aziz
parents: 113
diff changeset
892
298
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
893 if (token.type != T.Comma)
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
894 break;
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
895 nT();
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
896 }
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
897
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
898 if (token.type == T.Colon)
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
899 {
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
900 // BindAlias = BindName(, BindAlias = BindName)*;
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
901 // BindName(, BindName)*;
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
902 Token* bindName, bindAlias;
320
0ce14640eb04 - Fix in parseImportDeclaration(): rewrote while loop and removed a call to nT().
aziz
parents: 319
diff changeset
903 do
114
83bb5190c0fc - Completed implementation of parseImportDeclaration().
aziz
parents: 113
diff changeset
904 {
298
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
905 nT();
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
906 bindAlias = requireId();
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
907
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
908 if (token.type == T.Assign)
114
83bb5190c0fc - Completed implementation of parseImportDeclaration().
aziz
parents: 113
diff changeset
909 {
83bb5190c0fc - Completed implementation of parseImportDeclaration().
aziz
parents: 113
diff changeset
910 nT();
298
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
911 bindName = requireId();
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
912 }
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
913 else
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
914 {
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
915 bindName = bindAlias;
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
916 bindAlias = null;
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
917 }
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
918
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
919 // Push identifiers.
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
920 bindNames ~= bindName;
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
921 bindAliases ~= bindAlias;
320
0ce14640eb04 - Fix in parseImportDeclaration(): rewrote while loop and removed a call to nT().
aziz
parents: 319
diff changeset
922 } while (token.type == T.Comma)
298
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
923 }
dc8bed242db5 - Fixed parsing ImportDeclaration.
aziz
parents: 297
diff changeset
924
114
83bb5190c0fc - Completed implementation of parseImportDeclaration().
aziz
parents: 113
diff changeset
925 require(T.Semicolon);
83bb5190c0fc - Completed implementation of parseImportDeclaration().
aziz
parents: 113
diff changeset
926
366
dcbd3bf9bf74 - Added command importgraph/igraph to main.d.
aziz
parents: 364
diff changeset
927 return new ImportDeclaration(moduleFQNs, moduleAliases, bindNames, bindAliases, isStatic);
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
928 }
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
929
107
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
930 Declaration parseEnumDeclaration()
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
931 {
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
932 assert(token.type == T.Enum);
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
933
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
934 Token* enumName;
107
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
935 Type baseType;
406
e242f0ee2d27 Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 405
diff changeset
936 EnumMember[] members;
126
0f0e7352e91d - Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents: 125
diff changeset
937 bool hasBody;
107
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
938
115
cea36caeec42 - Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents: 114
diff changeset
939 nT(); // Skip enum keyword.
231
6846138a0e24 - Fixed parseEnumDeclaration().
aziz
parents: 230
diff changeset
940
6846138a0e24 - Fixed parseEnumDeclaration().
aziz
parents: 230
diff changeset
941 if (token.type == T.Identifier)
6846138a0e24 - Fixed parseEnumDeclaration().
aziz
parents: 230
diff changeset
942 {
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
943 enumName = token;
231
6846138a0e24 - Fixed parseEnumDeclaration().
aziz
parents: 230
diff changeset
944 nT();
6846138a0e24 - Fixed parseEnumDeclaration().
aziz
parents: 230
diff changeset
945 }
107
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
946
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
947 if (token.type == T.Colon)
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
948 {
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
949 nT();
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
950 baseType = parseBasicType();
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
951 }
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
952
115
cea36caeec42 - Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents: 114
diff changeset
953 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
954 {
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
955 if (enumName is null)
231
6846138a0e24 - Fixed parseEnumDeclaration().
aziz
parents: 230
diff changeset
956 expected(T.Identifier);
115
cea36caeec42 - Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents: 114
diff changeset
957 nT();
cea36caeec42 - Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents: 114
diff changeset
958 }
cea36caeec42 - Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents: 114
diff changeset
959 else if (token.type == T.LBrace)
107
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
960 {
126
0f0e7352e91d - Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents: 125
diff changeset
961 hasBody = true;
398
f7bb892d64c2 Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 396
diff changeset
962 nT(); // Skip {
f7bb892d64c2 Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 396
diff changeset
963 while (token.type != T.RBrace)
107
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
964 {
406
e242f0ee2d27 Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 405
diff changeset
965 auto begin = token;
e242f0ee2d27 Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 405
diff changeset
966 auto memberName = requireId();
e242f0ee2d27 Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 405
diff changeset
967 Expression value;
107
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
968
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
969 if (token.type == T.Assign)
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
970 {
115
cea36caeec42 - Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents: 114
diff changeset
971 nT();
406
e242f0ee2d27 Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 405
diff changeset
972 value = parseAssignExpression();
107
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
973 }
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
974 else
406
e242f0ee2d27 Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 405
diff changeset
975 value = null;
e242f0ee2d27 Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 405
diff changeset
976
e242f0ee2d27 Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 405
diff changeset
977 members ~= set(new EnumMember(memberName, value), begin);
107
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
978
398
f7bb892d64c2 Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 396
diff changeset
979 if (token.type != T.Comma)
115
cea36caeec42 - Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents: 114
diff changeset
980 break;
398
f7bb892d64c2 Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 396
diff changeset
981 nT(); // Skip ,
f7bb892d64c2 Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 396
diff changeset
982 }
f7bb892d64c2 Fixed Parser.parseEnumDeclaration(): empty enums are allowed now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 396
diff changeset
983 require(T.RBrace);
107
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
984 }
231
6846138a0e24 - Fixed parseEnumDeclaration().
aziz
parents: 230
diff changeset
985 else
6846138a0e24 - Fixed parseEnumDeclaration().
aziz
parents: 230
diff changeset
986 error(MID.ExpectedButFound, "enum declaration", token.srcText);
107
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
987
406
e242f0ee2d27 Added class EnumMember.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 405
diff changeset
988 return new EnumDeclaration(enumName, baseType, members, hasBody);
107
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
989 }
722c05bbd5eb - Implemented parseEnumDeclaration() and added class EnumDeclaration.
aziz
parents: 106
diff changeset
990
109
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
991 Declaration parseClassDeclaration()
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
992 {
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
993 assert(token.type == T.Class);
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
994
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
995 Token* className;
258
112a57f433f2 - Created class TemplateParameters.
aziz
parents: 257
diff changeset
996 TemplateParameters tparams;
109
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
997 BaseClass[] bases;
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 304
diff changeset
998 Declarations decls;
126
0f0e7352e91d - Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents: 125
diff changeset
999 bool hasBody;
109
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1000
115
cea36caeec42 - Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents: 114
diff changeset
1001 nT(); // Skip class keyword.
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1002 className = requireId();
109
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1003
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1004 if (token.type == T.LParen)
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1005 {
195
37c2ffd649c4 - Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents: 194
diff changeset
1006 tparams = parseTemplateParameterList();
109
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1007 }
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1008
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1009 if (token.type == T.Colon)
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1010 bases = parseBaseClasses();
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1011
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1012 if (token.type == T.Semicolon)
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1013 {
405
e2529923a0cb Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 404
diff changeset
1014 if (bases.length != 0)
e2529923a0cb Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 404
diff changeset
1015 error(MID.BaseClassInForwardDeclaration);
109
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1016 nT();
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1017 }
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1018 else if (token.type == T.LBrace)
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1019 {
126
0f0e7352e91d - Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents: 125
diff changeset
1020 hasBody = true;
115
cea36caeec42 - Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents: 114
diff changeset
1021 // 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.
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
1022 decls = parseDeclarationDefinitionsBlock();
109
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1023 }
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1024 else
124
d4c4cea6ee7f - Renamed method errorIfNot() to expected().
aziz
parents: 123
diff changeset
1025 expected(T.LBrace); // TODO: better error msg
109
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1026
195
37c2ffd649c4 - Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents: 194
diff changeset
1027 return new ClassDeclaration(className, tparams, bases, decls, hasBody);
109
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1028 }
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1029
144
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
1030 BaseClass[] parseBaseClasses(bool colonLeadsOff = true)
109
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1031 {
144
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
1032 if (colonLeadsOff)
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
1033 {
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
1034 assert(token.type == T.Colon);
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
1035 nT(); // Skip colon
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
1036 }
109
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1037
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1038 BaseClass[] bases;
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1039
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1040 while (1)
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1041 {
117
79857de26e86 - Moved class Parameter to module Types. Added struct Parameters.
aziz
parents: 116
diff changeset
1042 Protection prot = Protection.Public;
109
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1043 switch (token.type)
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1044 {
204
082f30904456 - Allowing 'typeof' in BaseClassList.
aziz
parents: 203
diff changeset
1045 case T.Identifier, T.Dot, T.Typeof: goto LparseBasicType;
109
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1046 case T.Private: prot = Protection.Private; break;
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1047 case T.Protected: prot = Protection.Protected; break;
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1048 case T.Package: prot = Protection.Package; break;
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1049 case T.Public: /*prot = Protection.Public;*/ break;
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1050 default:
405
e2529923a0cb Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 404
diff changeset
1051 error(MID.ExpectedBaseClasses, token.srcText);
109
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1052 return bases;
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1053 }
158
759f437313f9 - Moved enum Protection and class BaseClass to module Types.
aziz
parents: 157
diff changeset
1054 nT(); // Skip protection attribute.
759f437313f9 - Moved enum Protection and class BaseClass to module Types.
aziz
parents: 157
diff changeset
1055 LparseBasicType:
759f437313f9 - Moved enum Protection and class BaseClass to module Types.
aziz
parents: 157
diff changeset
1056 auto type = parseBasicType();
759f437313f9 - Moved enum Protection and class BaseClass to module Types.
aziz
parents: 157
diff changeset
1057 //if (type.tid != TID.DotList)
759f437313f9 - Moved enum Protection and class BaseClass to module Types.
aziz
parents: 157
diff changeset
1058 // TODO: issue error msg. base classes can only be one or more identifiers or template instances separated by dots.
759f437313f9 - Moved enum Protection and class BaseClass to module Types.
aziz
parents: 157
diff changeset
1059 bases ~= new BaseClass(prot, type);
109
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1060 if (token.type != T.Comma)
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1061 break;
396
0a4619735ce9 Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 391
diff changeset
1062 nT();
109
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1063 }
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1064 return bases;
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1065 }
d0cc281cacbd - Added methods parseClassDeclaration() and parseBaseClasses().
aziz
parents: 108
diff changeset
1066
112
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1067 Declaration parseInterfaceDeclaration()
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1068 {
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1069 assert(token.type == T.Interface);
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1070
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1071 Token* name;
258
112a57f433f2 - Created class TemplateParameters.
aziz
parents: 257
diff changeset
1072 TemplateParameters tparams;
112
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1073 BaseClass[] bases;
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 304
diff changeset
1074 Declarations decls;
126
0f0e7352e91d - Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents: 125
diff changeset
1075 bool hasBody;
112
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1076
115
cea36caeec42 - Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents: 114
diff changeset
1077 nT(); // Skip interface keyword.
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1078 name = requireId();
112
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1079
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1080 if (token.type == T.LParen)
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1081 {
195
37c2ffd649c4 - Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents: 194
diff changeset
1082 tparams = parseTemplateParameterList();
112
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1083 }
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1084
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1085 if (token.type == T.Colon)
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1086 bases = parseBaseClasses();
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1087
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1088 if (token.type == T.Semicolon)
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1089 {
405
e2529923a0cb Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 404
diff changeset
1090 if (bases.length != 0)
e2529923a0cb Added two error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 404
diff changeset
1091 error(MID.BaseClassInForwardDeclaration);
112
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1092 nT();
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1093 }
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1094 else if (token.type == T.LBrace)
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1095 {
126
0f0e7352e91d - Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents: 125
diff changeset
1096 hasBody = true;
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
1097 decls = parseDeclarationDefinitionsBlock();
112
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1098 }
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1099 else
124
d4c4cea6ee7f - Renamed method errorIfNot() to expected().
aziz
parents: 123
diff changeset
1100 expected(T.LBrace); // TODO: better error msg
112
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1101
195
37c2ffd649c4 - Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents: 194
diff changeset
1102 return new InterfaceDeclaration(name, tparams, bases, decls, hasBody);
112
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1103 }
004d98df65af - Implemented parseInterfaceDeclaration().
aziz
parents: 111
diff changeset
1104
113
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
1105 Declaration parseAggregateDeclaration()
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
1106 {
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
1107 assert(token.type == T.Struct || token.type == T.Union);
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
1108
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
1109 TOK tok = token.type;
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
1110
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1111 Token* name;
258
112a57f433f2 - Created class TemplateParameters.
aziz
parents: 257
diff changeset
1112 TemplateParameters tparams;
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 304
diff changeset
1113 Declarations decls;
126
0f0e7352e91d - Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents: 125
diff changeset
1114 bool hasBody;
113
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
1115
115
cea36caeec42 - Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents: 114
diff changeset
1116 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
1117 // name is optional.
113
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
1118 if (token.type == T.Identifier)
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
1119 {
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1120 name = token;
113
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
1121 nT();
115
cea36caeec42 - Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents: 114
diff changeset
1122 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
1123 {
195
37c2ffd649c4 - Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents: 194
diff changeset
1124 tparams = parseTemplateParameterList();
115
cea36caeec42 - Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents: 114
diff changeset
1125 }
113
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
1126 }
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
1127
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
1128 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
1129 {
cea36caeec42 - Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents: 114
diff changeset
1130 //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
1131 // TODO: error: forward declarations must have a name.
113
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
1132 nT();
115
cea36caeec42 - Added method requireIdentifier(). Removed if-else-statements which checked for T.Identifier and replaced with requireIdentifier().
aziz
parents: 114
diff changeset
1133 }
113
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
1134 else if (token.type == T.LBrace)
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
1135 {
126
0f0e7352e91d - Renamed member hasDefinition of class Declaration to hasBody.
aziz
parents: 125
diff changeset
1136 hasBody = true;
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
1137 decls = parseDeclarationDefinitionsBlock();
113
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
1138 }
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
1139 else
124
d4c4cea6ee7f - Renamed method errorIfNot() to expected().
aziz
parents: 123
diff changeset
1140 expected(T.LBrace); // TODO: better error msg
113
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
1141
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
1142 if (tok == T.Struct)
195
37c2ffd649c4 - Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents: 194
diff changeset
1143 return new StructDeclaration(name, tparams, decls, hasBody);
113
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
1144 else
195
37c2ffd649c4 - Parsing template parameter list for class, interface, struct and union declarations.
aziz
parents: 194
diff changeset
1145 return new UnionDeclaration(name, tparams, decls, hasBody);
113
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
1146 }
20d8ae8a3fd9 - Implemented parseAggregateDeclaration for Struct- and UnionDeclarations.
aziz
parents: 112
diff changeset
1147
117
79857de26e86 - Moved class Parameter to module Types. Added struct Parameters.
aziz
parents: 116
diff changeset
1148 Declaration parseConstructorDeclaration()
79857de26e86 - Moved class Parameter to module Types. Added struct Parameters.
aziz
parents: 116
diff changeset
1149 {
79857de26e86 - Moved class Parameter to module Types. Added struct Parameters.
aziz
parents: 116
diff changeset
1150 assert(token.type == T.This);
79857de26e86 - Moved class Parameter to module Types. Added struct Parameters.
aziz
parents: 116
diff changeset
1151 nT(); // Skip 'this' keyword.
143
e760d7552f66 - Renamed parseArgumentList() to parseArguments().
aziz
parents: 141
diff changeset
1152 auto parameters = parseParameterList();
267
f3dfa6208ed3 - Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents: 266
diff changeset
1153 auto funcBody = parseFunctionBody();
197
ff32eb87300e - Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents: 196
diff changeset
1154 return new ConstructorDeclaration(parameters, funcBody);
117
79857de26e86 - Moved class Parameter to module Types. Added struct Parameters.
aziz
parents: 116
diff changeset
1155 }
79857de26e86 - Moved class Parameter to module Types. Added struct Parameters.
aziz
parents: 116
diff changeset
1156
118
379f33cbd521 - Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents: 117
diff changeset
1157 Declaration parseDestructorDeclaration()
379f33cbd521 - Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents: 117
diff changeset
1158 {
379f33cbd521 - Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents: 117
diff changeset
1159 assert(token.type == T.Tilde);
379f33cbd521 - Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents: 117
diff changeset
1160 nT(); // Skip ~
379f33cbd521 - Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents: 117
diff changeset
1161 require(T.This);
379f33cbd521 - Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents: 117
diff changeset
1162 require(T.LParen);
379f33cbd521 - Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents: 117
diff changeset
1163 require(T.RParen);
267
f3dfa6208ed3 - Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents: 266
diff changeset
1164 auto funcBody = parseFunctionBody();
197
ff32eb87300e - Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents: 196
diff changeset
1165 return new DestructorDeclaration(funcBody);
118
379f33cbd521 - Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents: 117
diff changeset
1166 }
379f33cbd521 - Added parseDestructorDeclaration() and DestructorDeclaration class.
aziz
parents: 117
diff changeset
1167
119
363cd39022f9 - Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents: 118
diff changeset
1168 Declaration parseStaticConstructorDeclaration()
363cd39022f9 - Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents: 118
diff changeset
1169 {
363cd39022f9 - Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents: 118
diff changeset
1170 assert(token.type == T.Static);
363cd39022f9 - Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents: 118
diff changeset
1171 nT(); // Skip static keyword.
363cd39022f9 - Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents: 118
diff changeset
1172 nT(); // Skip 'this' keyword.
363cd39022f9 - Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents: 118
diff changeset
1173 require(T.LParen);
363cd39022f9 - Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents: 118
diff changeset
1174 require(T.RParen);
267
f3dfa6208ed3 - Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents: 266
diff changeset
1175 auto funcBody = parseFunctionBody();
197
ff32eb87300e - Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents: 196
diff changeset
1176 return new StaticConstructorDeclaration(funcBody);
119
363cd39022f9 - Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents: 118
diff changeset
1177 }
363cd39022f9 - Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents: 118
diff changeset
1178
363cd39022f9 - Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents: 118
diff changeset
1179 Declaration parseStaticDestructorDeclaration()
363cd39022f9 - Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents: 118
diff changeset
1180 {
363cd39022f9 - Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents: 118
diff changeset
1181 assert(token.type == T.Static);
363cd39022f9 - Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents: 118
diff changeset
1182 nT(); // Skip static keyword.
363cd39022f9 - Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents: 118
diff changeset
1183 nT(); // Skip ~
363cd39022f9 - Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents: 118
diff changeset
1184 require(T.This);
363cd39022f9 - Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents: 118
diff changeset
1185 require(T.LParen);
363cd39022f9 - Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents: 118
diff changeset
1186 require(T.RParen);
267
f3dfa6208ed3 - Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents: 266
diff changeset
1187 auto funcBody = parseFunctionBody();
197
ff32eb87300e - Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents: 196
diff changeset
1188 return new StaticDestructorDeclaration(funcBody);
119
363cd39022f9 - Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents: 118
diff changeset
1189 }
363cd39022f9 - Added parseStaticConstructor- and DestructorDeclaration().
aziz
parents: 118
diff changeset
1190
120
e5329dac0405 - Added parseInvariantDeclaration().
aziz
parents: 119
diff changeset
1191 Declaration parseInvariantDeclaration()
e5329dac0405 - Added parseInvariantDeclaration().
aziz
parents: 119
diff changeset
1192 {
e5329dac0405 - Added parseInvariantDeclaration().
aziz
parents: 119
diff changeset
1193 assert(token.type == T.Invariant);
e5329dac0405 - Added parseInvariantDeclaration().
aziz
parents: 119
diff changeset
1194 nT(); // Skip invariant keyword.
e5329dac0405 - Added parseInvariantDeclaration().
aziz
parents: 119
diff changeset
1195 // Optional () for getting ready porting to D 2.0
e5329dac0405 - Added parseInvariantDeclaration().
aziz
parents: 119
diff changeset
1196 if (token.type == T.LParen)
122
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1197 requireNext(T.RParen);
267
f3dfa6208ed3 - Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents: 266
diff changeset
1198 auto funcBody = parseFunctionBody();
197
ff32eb87300e - Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents: 196
diff changeset
1199 return new InvariantDeclaration(funcBody);
120
e5329dac0405 - Added parseInvariantDeclaration().
aziz
parents: 119
diff changeset
1200 }
e5329dac0405 - Added parseInvariantDeclaration().
aziz
parents: 119
diff changeset
1201
121
030933c6b5f0 - Added parseUnittestDeclaration().
aziz
parents: 120
diff changeset
1202 Declaration parseUnittestDeclaration()
030933c6b5f0 - Added parseUnittestDeclaration().
aziz
parents: 120
diff changeset
1203 {
030933c6b5f0 - Added parseUnittestDeclaration().
aziz
parents: 120
diff changeset
1204 assert(token.type == T.Unittest);
030933c6b5f0 - Added parseUnittestDeclaration().
aziz
parents: 120
diff changeset
1205
122
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1206 nT(); // Skip unittest keyword.
267
f3dfa6208ed3 - Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents: 266
diff changeset
1207 auto funcBody = parseFunctionBody();
197
ff32eb87300e - Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents: 196
diff changeset
1208 return new UnittestDeclaration(funcBody);
121
030933c6b5f0 - Added parseUnittestDeclaration().
aziz
parents: 120
diff changeset
1209 }
030933c6b5f0 - Added parseUnittestDeclaration().
aziz
parents: 120
diff changeset
1210
122
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1211 Declaration parseDebugDeclaration()
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1212 {
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1213 assert(token.type == T.Debug);
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1214
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1215 nT(); // Skip debug keyword.
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1216
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1217 Token* spec; // debug = Integer ;
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1218 // debug = Identifier ;
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1219 Token* cond; // debug ( Integer )
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1220 // debug ( Identifier )
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 304
diff changeset
1221 Declaration decls, elseDecls;
122
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1222
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1223 void parseIdentOrInt(ref Token* tok)
122
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1224 {
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1225 nT();
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1226 if (token.type == T.Int32 ||
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1227 token.type == T.Identifier)
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1228 {
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1229 tok = token;
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1230 nT();
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1231 }
122
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1232 else
124
d4c4cea6ee7f - Renamed method errorIfNot() to expected().
aziz
parents: 123
diff changeset
1233 expected(T.Identifier); // TODO: better error msg
123
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1234 }
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1235
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1236 if (token.type == T.Assign)
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1237 {
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1238 parseIdentOrInt(spec);
122
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1239 require(T.Semicolon);
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1240 }
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1241 else
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1242 {
123
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1243 // Condition:
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1244 // Integer
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1245 // Identifier
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1246 // ( Condition )
122
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1247 if (token.type == T.LParen)
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1248 {
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1249 parseIdentOrInt(cond);
122
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1250 require(T.RParen);
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1251 }
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1252
123
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1253 // debug DeclarationsBlock
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1254 // debug ( Condition ) DeclarationsBlock
404
fe46b5ea7a18 Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 400
diff changeset
1255 decls = parseDeclarationsBlockNoColon();
123
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1256
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1257 // else DeclarationsBlock
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1258 if (token.type == T.Else)
122
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1259 {
123
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1260 nT();
404
fe46b5ea7a18 Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 400
diff changeset
1261 elseDecls = parseDeclarationsBlockNoColon();
123
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1262 }
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1263 }
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1264
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1265 return new DebugDeclaration(spec, cond, decls, elseDecls);
123
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1266 }
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1267
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1268 Declaration parseVersionDeclaration()
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1269 {
146
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
1270 assert(token.type == T.Version);
123
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1271
146
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
1272 nT(); // Skip version keyword.
123
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1273
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1274 Token* spec; // version = Integer ;
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1275 // version = Identifier ;
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1276 Token* cond; // version ( Integer )
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1277 // version ( Identifier )
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 304
diff changeset
1278 Declaration decls, elseDecls;
122
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1279
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1280 void parseIdentOrInt(ref Token* tok)
123
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1281 {
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1282 if (token.type == T.Int32 ||
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1283 token.type == T.Identifier)
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1284 {
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1285 tok = token;
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1286 nT();
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1287 }
123
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1288 else
124
d4c4cea6ee7f - Renamed method errorIfNot() to expected().
aziz
parents: 123
diff changeset
1289 expected(T.Identifier); // TODO: better error msg
123
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1290 }
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1291
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1292 if (token.type == T.Assign)
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1293 {
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
1294 nT();
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1295 parseIdentOrInt(spec);
123
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1296 require(T.Semicolon);
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1297 }
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1298 else
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1299 {
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1300 // Condition:
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1301 // Integer
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1302 // Identifier
146
8180eb84e69c - Started implementation of parseAttributeSpecifier().
aziz
parents: 145
diff changeset
1303
123
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1304 // ( Condition )
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1305 require(T.LParen);
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1306 parseIdentOrInt(cond);
123
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1307 require(T.RParen);
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1308
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1309 // version ( Condition ) DeclarationsBlock
404
fe46b5ea7a18 Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 400
diff changeset
1310 decls = parseDeclarationsBlockNoColon();
123
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1311
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1312 // else DeclarationsBlock
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1313 if (token.type == T.Else)
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1314 {
0f55c0ac6589 - Added method parseVersionDeclaration().
aziz
parents: 122
diff changeset
1315 nT();
404
fe46b5ea7a18 Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 400
diff changeset
1316 elseDecls = parseDeclarationsBlockNoColon();
122
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1317 }
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1318 }
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1319
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1320 return new VersionDeclaration(spec, cond, decls, elseDecls);
122
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1321 }
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
1322
125
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
1323 Declaration parseStaticIfDeclaration()
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
1324 {
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
1325 assert(token.type == T.Static);
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
1326
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
1327 nT(); // Skip static keyword.
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
1328 nT(); // Skip if keyword.
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
1329
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
1330 Expression condition;
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 304
diff changeset
1331 Declaration ifDecls, elseDecls;
125
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
1332
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
1333 require(T.LParen);
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
1334 condition = parseAssignExpression();
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
1335 require(T.RParen);
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
1336
404
fe46b5ea7a18 Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 400
diff changeset
1337 ifDecls = parseDeclarationsBlockNoColon();
125
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
1338
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
1339 if (token.type == T.Else)
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
1340 {
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
1341 nT();
404
fe46b5ea7a18 Added method parseDeclarationsBlockNoColon().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 400
diff changeset
1342 elseDecls = parseDeclarationsBlockNoColon();
125
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
1343 }
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
1344
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
1345 return new StaticIfDeclaration(condition, ifDecls, elseDecls);
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
1346 }
240a8b053803 - Added method parseStaticIfDeclaration and added class StaticIfDeclaration.
aziz
parents: 124
diff changeset
1347
127
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
1348 Declaration parseStaticAssertDeclaration()
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
1349 {
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
1350 assert(token.type == T.Static);
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
1351
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
1352 nT(); // Skip static keyword.
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
1353 nT(); // Skip assert keyword.
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
1354
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
1355 Expression condition, message;
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
1356
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
1357 require(T.LParen);
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
1358
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
1359 condition = parseAssignExpression();
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
1360
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
1361 if (token.type == T.Comma)
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
1362 {
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
1363 nT();
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
1364 message = parseAssignExpression();
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
1365 }
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
1366
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
1367 require(T.RParen);
128
e02b87281b4e - Static asserts have to end with a semicolon.
aziz
parents: 127
diff changeset
1368 require(T.Semicolon);
127
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
1369
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
1370 return new StaticAssertDeclaration(condition, message);
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
1371 }
cb9a97ebb570 - Added method parseStaticAssertDeclaration and added class StaticAssertDeclaration.
aziz
parents: 126
diff changeset
1372
140
64d7186b087c - Implemented parseTemplateParameters().
aziz
parents: 139
diff changeset
1373 Declaration parseTemplateDeclaration()
64d7186b087c - Implemented parseTemplateParameters().
aziz
parents: 139
diff changeset
1374 {
64d7186b087c - Implemented parseTemplateParameters().
aziz
parents: 139
diff changeset
1375 assert(token.type == T.Template);
64d7186b087c - Implemented parseTemplateParameters().
aziz
parents: 139
diff changeset
1376 nT(); // Skip template keyword.
265
3a2a0a63c638 - Changed some string types to Token*.
aziz
parents: 264
diff changeset
1377 auto templateName = requireId();
143
e760d7552f66 - Renamed parseArgumentList() to parseArguments().
aziz
parents: 141
diff changeset
1378 auto templateParams = parseTemplateParameterList();
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
1379 auto decls = parseDeclarationDefinitionsBlock();
140
64d7186b087c - Implemented parseTemplateParameters().
aziz
parents: 139
diff changeset
1380 return new TemplateDeclaration(templateName, templateParams, decls);
64d7186b087c - Implemented parseTemplateParameters().
aziz
parents: 139
diff changeset
1381 }
64d7186b087c - Implemented parseTemplateParameters().
aziz
parents: 139
diff changeset
1382
141
7ab33ee1a641 - Implemented parseNew- and DeleteDeclaration().
aziz
parents: 140
diff changeset
1383 Declaration parseNewDeclaration()
7ab33ee1a641 - Implemented parseNew- and DeleteDeclaration().
aziz
parents: 140
diff changeset
1384 {
7ab33ee1a641 - Implemented parseNew- and DeleteDeclaration().
aziz
parents: 140
diff changeset
1385 assert(token.type == T.New);
7ab33ee1a641 - Implemented parseNew- and DeleteDeclaration().
aziz
parents: 140
diff changeset
1386 nT(); // Skip new keyword.
143
e760d7552f66 - Renamed parseArgumentList() to parseArguments().
aziz
parents: 141
diff changeset
1387 auto parameters = parseParameterList();
267
f3dfa6208ed3 - Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents: 266
diff changeset
1388 auto funcBody = parseFunctionBody();
197
ff32eb87300e - Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents: 196
diff changeset
1389 return new NewDeclaration(parameters, funcBody);
141
7ab33ee1a641 - Implemented parseNew- and DeleteDeclaration().
aziz
parents: 140
diff changeset
1390 }
7ab33ee1a641 - Implemented parseNew- and DeleteDeclaration().
aziz
parents: 140
diff changeset
1391
7ab33ee1a641 - Implemented parseNew- and DeleteDeclaration().
aziz
parents: 140
diff changeset
1392 Declaration parseDeleteDeclaration()
7ab33ee1a641 - Implemented parseNew- and DeleteDeclaration().
aziz
parents: 140
diff changeset
1393 {
7ab33ee1a641 - Implemented parseNew- and DeleteDeclaration().
aziz
parents: 140
diff changeset
1394 assert(token.type == T.Delete);
7ab33ee1a641 - Implemented parseNew- and DeleteDeclaration().
aziz
parents: 140
diff changeset
1395 nT(); // Skip delete keyword.
143
e760d7552f66 - Renamed parseArgumentList() to parseArguments().
aziz
parents: 141
diff changeset
1396 auto parameters = parseParameterList();
197
ff32eb87300e - Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents: 196
diff changeset
1397 // TODO: only one parameter of type void* allowed. Check in parsing or semantic phase?
267
f3dfa6208ed3 - Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents: 266
diff changeset
1398 auto funcBody = parseFunctionBody();
197
ff32eb87300e - Using parseFunctionBody() for Constructor-,Destructor-,StaticConstructor-,StaticDestructor-,Invariant-,Unittest-,New- and DeleteDeclaration.
aziz
parents: 196
diff changeset
1399 return new DeleteDeclaration(parameters, funcBody);
141
7ab33ee1a641 - Implemented parseNew- and DeleteDeclaration().
aziz
parents: 140
diff changeset
1400 }
7ab33ee1a641 - Implemented parseNew- and DeleteDeclaration().
aziz
parents: 140
diff changeset
1401
154
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1402 /+
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1403 DotListExpression:
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1404 . DotListItems
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1405 DotListItems
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1406 Typeof
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1407 Typeof . DotListItems
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1408 DotListItems:
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1409 DotListItem
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1410 DotListItem . DotListItems
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1411 DotListItem:
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1412 Identifier
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1413 TemplateInstance
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1414 NewExpression
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1415 TemplateInstance:
233
c2b601dcd57d - Added assert to parseDotListExpression().
aziz
parents: 232
diff changeset
1416 Identifier !( TemplateArguments )
154
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1417 +/
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1418 DotListExpression parseDotListExpression()
152
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1419 {
233
c2b601dcd57d - Added assert to parseDotListExpression().
aziz
parents: 232
diff changeset
1420 assert(token.type == T.Identifier || token.type == T.Dot || token.type == T.Typeof);
152
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1421 Expression[] identList;
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1422 if (token.type == T.Dot)
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1423 {
252
788398655d24 - Changed some string types to Token*. Adapted parser accordingly.
aziz
parents: 251
diff changeset
1424 identList ~= new IdentifierExpression(token);
152
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1425 nT();
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1426 }
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1427 else if (token.type == T.Typeof)
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1428 {
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1429 requireNext(T.LParen);
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1430 auto type = new TypeofType(parseExpression());
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1431 require(T.RParen);
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1432 identList ~= new TypeofExpression(type);
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1433 if (token.type != T.Dot)
154
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1434 goto Lreturn;
152
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1435 nT();
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1436 }
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1437
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1438 while (1)
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1439 {
321
ae7f48182cb1 - Added some calls to set().
aziz
parents: 320
diff changeset
1440 auto begin2 = token;
252
788398655d24 - Changed some string types to Token*. Adapted parser accordingly.
aziz
parents: 251
diff changeset
1441 auto ident = requireId();
788398655d24 - Changed some string types to Token*. Adapted parser accordingly.
aziz
parents: 251
diff changeset
1442 Expression e;
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1443 if (token.type == T.Not && peekNext() == T.LParen) // Identifier !( TemplateArguments )
152
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1444 {
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1445 nT(); // Skip !.
321
ae7f48182cb1 - Added some calls to set().
aziz
parents: 320
diff changeset
1446 e = set(new TemplateInstanceExpression(ident, parseTemplateArguments()), begin2);
152
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1447 }
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1448 else // Identifier
321
ae7f48182cb1 - Added some calls to set().
aziz
parents: 320
diff changeset
1449 e = set(new IdentifierExpression(ident), begin2);
252
788398655d24 - Changed some string types to Token*. Adapted parser accordingly.
aziz
parents: 251
diff changeset
1450
788398655d24 - Changed some string types to Token*. Adapted parser accordingly.
aziz
parents: 251
diff changeset
1451 identList ~= e;
152
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1452
154
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1453 LnewExpressionLoop:
152
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1454 if (token.type != T.Dot)
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1455 break;
154
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1456 nT(); // Skip dot.
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1457
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1458 if (token.type == T.New)
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1459 {
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1460 identList ~= parseNewExpression();
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1461 goto LnewExpressionLoop;
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1462 }
152
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1463 }
233
c2b601dcd57d - Added assert to parseDotListExpression().
aziz
parents: 232
diff changeset
1464
154
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1465 Lreturn:
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1466 return new DotListExpression(identList);
152
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1467 }
fe2e36eb4b45 - Added method parseIdentifierListExpression() and class IdentifierListExpression.
aziz
parents: 151
diff changeset
1468
154
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1469 /+
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1470 DotListType:
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1471 . TypeItems
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1472 TypeItems
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1473 Typeof
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1474 Typeof . TypeItems
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1475 TypeItems:
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1476 TypeItem
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1477 TypeItem . TypeItems
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1478 TypeItem:
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1479 Identifier
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1480 TemplateInstance
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1481 TemplateInstance:
233
c2b601dcd57d - Added assert to parseDotListExpression().
aziz
parents: 232
diff changeset
1482 Identifier !( TemplateArguments )
154
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1483 +/
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1484 DotListType parseDotListType()
153
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1485 {
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1486 Type[] identList;
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1487 if (token.type == T.Dot)
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1488 {
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1489 identList ~= new IdentifierType(token);
153
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1490 nT();
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1491 }
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1492 else if (token.type == T.Typeof)
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1493 {
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1494 requireNext(T.LParen);
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1495 identList ~= new TypeofType(parseExpression());
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1496 require(T.RParen);
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1497 if (token.type != T.Dot)
154
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1498 goto Lreturn;
153
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1499 nT();
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1500 }
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1501
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1502 while (1)
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1503 {
321
ae7f48182cb1 - Added some calls to set().
aziz
parents: 320
diff changeset
1504 auto begin2 = token;
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1505 auto ident = requireId();
154
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1506 // NB.: Currently Types can't be followed by "!=" so we don't need to peek for "(" when parsing TemplateInstances.
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1507 if (token.type == T.Not/+ && peekNext() == T.LParen+/) // Identifier !( TemplateArguments )
153
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1508 {
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1509 nT(); // Skip !.
321
ae7f48182cb1 - Added some calls to set().
aziz
parents: 320
diff changeset
1510 identList ~= set(new TemplateInstanceType(ident, parseTemplateArguments()), begin2);
153
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1511 }
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1512 else // Identifier
321
ae7f48182cb1 - Added some calls to set().
aziz
parents: 320
diff changeset
1513 identList ~= set(new IdentifierType(ident), begin2);
153
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1514
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1515 if (token.type != T.Dot)
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1516 break;
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1517 nT();
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1518 }
154
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1519 Lreturn:
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
1520 return new DotListType(identList);
153
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1521 }
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
1522
150
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1523 /*
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1524 TemplateMixin:
151
2e959f67000b - Added code for parsing mixin expression declarations.
aziz
parents: 150
diff changeset
1525 mixin ( AssignExpression ) ;
150
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1526 mixin TemplateIdentifier ;
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1527 mixin TemplateIdentifier MixinIdentifier ;
233
c2b601dcd57d - Added assert to parseDotListExpression().
aziz
parents: 232
diff changeset
1528 mixin TemplateIdentifier !( TemplateArguments ) ;
c2b601dcd57d - Added assert to parseDotListExpression().
aziz
parents: 232
diff changeset
1529 mixin TemplateIdentifier !( TemplateArguments ) MixinIdentifier ;
150
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1530 */
256
8f27920ae17a - Made parseMixinDeclaration() a template.
aziz
parents: 255
diff changeset
1531 Class parseMixin(Class)()
150
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1532 {
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1533 assert(token.type == T.Mixin);
256
8f27920ae17a - Made parseMixinDeclaration() a template.
aziz
parents: 255
diff changeset
1534 auto begin = token;
150
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1535 nT(); // Skip mixin keyword.
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1536
256
8f27920ae17a - Made parseMixinDeclaration() a template.
aziz
parents: 255
diff changeset
1537 static if (is(Class == MixinDeclaration))
301
caef255a2801 - Fix in some ctors: adding only non-null members to this.children.
aziz
parents: 299
diff changeset
1538 {
151
2e959f67000b - Added code for parsing mixin expression declarations.
aziz
parents: 150
diff changeset
1539 if (token.type == T.LParen)
2e959f67000b - Added code for parsing mixin expression declarations.
aziz
parents: 150
diff changeset
1540 {
2e959f67000b - Added code for parsing mixin expression declarations.
aziz
parents: 150
diff changeset
1541 // TODO: What about mixin(...).ident;?
2e959f67000b - Added code for parsing mixin expression declarations.
aziz
parents: 150
diff changeset
1542 nT();
2e959f67000b - Added code for parsing mixin expression declarations.
aziz
parents: 150
diff changeset
1543 auto e = parseAssignExpression();
2e959f67000b - Added code for parsing mixin expression declarations.
aziz
parents: 150
diff changeset
1544 require(T.RParen);
2e959f67000b - Added code for parsing mixin expression declarations.
aziz
parents: 150
diff changeset
1545 require(T.Semicolon);
262
0f22269e76ff - Changed some string types to Token*.
aziz
parents: 261
diff changeset
1546 return new MixinDeclaration(e);
151
2e959f67000b - Added code for parsing mixin expression declarations.
aziz
parents: 150
diff changeset
1547 }
301
caef255a2801 - Fix in some ctors: adding only non-null members to this.children.
aziz
parents: 299
diff changeset
1548 }
151
2e959f67000b - Added code for parsing mixin expression declarations.
aziz
parents: 150
diff changeset
1549
150
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1550 Expression[] templateIdent;
252
788398655d24 - Changed some string types to Token*. Adapted parser accordingly.
aziz
parents: 251
diff changeset
1551 Token* mixinIdent;
150
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1552
159
5aa877506db0 - Added enum Linkage.
aziz
parents: 158
diff changeset
1553 // This code is similar to parseDotListType().
150
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1554 if (token.type == T.Dot)
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1555 {
252
788398655d24 - Changed some string types to Token*. Adapted parser accordingly.
aziz
parents: 251
diff changeset
1556 templateIdent ~= new IdentifierExpression(token);
150
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1557 nT();
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1558 }
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1559
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1560 while (1)
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1561 {
252
788398655d24 - Changed some string types to Token*. Adapted parser accordingly.
aziz
parents: 251
diff changeset
1562 auto ident = requireId();
788398655d24 - Changed some string types to Token*. Adapted parser accordingly.
aziz
parents: 251
diff changeset
1563 Expression e;
150
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1564 if (token.type == T.Not) // Identifier !( TemplateArguments )
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1565 {
151
2e959f67000b - Added code for parsing mixin expression declarations.
aziz
parents: 150
diff changeset
1566 // No need to peek for T.LParen. This must be a template instance.
150
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1567 nT();
252
788398655d24 - Changed some string types to Token*. Adapted parser accordingly.
aziz
parents: 251
diff changeset
1568 e = new TemplateInstanceExpression(ident, parseTemplateArguments());
150
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1569 }
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1570 else // Identifier
252
788398655d24 - Changed some string types to Token*. Adapted parser accordingly.
aziz
parents: 251
diff changeset
1571 e = new IdentifierExpression(ident);
788398655d24 - Changed some string types to Token*. Adapted parser accordingly.
aziz
parents: 251
diff changeset
1572
788398655d24 - Changed some string types to Token*. Adapted parser accordingly.
aziz
parents: 251
diff changeset
1573 templateIdent ~= e;
150
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1574
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1575 if (token.type != T.Dot)
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1576 break;
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1577 nT();
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1578 }
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1579
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1580 if (token.type == T.Identifier)
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1581 {
252
788398655d24 - Changed some string types to Token*. Adapted parser accordingly.
aziz
parents: 251
diff changeset
1582 mixinIdent = token;
150
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1583 nT();
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1584 }
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1585
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1586 require(T.Semicolon);
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1587
262
0f22269e76ff - Changed some string types to Token*.
aziz
parents: 261
diff changeset
1588 return new Class(templateIdent, mixinIdent);
150
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1589 }
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
1590
102
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
1591 /+++++++++++++++++++++++++++++
161
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1592 + Statement parsing methods +
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1593 +++++++++++++++++++++++++++++/
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1594
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1595 Statements parseStatements()
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1596 {
262
0f22269e76ff - Changed some string types to Token*.
aziz
parents: 261
diff changeset
1597 auto begin = token;
318
a1c9d93a66e3 - Added member prevToken to Parser.
aziz
parents: 314
diff changeset
1598 require(T.LBrace);
162
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
1599 auto statements = new Statements();
161
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1600 while (token.type != T.RBrace && token.type != T.EOF)
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1601 statements ~= parseStatement();
318
a1c9d93a66e3 - Added member prevToken to Parser.
aziz
parents: 314
diff changeset
1602 require(T.RBrace);
262
0f22269e76ff - Changed some string types to Token*.
aziz
parents: 261
diff changeset
1603 return set(statements, begin);
161
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1604 }
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1605
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1606 Statement parseStatement()
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1607 {
261
966756c5d5d3 - Added begin variables and calls to set().
aziz
parents: 260
diff changeset
1608 auto begin = token;
161
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1609 Statement s;
188
5c6ebf9f60a9 - Added code for parsing DeclarationStatement.
aziz
parents: 187
diff changeset
1610 Declaration d;
161
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1611 switch (token.type)
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1612 {
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1613 case T.Align:
260
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
1614 int size = -1;
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
1615 auto intTok = parseAlignAttribute();
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
1616 if (intTok)
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
1617 size = intTok.int_;
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
1618 // Restrict align attribute to structs in parsing phase.
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
1619 Declaration structDecl;
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
1620 if (token.type == T.Struct)
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
1621 structDecl = parseAggregateDeclaration();
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
1622 else
b83180748ae6 - Added method parseAlignAttribute().
aziz
parents: 259
diff changeset
1623 expected(T.Struct);
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 304
diff changeset
1624 d = new AlignDeclaration(size, structDecl ? structDecl : new Declarations);
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
1625 goto LreturnDeclarationStatement;
201
70715b9e2109 - Implemented parseAttributeStatement().
aziz
parents: 200
diff changeset
1626 /+ Not applicable for statements.
191
3ce110cefbc5 - Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents: 190
diff changeset
1627 // T.Private,
3ce110cefbc5 - Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents: 190
diff changeset
1628 // T.Package,
3ce110cefbc5 - Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents: 190
diff changeset
1629 // T.Protected,
3ce110cefbc5 - Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents: 190
diff changeset
1630 // T.Public,
3ce110cefbc5 - Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents: 190
diff changeset
1631 // T.Export,
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1632 // T.Deprecated,
191
3ce110cefbc5 - Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents: 190
diff changeset
1633 // T.Override,
3ce110cefbc5 - Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents: 190
diff changeset
1634 // T.Abstract,
201
70715b9e2109 - Implemented parseAttributeStatement().
aziz
parents: 200
diff changeset
1635 +/
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1636 case T.Extern,
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1637 T.Final,
191
3ce110cefbc5 - Added code for parsing AliasDeclaration and TypedefDeclaration.
aziz
parents: 190
diff changeset
1638 T.Const,
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1639 T.Auto:
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1640 //T.Scope
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1641 //T.Static
201
70715b9e2109 - Implemented parseAttributeStatement().
aziz
parents: 200
diff changeset
1642 case_parseAttribute:
70715b9e2109 - Implemented parseAttributeStatement().
aziz
parents: 200
diff changeset
1643 s = parseAttributeStatement();
261
966756c5d5d3 - Added begin variables and calls to set().
aziz
parents: 260
diff changeset
1644 return s;
161
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1645 case T.Identifier:
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1646 if (peekNext() == T.Colon)
161
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1647 {
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
1648 auto ident = token;
161
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1649 nT(); // Skip Identifier
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1650 nT(); // Skip :
234
5c1111dc8670 - Added method parseNoScopeOrEmptyStatement().
aziz
parents: 233
diff changeset
1651 s = new LabeledStatement(ident, parseNoScopeOrEmptyStatement());
161
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1652 break;
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1653 }
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
1654 goto case T.Dot;
201
70715b9e2109 - Implemented parseAttributeStatement().
aziz
parents: 200
diff changeset
1655 case T.Dot, T.Typeof:
214
45fc474c1678 - Changed 'failed' parameter of try_() to 'success'.
aziz
parents: 213
diff changeset
1656 bool success;
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
1657 d = try_({return parseDeclaration(StorageClass.None, false);}, success);
214
45fc474c1678 - Changed 'failed' parameter of try_() to 'success'.
aziz
parents: 213
diff changeset
1658 if (success)
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
1659 goto LreturnDeclarationStatement; // Declaration
201
70715b9e2109 - Implemented parseAttributeStatement().
aziz
parents: 200
diff changeset
1660 else
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
1661 goto case_parseExpressionStatement; // Expression
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
1662 // IntegralType
201
70715b9e2109 - Implemented parseAttributeStatement().
aziz
parents: 200
diff changeset
1663 case T.Char, T.Wchar, T.Dchar, T.Bool,
70715b9e2109 - Implemented parseAttributeStatement().
aziz
parents: 200
diff changeset
1664 T.Byte, T.Ubyte, T.Short, T.Ushort,
70715b9e2109 - Implemented parseAttributeStatement().
aziz
parents: 200
diff changeset
1665 T.Int, T.Uint, T.Long, T.Ulong,
70715b9e2109 - Implemented parseAttributeStatement().
aziz
parents: 200
diff changeset
1666 T.Float, T.Double, T.Real,
70715b9e2109 - Implemented parseAttributeStatement().
aziz
parents: 200
diff changeset
1667 T.Ifloat, T.Idouble, T.Ireal,
70715b9e2109 - Implemented parseAttributeStatement().
aziz
parents: 200
diff changeset
1668 T.Cfloat, T.Cdouble, T.Creal, T.Void:
70715b9e2109 - Implemented parseAttributeStatement().
aziz
parents: 200
diff changeset
1669 case_parseDeclaration:
70715b9e2109 - Implemented parseAttributeStatement().
aziz
parents: 200
diff changeset
1670 d = parseDeclaration();
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
1671 goto LreturnDeclarationStatement;
162
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
1672 case T.If:
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
1673 s = parseIfStatement();
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
1674 break;
164
8ec99326752b - Implemented parseWhileStatement().
aziz
parents: 163
diff changeset
1675 case T.While:
8ec99326752b - Implemented parseWhileStatement().
aziz
parents: 163
diff changeset
1676 s = parseWhileStatement();
8ec99326752b - Implemented parseWhileStatement().
aziz
parents: 163
diff changeset
1677 break;
165
797074d143d7 - Implemented parseDoWhileStatement().
aziz
parents: 164
diff changeset
1678 case T.Do:
797074d143d7 - Implemented parseDoWhileStatement().
aziz
parents: 164
diff changeset
1679 s = parseDoWhileStatement();
797074d143d7 - Implemented parseDoWhileStatement().
aziz
parents: 164
diff changeset
1680 break;
216
984d48932bce - Added class EmptyStatement.
aziz
parents: 214
diff changeset
1681 case T.For:
984d48932bce - Added class EmptyStatement.
aziz
parents: 214
diff changeset
1682 s = parseForStatement();
984d48932bce - Added class EmptyStatement.
aziz
parents: 214
diff changeset
1683 break;
169
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
1684 case T.Foreach, T.Foreach_reverse:
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
1685 s = parseForeachStatement();
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
1686 break;
170
a63696d1c474 - Implemented parseSwitchStatement().
aziz
parents: 169
diff changeset
1687 case T.Switch:
a63696d1c474 - Implemented parseSwitchStatement().
aziz
parents: 169
diff changeset
1688 s = parseSwitchStatement();
a63696d1c474 - Implemented parseSwitchStatement().
aziz
parents: 169
diff changeset
1689 break;
171
f1fa9bbdb4cb - Implemented parseCaseStatement().
aziz
parents: 170
diff changeset
1690 case T.Case:
f1fa9bbdb4cb - Implemented parseCaseStatement().
aziz
parents: 170
diff changeset
1691 s = parseCaseStatement();
f1fa9bbdb4cb - Implemented parseCaseStatement().
aziz
parents: 170
diff changeset
1692 break;
172
89d4519bd8a1 - Implemented parseDefaultStatement().
aziz
parents: 171
diff changeset
1693 case T.Default:
89d4519bd8a1 - Implemented parseDefaultStatement().
aziz
parents: 171
diff changeset
1694 s = parseDefaultStatement();
89d4519bd8a1 - Implemented parseDefaultStatement().
aziz
parents: 171
diff changeset
1695 break;
173
c2714ba44350 - Implemented parseContinueStatement().
aziz
parents: 172
diff changeset
1696 case T.Continue:
c2714ba44350 - Implemented parseContinueStatement().
aziz
parents: 172
diff changeset
1697 s = parseContinueStatement();
c2714ba44350 - Implemented parseContinueStatement().
aziz
parents: 172
diff changeset
1698 break;
174
e51c9ee66ea0 - Implemented parseBreakStatement().
aziz
parents: 173
diff changeset
1699 case T.Break:
e51c9ee66ea0 - Implemented parseBreakStatement().
aziz
parents: 173
diff changeset
1700 s = parseBreakStatement();
e51c9ee66ea0 - Implemented parseBreakStatement().
aziz
parents: 173
diff changeset
1701 break;
175
522df6f0f230 - Implemented parseReturnStatement().
aziz
parents: 174
diff changeset
1702 case T.Return:
522df6f0f230 - Implemented parseReturnStatement().
aziz
parents: 174
diff changeset
1703 s = parseReturnStatement();
522df6f0f230 - Implemented parseReturnStatement().
aziz
parents: 174
diff changeset
1704 break;
176
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
1705 case T.Goto:
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
1706 s = parseGotoStatement();
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
1707 break;
177
504b1b2f7c93 - Implemented parseWithStatement().
aziz
parents: 176
diff changeset
1708 case T.With:
504b1b2f7c93 - Implemented parseWithStatement().
aziz
parents: 176
diff changeset
1709 s = parseWithStatement();
504b1b2f7c93 - Implemented parseWithStatement().
aziz
parents: 176
diff changeset
1710 break;
178
62718b29679e - Implemented parseSynchronizedStatement().
aziz
parents: 177
diff changeset
1711 case T.Synchronized:
62718b29679e - Implemented parseSynchronizedStatement().
aziz
parents: 177
diff changeset
1712 s = parseSynchronizedStatement();
62718b29679e - Implemented parseSynchronizedStatement().
aziz
parents: 177
diff changeset
1713 break;
179
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
1714 case T.Try:
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
1715 s = parseTryStatement();
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
1716 break;
180
d5a67aa578a8 - Implemented parseThrowStatement().
aziz
parents: 179
diff changeset
1717 case T.Throw:
d5a67aa578a8 - Implemented parseThrowStatement().
aziz
parents: 179
diff changeset
1718 s = parseThrowStatement();
d5a67aa578a8 - Implemented parseThrowStatement().
aziz
parents: 179
diff changeset
1719 break;
181
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
1720 case T.Scope:
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1721 if (peekNext() != T.LParen)
201
70715b9e2109 - Implemented parseAttributeStatement().
aziz
parents: 200
diff changeset
1722 goto case_parseAttribute;
181
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
1723 s = parseScopeGuardStatement();
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
1724 break;
182
673b355ba0e9 - Implemented parseVolatileStatement().
aziz
parents: 181
diff changeset
1725 case T.Volatile:
673b355ba0e9 - Implemented parseVolatileStatement().
aziz
parents: 181
diff changeset
1726 s = parseVolatileStatement();
673b355ba0e9 - Implemented parseVolatileStatement().
aziz
parents: 181
diff changeset
1727 break;
183
c9df82f6f6be - Added parseAsmStatement() stub.
aziz
parents: 182
diff changeset
1728 case T.Asm:
c9df82f6f6be - Added parseAsmStatement() stub.
aziz
parents: 182
diff changeset
1729 s = parseAsmStatement();
c9df82f6f6be - Added parseAsmStatement() stub.
aziz
parents: 182
diff changeset
1730 break;
184
30a4c8522b09 - Implemented parsePragmaStatement().
aziz
parents: 183
diff changeset
1731 case T.Pragma:
30a4c8522b09 - Implemented parsePragmaStatement().
aziz
parents: 183
diff changeset
1732 s = parsePragmaStatement();
30a4c8522b09 - Implemented parsePragmaStatement().
aziz
parents: 183
diff changeset
1733 break;
185
35c93b776be0 - Added code for parsing MixinStatements.
aziz
parents: 184
diff changeset
1734 case T.Mixin:
246
52f4aa097865 - Fix: parse mixin as expression instead of statement when next token is T.LParen.
aziz
parents: 245
diff changeset
1735 if (peekNext() == T.LParen)
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
1736 goto case_parseExpressionStatement; // Parse as expression.
256
8f27920ae17a - Made parseMixinDeclaration() a template.
aziz
parents: 255
diff changeset
1737 s = parseMixin!(MixinStatement)();
185
35c93b776be0 - Added code for parsing MixinStatements.
aziz
parents: 184
diff changeset
1738 break;
186
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
1739 case T.Static:
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1740 switch (peekNext())
186
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
1741 {
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
1742 case T.If:
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
1743 s = parseStaticIfStatement();
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
1744 break;
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
1745 case T.Assert:
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
1746 s = parseStaticAssertStatement();
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
1747 break;
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
1748 default:
201
70715b9e2109 - Implemented parseAttributeStatement().
aziz
parents: 200
diff changeset
1749 goto case_parseAttribute;
186
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
1750 }
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1751 break;
190
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
1752 case T.Debug:
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
1753 s = parseDebugStatement();
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
1754 break;
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
1755 case T.Version:
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
1756 s = parseVersionStatement();
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
1757 break;
226
aa38e1401217 - Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents: 225
diff changeset
1758 // DeclDef
aa38e1401217 - Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents: 225
diff changeset
1759 case T.Alias, T.Typedef:
aa38e1401217 - Fixed cases T.Alias and T.Typedef. Wrong function called.
aziz
parents: 225
diff changeset
1760 d = parseDeclarationDefinition();
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
1761 goto LreturnDeclarationStatement;
188
5c6ebf9f60a9 - Added code for parsing DeclarationStatement.
aziz
parents: 187
diff changeset
1762 case T.Enum:
5c6ebf9f60a9 - Added code for parsing DeclarationStatement.
aziz
parents: 187
diff changeset
1763 d = parseEnumDeclaration();
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
1764 goto LreturnDeclarationStatement;
188
5c6ebf9f60a9 - Added code for parsing DeclarationStatement.
aziz
parents: 187
diff changeset
1765 case T.Class:
5c6ebf9f60a9 - Added code for parsing DeclarationStatement.
aziz
parents: 187
diff changeset
1766 d = parseClassDeclaration();
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
1767 goto LreturnDeclarationStatement;
188
5c6ebf9f60a9 - Added code for parsing DeclarationStatement.
aziz
parents: 187
diff changeset
1768 case T.Interface:
5c6ebf9f60a9 - Added code for parsing DeclarationStatement.
aziz
parents: 187
diff changeset
1769 d = parseInterfaceDeclaration();
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
1770 goto LreturnDeclarationStatement;
188
5c6ebf9f60a9 - Added code for parsing DeclarationStatement.
aziz
parents: 187
diff changeset
1771 case T.Struct, T.Union:
5c6ebf9f60a9 - Added code for parsing DeclarationStatement.
aziz
parents: 187
diff changeset
1772 d = parseAggregateDeclaration();
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
1773 // goto LreturnDeclarationStatement;
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
1774 LreturnDeclarationStatement:
261
966756c5d5d3 - Added begin variables and calls to set().
aziz
parents: 260
diff changeset
1775 set(d, begin);
188
5c6ebf9f60a9 - Added code for parsing DeclarationStatement.
aziz
parents: 187
diff changeset
1776 s = new DeclarationStatement(d);
5c6ebf9f60a9 - Added code for parsing DeclarationStatement.
aziz
parents: 187
diff changeset
1777 break;
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
1778 case T.LBrace:
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
1779 s = parseScopeStatement();
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
1780 break;
216
984d48932bce - Added class EmptyStatement.
aziz
parents: 214
diff changeset
1781 case T.Semicolon:
231
6846138a0e24 - Fixed parseEnumDeclaration().
aziz
parents: 230
diff changeset
1782 nT();
216
984d48932bce - Added class EmptyStatement.
aziz
parents: 214
diff changeset
1783 s = new EmptyStatement();
984d48932bce - Added class EmptyStatement.
aziz
parents: 214
diff changeset
1784 break;
400
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1785 /+
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1786 Parse ExpressionStatement:
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1787 +/
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1788 // Tokens that start a PrimaryExpression.
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1789 // case T.Identifier, T.Dot, T.Typeof:
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1790 case T.This:
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1791 case T.Super:
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1792 case T.Null:
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1793 case T.True, T.False:
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1794 // case T.Dollar:
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1795 case T.Int32, T.Int64, T.Uint32, T.Uint64:
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1796 case T.Float32, T.Float64, T.Float80,
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1797 T.Imaginary32, T.Imaginary64, T.Imaginary80:
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1798 case T.CharLiteral, T.WCharLiteral, T.DCharLiteral:
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1799 case T.String:
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1800 case T.LBracket:
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1801 // case T.LBrace:
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1802 case T.Function, T.Delegate:
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1803 case T.Assert:
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1804 // case T.Mixin:
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1805 case T.Import:
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1806 case T.Typeid:
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1807 case T.Is:
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1808 case T.LParen:
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1809 // IntegralType
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1810 /+case T.Char, T.Wchar, T.Dchar, T.Bool,
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1811 T.Byte, T.Ubyte, T.Short, T.Ushort,
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1812 T.Int, T.Uint, T.Long, T.Ulong,
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1813 T.Float, T.Double, T.Real,
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1814 T.Ifloat, T.Idouble, T.Ireal,
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1815 T.Cfloat, T.Cdouble, T.Creal, T.Void:+/
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1816 case T.Traits:
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1817 // Tokens that can start a UnaryExpression:
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1818 case T.AndBinary,
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1819 T.PlusPlus,
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1820 T.MinusMinus,
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1821 T.Mul,
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1822 T.Minus,
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1823 T.Plus,
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1824 T.Not,
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1825 T.Tilde,
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1826 T.New,
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1827 T.Delete,
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1828 T.Cast:
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
1829 case_parseExpressionStatement:
400
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1830 s = new ExpressionStatement(parseExpression());
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1831 require(T.Semicolon);
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1832 break;
161
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1833 default:
400
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1834 if (token.isSpecialToken)
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
1835 goto case_parseExpressionStatement;
400
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1836
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1837 // Assert that this isn't a valid expression.
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1838 assert(
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1839 delegate bool(){
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1840 bool success;
423
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
1841 auto expression = try_(&parseExpression, success);
400
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1842 return success;
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1843 }() == false, "Any token that could start a valid expression must have been caught by a case statement in parseStatement()."
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1844 );
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1845
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1846 // Report error: it's an illegal statement.
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1847 error(MID.ExpectedButFound, "Statement", token.srcText);
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1848 s = new IllegalStatement(token);
a0fa0dcfa50a Added case statements to switch in Parser.parseStatement().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 399
diff changeset
1849 nT();
161
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1850 }
205
e5a4f88982d1 - Added assert at the end of parseStatement().
aziz
parents: 204
diff changeset
1851 assert(s !is null);
261
966756c5d5d3 - Added begin variables and calls to set().
aziz
parents: 260
diff changeset
1852 set(s, begin);
161
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1853 return s;
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1854 }
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
1855
162
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
1856 /+
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
1857 ScopeStatement:
219
0d14a09227a4 - Simplified parseScopeStatement().
aziz
parents: 218
diff changeset
1858 NoScopeStatement
162
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
1859 +/
164
8ec99326752b - Implemented parseWhileStatement().
aziz
parents: 163
diff changeset
1860 Statement parseScopeStatement()
162
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
1861 {
219
0d14a09227a4 - Simplified parseScopeStatement().
aziz
parents: 218
diff changeset
1862 return new ScopeStatement(parseNoScopeStatement());
162
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
1863 }
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
1864
166
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1865 /+
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1866 NoScopeStatement:
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1867 NonEmptyStatement
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1868 BlockStatement
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1869 BlockStatement:
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1870 { }
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1871 { StatementList }
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1872 +/
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1873 Statement parseNoScopeStatement()
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1874 {
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1875 Statement s;
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1876 if (token.type == T.LBrace)
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1877 {
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1878 nT();
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1879 auto ss = new Statements();
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1880 while (token.type != T.RBrace && token.type != T.EOF)
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1881 ss ~= parseStatement();
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1882 require(T.RBrace);
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1883 s = ss;
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1884 }
219
0d14a09227a4 - Simplified parseScopeStatement().
aziz
parents: 218
diff changeset
1885 else if (token.type == T.Semicolon)
0d14a09227a4 - Simplified parseScopeStatement().
aziz
parents: 218
diff changeset
1886 {
0d14a09227a4 - Simplified parseScopeStatement().
aziz
parents: 218
diff changeset
1887 error(MID.ExpectedButFound, "non-empty statement", ";");
0d14a09227a4 - Simplified parseScopeStatement().
aziz
parents: 218
diff changeset
1888 s = new EmptyStatement();
0d14a09227a4 - Simplified parseScopeStatement().
aziz
parents: 218
diff changeset
1889 nT();
0d14a09227a4 - Simplified parseScopeStatement().
aziz
parents: 218
diff changeset
1890 }
166
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1891 else
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1892 s = parseStatement();
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1893 return s;
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1894 }
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
1895
234
5c1111dc8670 - Added method parseNoScopeOrEmptyStatement().
aziz
parents: 233
diff changeset
1896 /+
5c1111dc8670 - Added method parseNoScopeOrEmptyStatement().
aziz
parents: 233
diff changeset
1897 NoScopeOrEmptyStatement:
5c1111dc8670 - Added method parseNoScopeOrEmptyStatement().
aziz
parents: 233
diff changeset
1898 ;
5c1111dc8670 - Added method parseNoScopeOrEmptyStatement().
aziz
parents: 233
diff changeset
1899 NoScopeStatement
5c1111dc8670 - Added method parseNoScopeOrEmptyStatement().
aziz
parents: 233
diff changeset
1900 +/
5c1111dc8670 - Added method parseNoScopeOrEmptyStatement().
aziz
parents: 233
diff changeset
1901 Statement parseNoScopeOrEmptyStatement()
5c1111dc8670 - Added method parseNoScopeOrEmptyStatement().
aziz
parents: 233
diff changeset
1902 {
5c1111dc8670 - Added method parseNoScopeOrEmptyStatement().
aziz
parents: 233
diff changeset
1903 if (token.type == T.Semicolon)
312
fa0b6f32c1ae - Added Special to enum TOK.
aziz
parents: 305
diff changeset
1904 {
234
5c1111dc8670 - Added method parseNoScopeOrEmptyStatement().
aziz
parents: 233
diff changeset
1905 nT();
312
fa0b6f32c1ae - Added Special to enum TOK.
aziz
parents: 305
diff changeset
1906 return new EmptyStatement();
fa0b6f32c1ae - Added Special to enum TOK.
aziz
parents: 305
diff changeset
1907 }
234
5c1111dc8670 - Added method parseNoScopeOrEmptyStatement().
aziz
parents: 233
diff changeset
1908 else
5c1111dc8670 - Added method parseNoScopeOrEmptyStatement().
aziz
parents: 233
diff changeset
1909 return parseNoScopeStatement();
5c1111dc8670 - Added method parseNoScopeOrEmptyStatement().
aziz
parents: 233
diff changeset
1910 }
5c1111dc8670 - Added method parseNoScopeOrEmptyStatement().
aziz
parents: 233
diff changeset
1911
201
70715b9e2109 - Implemented parseAttributeStatement().
aziz
parents: 200
diff changeset
1912 Statement parseAttributeStatement()
70715b9e2109 - Implemented parseAttributeStatement().
aziz
parents: 200
diff changeset
1913 {
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1914 StorageClass stc, tmp;
359
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
1915 Linkage.Category link_cat;
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1916
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1917 void addStorageClass()
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1918 {
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1919 if (stc & tmp)
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1920 {
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1921 error(MID.RedundantStorageClass, token.srcText);
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1922 }
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1923 else
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1924 stc |= tmp;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1925 }
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1926
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1927 Statement parse()
201
70715b9e2109 - Implemented parseAttributeStatement().
aziz
parents: 200
diff changeset
1928 {
261
966756c5d5d3 - Added begin variables and calls to set().
aziz
parents: 260
diff changeset
1929 auto begin = token;
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1930 Statement s;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1931 switch (token.type)
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1932 {
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1933 case T.Extern:
359
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
1934 stc |= StorageClass.Extern;
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1935 nT();
359
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
1936 Linkage linkage = parseLinkage();
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
1937
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
1938 // Check for redundancy.
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
1939 Linkage.Category link_cat_tmp = Linkage.getCategory(linkage);
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
1940 if (link_cat & link_cat_tmp)
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1941 {
359
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
1942 char[] srcText = begin.srcText;
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
1943 if (link_cat_tmp == Linkage.Category.MangleSymbol)
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
1944 srcText = begin.start[0 .. prevToken.end - begin.start];
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
1945 error(MID.RedundantStorageClass, srcText);
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1946 }
359
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
1947 else
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
1948 link_cat |= link_cat_tmp;
511c14950cac - Added messages MissingLinkageType and UnrecognizedLinkageType.
aziz
parents: 358
diff changeset
1949
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1950 s = new ExternStatement(linkage, parse());
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1951 break;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1952 case T.Static:
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1953 tmp = StorageClass.Static;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1954 goto Lcommon;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1955 case T.Final:
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1956 tmp = StorageClass.Final;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1957 goto Lcommon;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1958 case T.Const:
270
764eccdf619d - Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents: 269
diff changeset
1959 version(D2)
764eccdf619d - Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents: 269
diff changeset
1960 {
764eccdf619d - Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents: 269
diff changeset
1961 if (peekNext() == T.LParen)
764eccdf619d - Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents: 269
diff changeset
1962 goto case_Declaration;
764eccdf619d - Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents: 269
diff changeset
1963 }
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1964 tmp = StorageClass.Const;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1965 goto Lcommon;
270
764eccdf619d - Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents: 269
diff changeset
1966 version(D2)
764eccdf619d - Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents: 269
diff changeset
1967 {
764eccdf619d - Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents: 269
diff changeset
1968 case T.Invariant: // D 2.0
764eccdf619d - Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents: 269
diff changeset
1969 if (peekNext() == T.LParen)
764eccdf619d - Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents: 269
diff changeset
1970 goto case_Declaration;
764eccdf619d - Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents: 269
diff changeset
1971 tmp = StorageClass.Invariant;
764eccdf619d - Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents: 269
diff changeset
1972 goto Lcommon;
764eccdf619d - Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents: 269
diff changeset
1973 }
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1974 case T.Auto:
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1975 tmp = StorageClass.Auto;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1976 goto Lcommon;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1977 case T.Scope:
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1978 tmp = StorageClass.Scope;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1979 goto Lcommon;
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1980 Lcommon:
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1981 addStorageClass();
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
1982 auto tok = token.type;
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1983 nT();
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
1984 s = new AttributeStatement(tok, parse());
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1985 break;
239
7911f6a92e6e - Added 'new' and 'delete' declarations to Token and uncommented next and prev members. Added HEAD to TOK.
aziz
parents: 238
diff changeset
1986 // TODO: allow "scope class", "abstract scope class" in function bodies?
7911f6a92e6e - Added 'new' and 'delete' declarations to Token and uncommented next and prev members. Added HEAD to TOK.
aziz
parents: 238
diff changeset
1987 //case T.Class:
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1988 default:
270
764eccdf619d - Fix in parseAttributeStatement(): added checks for T.LParen after const/invariant.
aziz
parents: 269
diff changeset
1989 case_Declaration:
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1990 s = new DeclarationStatement(parseDeclaration(stc));
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1991 }
261
966756c5d5d3 - Added begin variables and calls to set().
aziz
parents: 260
diff changeset
1992 set(s, begin);
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1993 return s;
201
70715b9e2109 - Implemented parseAttributeStatement().
aziz
parents: 200
diff changeset
1994 }
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
1995 return parse();
201
70715b9e2109 - Implemented parseAttributeStatement().
aziz
parents: 200
diff changeset
1996 }
70715b9e2109 - Implemented parseAttributeStatement().
aziz
parents: 200
diff changeset
1997
162
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
1998 Statement parseIfStatement()
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
1999 {
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2000 assert(token.type == T.If);
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2001 nT();
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2002
283
df657dd98ffa - Fix: added member type to VariableDeclaration.
aziz
parents: 282
diff changeset
2003 Statement variable;
162
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2004 Expression condition;
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2005 Statement ifBody, elseBody;
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2006
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2007 require(T.LParen);
283
df657dd98ffa - Fix: added member type to VariableDeclaration.
aziz
parents: 282
diff changeset
2008
df657dd98ffa - Fix: added member type to VariableDeclaration.
aziz
parents: 282
diff changeset
2009 Token* ident;
162
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2010 // auto Identifier = Expression
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2011 if (token.type == T.Auto)
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2012 {
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2013 nT();
253
4279b638c63e - Changed some string types to Token*. Adapted parser accordingly.
aziz
parents: 252
diff changeset
2014 ident = requireId();
162
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2015 require(T.Assign);
283
df657dd98ffa - Fix: added member type to VariableDeclaration.
aziz
parents: 282
diff changeset
2016 auto init = parseExpression();
367
dda55fae37de - ImportGraph.execute() can parse all modules depending on the imports of the root module.
aziz
parents: 366
diff changeset
2017 variable = new AttributeStatement(T.Auto, new DeclarationStatement(new VariableDeclaration(null, [ident], [init])));
162
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2018 }
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2019 else
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2020 {
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2021 // Declarator = Expression
237
805796880adb - Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents: 236
diff changeset
2022 Type parseDeclaratorAssign()
162
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2023 {
237
805796880adb - Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents: 236
diff changeset
2024 auto type = parseDeclarator(ident);
162
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2025 require(T.Assign);
237
805796880adb - Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents: 236
diff changeset
2026 return type;
162
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2027 }
237
805796880adb - Fix in parseIfStatement(): require(T.Assign) must be encompassed by a try_() call.
aziz
parents: 236
diff changeset
2028 bool success;
423
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
2029 auto type = try_(&parseDeclaratorAssign, success);
283
df657dd98ffa - Fix: added member type to VariableDeclaration.
aziz
parents: 282
diff changeset
2030 if (success)
163
f27a98bb17c7 - Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents: 162
diff changeset
2031 {
283
df657dd98ffa - Fix: added member type to VariableDeclaration.
aziz
parents: 282
diff changeset
2032 auto init = parseExpression();
df657dd98ffa - Fix: added member type to VariableDeclaration.
aziz
parents: 282
diff changeset
2033 variable = new DeclarationStatement(new VariableDeclaration(type, [ident], [init]));
163
f27a98bb17c7 - Fix: when parsing Declarator fails, type and ident is set to null.
aziz
parents: 162
diff changeset
2034 }
283
df657dd98ffa - Fix: added member type to VariableDeclaration.
aziz
parents: 282
diff changeset
2035 else
df657dd98ffa - Fix: added member type to VariableDeclaration.
aziz
parents: 282
diff changeset
2036 condition = parseExpression();
162
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2037 }
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2038 require(T.RParen);
164
8ec99326752b - Implemented parseWhileStatement().
aziz
parents: 163
diff changeset
2039 ifBody = parseScopeStatement();
162
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2040 if (token.type == T.Else)
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2041 {
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2042 nT();
164
8ec99326752b - Implemented parseWhileStatement().
aziz
parents: 163
diff changeset
2043 elseBody = parseScopeStatement();
162
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2044 }
283
df657dd98ffa - Fix: added member type to VariableDeclaration.
aziz
parents: 282
diff changeset
2045 return new IfStatement(variable, condition, ifBody, elseBody);
162
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2046 }
c7b250662c74 - Added class ScopeStatement.
aziz
parents: 161
diff changeset
2047
164
8ec99326752b - Implemented parseWhileStatement().
aziz
parents: 163
diff changeset
2048 Statement parseWhileStatement()
8ec99326752b - Implemented parseWhileStatement().
aziz
parents: 163
diff changeset
2049 {
8ec99326752b - Implemented parseWhileStatement().
aziz
parents: 163
diff changeset
2050 assert(token.type == T.While);
8ec99326752b - Implemented parseWhileStatement().
aziz
parents: 163
diff changeset
2051 nT();
166
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
2052 require(T.LParen);
164
8ec99326752b - Implemented parseWhileStatement().
aziz
parents: 163
diff changeset
2053 auto condition = parseExpression();
166
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
2054 require(T.RParen);
164
8ec99326752b - Implemented parseWhileStatement().
aziz
parents: 163
diff changeset
2055 return new WhileStatement(condition, parseScopeStatement());
8ec99326752b - Implemented parseWhileStatement().
aziz
parents: 163
diff changeset
2056 }
8ec99326752b - Implemented parseWhileStatement().
aziz
parents: 163
diff changeset
2057
165
797074d143d7 - Implemented parseDoWhileStatement().
aziz
parents: 164
diff changeset
2058 Statement parseDoWhileStatement()
797074d143d7 - Implemented parseDoWhileStatement().
aziz
parents: 164
diff changeset
2059 {
797074d143d7 - Implemented parseDoWhileStatement().
aziz
parents: 164
diff changeset
2060 assert(token.type == T.Do);
797074d143d7 - Implemented parseDoWhileStatement().
aziz
parents: 164
diff changeset
2061 nT();
797074d143d7 - Implemented parseDoWhileStatement().
aziz
parents: 164
diff changeset
2062 auto doBody = parseScopeStatement();
797074d143d7 - Implemented parseDoWhileStatement().
aziz
parents: 164
diff changeset
2063 require(T.While);
166
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
2064 require(T.LParen);
165
797074d143d7 - Implemented parseDoWhileStatement().
aziz
parents: 164
diff changeset
2065 auto condition = parseExpression();
166
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
2066 require(T.RParen);
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
2067 return new DoWhileStatement(condition, doBody);
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
2068 }
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
2069
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
2070 Statement parseForStatement()
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
2071 {
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
2072 assert(token.type == T.For);
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
2073 nT();
165
797074d143d7 - Implemented parseDoWhileStatement().
aziz
parents: 164
diff changeset
2074 require(T.LParen);
166
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
2075
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
2076 Statement init, forBody;
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
2077 Expression condition, increment;
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
2078
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
2079 if (token.type != T.Semicolon)
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
2080 init = parseNoScopeStatement();
230
8f1790d16753 - Fix: added missing call to parseDeclaratorSuffx() in parseDeclaration.
aziz
parents: 229
diff changeset
2081 else
8f1790d16753 - Fix: added missing call to parseDeclaratorSuffx() in parseDeclaration.
aziz
parents: 229
diff changeset
2082 nT(); // Skip ;
166
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
2083 if (token.type != T.Semicolon)
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
2084 condition = parseExpression();
168
fbbb2434bf6b - Simplified parseForStatement().
aziz
parents: 167
diff changeset
2085 require(T.Semicolon);
166
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
2086 if (token.type != T.RParen)
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
2087 increment = parseExpression();
168
fbbb2434bf6b - Simplified parseForStatement().
aziz
parents: 167
diff changeset
2088 require(T.RParen);
167
141b908e32b6 - Fix: forgot parsing forBody.
aziz
parents: 166
diff changeset
2089 forBody = parseScopeStatement();
166
56334292a29e - Implemented parseForStatement().
aziz
parents: 165
diff changeset
2090 return new ForStatement(init, condition, increment, forBody);
165
797074d143d7 - Implemented parseDoWhileStatement().
aziz
parents: 164
diff changeset
2091 }
797074d143d7 - Implemented parseDoWhileStatement().
aziz
parents: 164
diff changeset
2092
169
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2093 Statement parseForeachStatement()
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2094 {
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2095 assert(token.type == T.Foreach || token.type == T.Foreach_reverse);
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2096 TOK tok = token.type;
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2097 nT();
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2098
257
6c58366ba1eb - Fix: need to allocate Parameters.
aziz
parents: 256
diff changeset
2099 auto params = new Parameters;
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
2100 Expression e; // Aggregate or LwrExpression
169
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2101
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2102 require(T.LParen);
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2103 while (1)
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2104 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
2105 auto paramBegin = token;
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
2106 Token* stcTok;
169
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2107 Type type;
253
4279b638c63e - Changed some string types to Token*. Adapted parser accordingly.
aziz
parents: 252
diff changeset
2108 Token* ident;
169
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2109
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2110 switch (token.type)
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2111 {
236
e961d1b957c3 - Fix in parseForeachStatement(): added T.Inout to case T.Ref; removed break statement.
aziz
parents: 235
diff changeset
2112 case T.Ref, T.Inout:
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
2113 stcTok = token;
169
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2114 nT();
236
e961d1b957c3 - Fix in parseForeachStatement(): added T.Inout to case T.Ref; removed break statement.
aziz
parents: 235
diff changeset
2115 // fall through
169
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2116 case T.Identifier:
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
2117 auto next = peekNext();
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
2118 if (next == T.Comma || next == T.Semicolon || next == T.RParen)
169
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2119 {
253
4279b638c63e - Changed some string types to Token*. Adapted parser accordingly.
aziz
parents: 252
diff changeset
2120 ident = token;
169
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2121 nT();
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2122 break;
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2123 }
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2124 // fall through
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2125 default:
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2126 type = parseDeclarator(ident);
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2127 }
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2128
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
2129 params ~= set(new Parameter(stcTok, type, ident, null), paramBegin);
169
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2130
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2131 if (token.type != T.Comma)
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2132 break;
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2133 nT();
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2134 }
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2135 require(T.Semicolon);
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
2136 e = parseExpression();
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
2137 version(D2)
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
2138 { //Foreach (ForeachType; LwrExpression .. UprExpression ) ScopeStatement
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
2139 if (token.type == T.Slice)
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
2140 {
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
2141 // if (params.length != 1)
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
2142 // error(MID.XYZ); // TODO: issue error msg
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
2143 nT();
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
2144 auto upper = parseExpression();
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
2145 require(T.RParen);
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
2146 auto forBody = parseScopeStatement();
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
2147 return new ForeachRangeStatement(tok, params, e, upper, forBody);
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
2148 }
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
2149 }
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
2150 // Foreach (ForeachTypeList; Aggregate) ScopeStatement
169
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2151 require(T.RParen);
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2152 auto forBody = parseScopeStatement();
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
2153 return new ForeachStatement(tok, params, e, forBody);
169
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2154 }
4666a05dfacf - Implemented parseForeachStatement().
aziz
parents: 168
diff changeset
2155
170
a63696d1c474 - Implemented parseSwitchStatement().
aziz
parents: 169
diff changeset
2156 Statement parseSwitchStatement()
a63696d1c474 - Implemented parseSwitchStatement().
aziz
parents: 169
diff changeset
2157 {
a63696d1c474 - Implemented parseSwitchStatement().
aziz
parents: 169
diff changeset
2158 assert(token.type == T.Switch);
a63696d1c474 - Implemented parseSwitchStatement().
aziz
parents: 169
diff changeset
2159 nT();
a63696d1c474 - Implemented parseSwitchStatement().
aziz
parents: 169
diff changeset
2160
a63696d1c474 - Implemented parseSwitchStatement().
aziz
parents: 169
diff changeset
2161 require(T.LParen);
a63696d1c474 - Implemented parseSwitchStatement().
aziz
parents: 169
diff changeset
2162 auto condition = parseExpression();
a63696d1c474 - Implemented parseSwitchStatement().
aziz
parents: 169
diff changeset
2163 require(T.RParen);
a63696d1c474 - Implemented parseSwitchStatement().
aziz
parents: 169
diff changeset
2164 auto switchBody = parseScopeStatement();
a63696d1c474 - Implemented parseSwitchStatement().
aziz
parents: 169
diff changeset
2165 return new SwitchStatement(condition, switchBody);
a63696d1c474 - Implemented parseSwitchStatement().
aziz
parents: 169
diff changeset
2166 }
a63696d1c474 - Implemented parseSwitchStatement().
aziz
parents: 169
diff changeset
2167
220
0c647e319b8e - Removed assert from parseStatement().
aziz
parents: 219
diff changeset
2168 Statement parseCaseDefaultBody()
0c647e319b8e - Removed assert from parseStatement().
aziz
parents: 219
diff changeset
2169 {
0c647e319b8e - Removed assert from parseStatement().
aziz
parents: 219
diff changeset
2170 // This function is similar to parseNoScopeStatement()
224
f838a37a25bd - Fixed parseCaseDefaultBody().
aziz
parents: 223
diff changeset
2171 auto s = new Statements();
f838a37a25bd - Fixed parseCaseDefaultBody().
aziz
parents: 223
diff changeset
2172 while (token.type != T.Case &&
f838a37a25bd - Fixed parseCaseDefaultBody().
aziz
parents: 223
diff changeset
2173 token.type != T.Default &&
f838a37a25bd - Fixed parseCaseDefaultBody().
aziz
parents: 223
diff changeset
2174 token.type != T.RBrace &&
f838a37a25bd - Fixed parseCaseDefaultBody().
aziz
parents: 223
diff changeset
2175 token.type != T.EOF)
f838a37a25bd - Fixed parseCaseDefaultBody().
aziz
parents: 223
diff changeset
2176 s ~= parseStatement();
220
0c647e319b8e - Removed assert from parseStatement().
aziz
parents: 219
diff changeset
2177 return new ScopeStatement(s);
0c647e319b8e - Removed assert from parseStatement().
aziz
parents: 219
diff changeset
2178 }
0c647e319b8e - Removed assert from parseStatement().
aziz
parents: 219
diff changeset
2179
171
f1fa9bbdb4cb - Implemented parseCaseStatement().
aziz
parents: 170
diff changeset
2180 Statement parseCaseStatement()
f1fa9bbdb4cb - Implemented parseCaseStatement().
aziz
parents: 170
diff changeset
2181 {
f1fa9bbdb4cb - Implemented parseCaseStatement().
aziz
parents: 170
diff changeset
2182 assert(token.type == T.Case);
f1fa9bbdb4cb - Implemented parseCaseStatement().
aziz
parents: 170
diff changeset
2183 // T.Case skipped in do-while.
f1fa9bbdb4cb - Implemented parseCaseStatement().
aziz
parents: 170
diff changeset
2184 Expression[] values;
f1fa9bbdb4cb - Implemented parseCaseStatement().
aziz
parents: 170
diff changeset
2185 do
f1fa9bbdb4cb - Implemented parseCaseStatement().
aziz
parents: 170
diff changeset
2186 {
f1fa9bbdb4cb - Implemented parseCaseStatement().
aziz
parents: 170
diff changeset
2187 nT();
f1fa9bbdb4cb - Implemented parseCaseStatement().
aziz
parents: 170
diff changeset
2188 values ~= parseAssignExpression();
f1fa9bbdb4cb - Implemented parseCaseStatement().
aziz
parents: 170
diff changeset
2189 } while (token.type == T.Comma)
f1fa9bbdb4cb - Implemented parseCaseStatement().
aziz
parents: 170
diff changeset
2190 require(T.Colon);
f1fa9bbdb4cb - Implemented parseCaseStatement().
aziz
parents: 170
diff changeset
2191
220
0c647e319b8e - Removed assert from parseStatement().
aziz
parents: 219
diff changeset
2192 auto caseBody = parseCaseDefaultBody();
171
f1fa9bbdb4cb - Implemented parseCaseStatement().
aziz
parents: 170
diff changeset
2193 return new CaseStatement(values, caseBody);
f1fa9bbdb4cb - Implemented parseCaseStatement().
aziz
parents: 170
diff changeset
2194 }
f1fa9bbdb4cb - Implemented parseCaseStatement().
aziz
parents: 170
diff changeset
2195
172
89d4519bd8a1 - Implemented parseDefaultStatement().
aziz
parents: 171
diff changeset
2196 Statement parseDefaultStatement()
89d4519bd8a1 - Implemented parseDefaultStatement().
aziz
parents: 171
diff changeset
2197 {
89d4519bd8a1 - Implemented parseDefaultStatement().
aziz
parents: 171
diff changeset
2198 assert(token.type == T.Default);
89d4519bd8a1 - Implemented parseDefaultStatement().
aziz
parents: 171
diff changeset
2199 nT();
89d4519bd8a1 - Implemented parseDefaultStatement().
aziz
parents: 171
diff changeset
2200 require(T.Colon);
220
0c647e319b8e - Removed assert from parseStatement().
aziz
parents: 219
diff changeset
2201 return new DefaultStatement(parseCaseDefaultBody());
172
89d4519bd8a1 - Implemented parseDefaultStatement().
aziz
parents: 171
diff changeset
2202 }
89d4519bd8a1 - Implemented parseDefaultStatement().
aziz
parents: 171
diff changeset
2203
173
c2714ba44350 - Implemented parseContinueStatement().
aziz
parents: 172
diff changeset
2204 Statement parseContinueStatement()
c2714ba44350 - Implemented parseContinueStatement().
aziz
parents: 172
diff changeset
2205 {
c2714ba44350 - Implemented parseContinueStatement().
aziz
parents: 172
diff changeset
2206 assert(token.type == T.Continue);
c2714ba44350 - Implemented parseContinueStatement().
aziz
parents: 172
diff changeset
2207 nT();
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2208 Token* ident;
173
c2714ba44350 - Implemented parseContinueStatement().
aziz
parents: 172
diff changeset
2209 if (token.type == T.Identifier)
c2714ba44350 - Implemented parseContinueStatement().
aziz
parents: 172
diff changeset
2210 {
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2211 ident = token;
173
c2714ba44350 - Implemented parseContinueStatement().
aziz
parents: 172
diff changeset
2212 nT();
c2714ba44350 - Implemented parseContinueStatement().
aziz
parents: 172
diff changeset
2213 }
c2714ba44350 - Implemented parseContinueStatement().
aziz
parents: 172
diff changeset
2214 require(T.Semicolon);
c2714ba44350 - Implemented parseContinueStatement().
aziz
parents: 172
diff changeset
2215 return new ContinueStatement(ident);
c2714ba44350 - Implemented parseContinueStatement().
aziz
parents: 172
diff changeset
2216 }
c2714ba44350 - Implemented parseContinueStatement().
aziz
parents: 172
diff changeset
2217
174
e51c9ee66ea0 - Implemented parseBreakStatement().
aziz
parents: 173
diff changeset
2218 Statement parseBreakStatement()
e51c9ee66ea0 - Implemented parseBreakStatement().
aziz
parents: 173
diff changeset
2219 {
e51c9ee66ea0 - Implemented parseBreakStatement().
aziz
parents: 173
diff changeset
2220 assert(token.type == T.Break);
e51c9ee66ea0 - Implemented parseBreakStatement().
aziz
parents: 173
diff changeset
2221 nT();
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2222 Token* ident;
174
e51c9ee66ea0 - Implemented parseBreakStatement().
aziz
parents: 173
diff changeset
2223 if (token.type == T.Identifier)
e51c9ee66ea0 - Implemented parseBreakStatement().
aziz
parents: 173
diff changeset
2224 {
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2225 ident = token;
174
e51c9ee66ea0 - Implemented parseBreakStatement().
aziz
parents: 173
diff changeset
2226 nT();
e51c9ee66ea0 - Implemented parseBreakStatement().
aziz
parents: 173
diff changeset
2227 }
e51c9ee66ea0 - Implemented parseBreakStatement().
aziz
parents: 173
diff changeset
2228 require(T.Semicolon);
e51c9ee66ea0 - Implemented parseBreakStatement().
aziz
parents: 173
diff changeset
2229 return new BreakStatement(ident);
e51c9ee66ea0 - Implemented parseBreakStatement().
aziz
parents: 173
diff changeset
2230 }
e51c9ee66ea0 - Implemented parseBreakStatement().
aziz
parents: 173
diff changeset
2231
175
522df6f0f230 - Implemented parseReturnStatement().
aziz
parents: 174
diff changeset
2232 Statement parseReturnStatement()
522df6f0f230 - Implemented parseReturnStatement().
aziz
parents: 174
diff changeset
2233 {
522df6f0f230 - Implemented parseReturnStatement().
aziz
parents: 174
diff changeset
2234 assert(token.type == T.Return);
522df6f0f230 - Implemented parseReturnStatement().
aziz
parents: 174
diff changeset
2235 nT();
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
2236 Expression expr;
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
2237 if (token.type != T.Semicolon)
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
2238 expr = parseExpression();
175
522df6f0f230 - Implemented parseReturnStatement().
aziz
parents: 174
diff changeset
2239 require(T.Semicolon);
522df6f0f230 - Implemented parseReturnStatement().
aziz
parents: 174
diff changeset
2240 return new ReturnStatement(expr);
522df6f0f230 - Implemented parseReturnStatement().
aziz
parents: 174
diff changeset
2241 }
522df6f0f230 - Implemented parseReturnStatement().
aziz
parents: 174
diff changeset
2242
176
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
2243 Statement parseGotoStatement()
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
2244 {
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
2245 assert(token.type == T.Goto);
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
2246 nT();
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2247 Token* ident;
176
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
2248 Expression caseExpr;
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
2249 switch (token.type)
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
2250 {
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
2251 case T.Case:
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
2252 nT();
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
2253 if (token.type == T.Semicolon)
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
2254 break;
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
2255 caseExpr = parseExpression();
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
2256 break;
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
2257 case T.Default:
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
2258 nT();
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
2259 break;
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
2260 default:
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2261 ident = requireId();
176
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
2262 }
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
2263 require(T.Semicolon);
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
2264 return new GotoStatement(ident, caseExpr);
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
2265 }
3071522c0cf0 - Implemented parseGotoStatement().
aziz
parents: 175
diff changeset
2266
177
504b1b2f7c93 - Implemented parseWithStatement().
aziz
parents: 176
diff changeset
2267 Statement parseWithStatement()
504b1b2f7c93 - Implemented parseWithStatement().
aziz
parents: 176
diff changeset
2268 {
504b1b2f7c93 - Implemented parseWithStatement().
aziz
parents: 176
diff changeset
2269 assert(token.type == T.With);
504b1b2f7c93 - Implemented parseWithStatement().
aziz
parents: 176
diff changeset
2270 nT();
504b1b2f7c93 - Implemented parseWithStatement().
aziz
parents: 176
diff changeset
2271 require(T.LParen);
504b1b2f7c93 - Implemented parseWithStatement().
aziz
parents: 176
diff changeset
2272 auto expr = parseExpression();
504b1b2f7c93 - Implemented parseWithStatement().
aziz
parents: 176
diff changeset
2273 require(T.RParen);
504b1b2f7c93 - Implemented parseWithStatement().
aziz
parents: 176
diff changeset
2274 return new WithStatement(expr, parseScopeStatement());
504b1b2f7c93 - Implemented parseWithStatement().
aziz
parents: 176
diff changeset
2275 }
504b1b2f7c93 - Implemented parseWithStatement().
aziz
parents: 176
diff changeset
2276
178
62718b29679e - Implemented parseSynchronizedStatement().
aziz
parents: 177
diff changeset
2277 Statement parseSynchronizedStatement()
62718b29679e - Implemented parseSynchronizedStatement().
aziz
parents: 177
diff changeset
2278 {
62718b29679e - Implemented parseSynchronizedStatement().
aziz
parents: 177
diff changeset
2279 assert(token.type == T.Synchronized);
62718b29679e - Implemented parseSynchronizedStatement().
aziz
parents: 177
diff changeset
2280 nT();
62718b29679e - Implemented parseSynchronizedStatement().
aziz
parents: 177
diff changeset
2281 Expression expr;
62718b29679e - Implemented parseSynchronizedStatement().
aziz
parents: 177
diff changeset
2282
62718b29679e - Implemented parseSynchronizedStatement().
aziz
parents: 177
diff changeset
2283 if (token.type == T.LParen)
62718b29679e - Implemented parseSynchronizedStatement().
aziz
parents: 177
diff changeset
2284 {
62718b29679e - Implemented parseSynchronizedStatement().
aziz
parents: 177
diff changeset
2285 nT();
62718b29679e - Implemented parseSynchronizedStatement().
aziz
parents: 177
diff changeset
2286 expr = parseExpression();
62718b29679e - Implemented parseSynchronizedStatement().
aziz
parents: 177
diff changeset
2287 require(T.RParen);
62718b29679e - Implemented parseSynchronizedStatement().
aziz
parents: 177
diff changeset
2288 }
62718b29679e - Implemented parseSynchronizedStatement().
aziz
parents: 177
diff changeset
2289 return new SynchronizedStatement(expr, parseScopeStatement());
62718b29679e - Implemented parseSynchronizedStatement().
aziz
parents: 177
diff changeset
2290 }
62718b29679e - Implemented parseSynchronizedStatement().
aziz
parents: 177
diff changeset
2291
179
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2292 Statement parseTryStatement()
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2293 {
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2294 assert(token.type == T.Try);
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2295 nT();
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2296
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2297 auto tryBody = parseScopeStatement();
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2298 CatchBody[] catchBodies;
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2299 FinallyBody finBody;
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2300
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2301 while (token.type == T.Catch)
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2302 {
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2303 nT();
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2304 Parameter param;
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2305 if (token.type == T.LParen)
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2306 {
229
a88967db063b - Fix: skip T.LParen in parseTryStatement().
aziz
parents: 228
diff changeset
2307 nT();
253
4279b638c63e - Changed some string types to Token*. Adapted parser accordingly.
aziz
parents: 252
diff changeset
2308 Token* ident;
369
27767e203d64 - Added override attribute to ImportParser.start().
aziz
parents: 368
diff changeset
2309 auto type = parseDeclarator(ident, true);
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
2310 param = new Parameter(null, type, ident, null);
179
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2311 require(T.RParen);
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2312 }
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2313 catchBodies ~= new CatchBody(param, parseNoScopeStatement());
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2314 if (param is null)
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2315 break; // This is a LastCatch
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2316 }
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2317
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2318 if (token.type == T.Finally)
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2319 {
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2320 nT();
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2321 finBody = new FinallyBody(parseNoScopeStatement());
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2322 }
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2323
396
0a4619735ce9 Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 391
diff changeset
2324 if (catchBodies.length == 0 && finBody is null)
179
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2325 {
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2326 // TODO: issue error msg.
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2327 }
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2328
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2329 return new TryStatement(tryBody, catchBodies, finBody);
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2330 }
507998c5c1ce - Implemented parseTryStatement().
aziz
parents: 178
diff changeset
2331
180
d5a67aa578a8 - Implemented parseThrowStatement().
aziz
parents: 179
diff changeset
2332 Statement parseThrowStatement()
d5a67aa578a8 - Implemented parseThrowStatement().
aziz
parents: 179
diff changeset
2333 {
d5a67aa578a8 - Implemented parseThrowStatement().
aziz
parents: 179
diff changeset
2334 assert(token.type == T.Throw);
d5a67aa578a8 - Implemented parseThrowStatement().
aziz
parents: 179
diff changeset
2335 nT();
d5a67aa578a8 - Implemented parseThrowStatement().
aziz
parents: 179
diff changeset
2336 auto expr = parseExpression();
d5a67aa578a8 - Implemented parseThrowStatement().
aziz
parents: 179
diff changeset
2337 require(T.Semicolon);
d5a67aa578a8 - Implemented parseThrowStatement().
aziz
parents: 179
diff changeset
2338 return new ThrowStatement(expr);
d5a67aa578a8 - Implemented parseThrowStatement().
aziz
parents: 179
diff changeset
2339 }
d5a67aa578a8 - Implemented parseThrowStatement().
aziz
parents: 179
diff changeset
2340
181
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
2341 Statement parseScopeGuardStatement()
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
2342 {
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
2343 assert(token.type == T.Scope);
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
2344 nT();
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
2345 assert(token.type == T.LParen);
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
2346 nT();
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
2347
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2348 Token* condition = requireId();
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2349 if (condition)
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2350 switch (condition.identifier)
181
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
2351 {
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
2352 case "exit":
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
2353 case "success":
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
2354 case "failure":
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
2355 break;
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
2356 default:
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
2357 // TODO: issue error msg.
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
2358 }
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
2359 require(T.RParen);
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
2360 Statement scopeBody;
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
2361 if (token.type == T.LBrace)
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
2362 scopeBody = parseScopeStatement();
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
2363 else
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
2364 scopeBody = parseNoScopeStatement();
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
2365 return new ScopeGuardStatement(condition, scopeBody);
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
2366 }
abfd51142477 - Implemented parseScopeGuardStatement().
aziz
parents: 180
diff changeset
2367
182
673b355ba0e9 - Implemented parseVolatileStatement().
aziz
parents: 181
diff changeset
2368 Statement parseVolatileStatement()
673b355ba0e9 - Implemented parseVolatileStatement().
aziz
parents: 181
diff changeset
2369 {
673b355ba0e9 - Implemented parseVolatileStatement().
aziz
parents: 181
diff changeset
2370 assert(token.type == T.Volatile);
673b355ba0e9 - Implemented parseVolatileStatement().
aziz
parents: 181
diff changeset
2371 nT();
673b355ba0e9 - Implemented parseVolatileStatement().
aziz
parents: 181
diff changeset
2372 Statement volatileBody;
673b355ba0e9 - Implemented parseVolatileStatement().
aziz
parents: 181
diff changeset
2373 if (token.type == T.Semicolon)
673b355ba0e9 - Implemented parseVolatileStatement().
aziz
parents: 181
diff changeset
2374 nT();
673b355ba0e9 - Implemented parseVolatileStatement().
aziz
parents: 181
diff changeset
2375 else if (token.type == T.LBrace)
673b355ba0e9 - Implemented parseVolatileStatement().
aziz
parents: 181
diff changeset
2376 volatileBody = parseScopeStatement();
673b355ba0e9 - Implemented parseVolatileStatement().
aziz
parents: 181
diff changeset
2377 else
219
0d14a09227a4 - Simplified parseScopeStatement().
aziz
parents: 218
diff changeset
2378 volatileBody = parseStatement();
182
673b355ba0e9 - Implemented parseVolatileStatement().
aziz
parents: 181
diff changeset
2379 return new VolatileStatement(volatileBody);
673b355ba0e9 - Implemented parseVolatileStatement().
aziz
parents: 181
diff changeset
2380 }
673b355ba0e9 - Implemented parseVolatileStatement().
aziz
parents: 181
diff changeset
2381
184
30a4c8522b09 - Implemented parsePragmaStatement().
aziz
parents: 183
diff changeset
2382 Statement parsePragmaStatement()
30a4c8522b09 - Implemented parsePragmaStatement().
aziz
parents: 183
diff changeset
2383 {
30a4c8522b09 - Implemented parsePragmaStatement().
aziz
parents: 183
diff changeset
2384 assert(token.type == T.Pragma);
30a4c8522b09 - Implemented parsePragmaStatement().
aziz
parents: 183
diff changeset
2385 nT();
30a4c8522b09 - Implemented parsePragmaStatement().
aziz
parents: 183
diff changeset
2386
245
93d37f874658 - Changed type of pragma identifier to Token*.
aziz
parents: 244
diff changeset
2387 Token* ident;
184
30a4c8522b09 - Implemented parsePragmaStatement().
aziz
parents: 183
diff changeset
2388 Expression[] args;
30a4c8522b09 - Implemented parsePragmaStatement().
aziz
parents: 183
diff changeset
2389 Statement pragmaBody;
30a4c8522b09 - Implemented parsePragmaStatement().
aziz
parents: 183
diff changeset
2390
30a4c8522b09 - Implemented parsePragmaStatement().
aziz
parents: 183
diff changeset
2391 require(T.LParen);
245
93d37f874658 - Changed type of pragma identifier to Token*.
aziz
parents: 244
diff changeset
2392 ident = requireId();
184
30a4c8522b09 - Implemented parsePragmaStatement().
aziz
parents: 183
diff changeset
2393
30a4c8522b09 - Implemented parsePragmaStatement().
aziz
parents: 183
diff changeset
2394 if (token.type == T.Comma)
244
829fdb2e2915 - Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents: 243
diff changeset
2395 {
829fdb2e2915 - Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents: 243
diff changeset
2396 // Parse at least one argument.
829fdb2e2915 - Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents: 243
diff changeset
2397 nT();
829fdb2e2915 - Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents: 243
diff changeset
2398 args ~= parseAssignExpression();
829fdb2e2915 - Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents: 243
diff changeset
2399 }
829fdb2e2915 - Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents: 243
diff changeset
2400
829fdb2e2915 - Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents: 243
diff changeset
2401 if (token.type == T.Comma)
829fdb2e2915 - Fix: parsing at least one argument in pragma declarations/statements.
aziz
parents: 243
diff changeset
2402 args ~= parseArguments(T.RParen);
184
30a4c8522b09 - Implemented parsePragmaStatement().
aziz
parents: 183
diff changeset
2403 else
30a4c8522b09 - Implemented parsePragmaStatement().
aziz
parents: 183
diff changeset
2404 require(T.RParen);
30a4c8522b09 - Implemented parsePragmaStatement().
aziz
parents: 183
diff changeset
2405
234
5c1111dc8670 - Added method parseNoScopeOrEmptyStatement().
aziz
parents: 233
diff changeset
2406 pragmaBody = parseNoScopeOrEmptyStatement();
184
30a4c8522b09 - Implemented parsePragmaStatement().
aziz
parents: 183
diff changeset
2407
30a4c8522b09 - Implemented parsePragmaStatement().
aziz
parents: 183
diff changeset
2408 return new PragmaStatement(ident, args, pragmaBody);
30a4c8522b09 - Implemented parsePragmaStatement().
aziz
parents: 183
diff changeset
2409 }
30a4c8522b09 - Implemented parsePragmaStatement().
aziz
parents: 183
diff changeset
2410
186
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2411 Statement parseStaticIfStatement()
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2412 {
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2413 assert(token.type == T.Static);
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2414 nT();
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2415 assert(token.type == T.If);
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2416 nT();
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2417 Expression condition;
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2418 Statement ifBody, elseBody;
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2419
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2420 require(T.LParen);
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2421 condition = parseExpression();
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2422 require(T.RParen);
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2423 ifBody = parseNoScopeStatement();
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2424 if (token.type == T.Else)
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2425 {
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2426 nT();
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2427 elseBody = parseNoScopeStatement();
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2428 }
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2429 return new StaticIfStatement(condition, ifBody, elseBody);
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2430 }
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2431
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2432 Statement parseStaticAssertStatement()
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2433 {
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2434 assert(token.type == T.Static);
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2435 nT();
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2436 assert(token.type == T.Assert);
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2437 nT();
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2438 Expression condition, message;
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2439 require(T.LParen);
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2440 condition = parseAssignExpression();
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2441 if (token.type == T.Comma)
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2442 {
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2443 nT();
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2444 message = parseAssignExpression();
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2445 }
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2446 require(T.RParen);
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2447 require(T.Semicolon);
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2448 return new StaticAssertStatement(condition, message);
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2449 }
d4292a5a7b8b - Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents: 185
diff changeset
2450
190
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2451 Statement parseDebugStatement()
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2452 {
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2453 assert(token.type == T.Debug);
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2454 nT(); // Skip debug keyword.
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2455
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2456 Token* cond; // debug ( Integer )
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2457 // debug ( Identifier )
190
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2458 Statement debugBody, elseBody;
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2459
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2460 void parseIdentOrInt(ref Token* tok)
190
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2461 {
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2462 nT();
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2463 if (token.type == T.Int32 ||
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2464 token.type == T.Identifier)
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2465 {
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2466 tok = token;
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2467 nT();
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2468 }
190
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2469 else
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2470 expected(T.Identifier); // TODO: better error msg
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2471 }
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2472
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2473 // if (token.type == T.Assign)
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2474 // {
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2475 // parseIdentOrInt(identSpec, levelSpec);
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2476 // require(T.Semicolon);
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2477 // }
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2478 // else
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2479 {
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2480 // Condition:
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2481 // Integer
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2482 // Identifier
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2483
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2484 // ( Condition )
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2485 if (token.type == T.LParen)
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2486 {
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2487 parseIdentOrInt(cond);
190
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2488 require(T.RParen);
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2489 }
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2490
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2491 // debug Statement
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2492 // debug ( Condition ) Statement
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2493 debugBody = parseNoScopeStatement();
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2494
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2495 // else Statement
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2496 if (token.type == T.Else)
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2497 {
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2498 // debug without condition and else body makes no sense
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2499 //if (levelCond == -1 && identCond.length == 0)
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2500 // TODO: issue error msg
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2501 nT();
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2502 elseBody = parseNoScopeStatement();
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2503 }
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2504 }
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2505
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2506 return new DebugStatement(cond, debugBody, elseBody);
190
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2507 }
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2508
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2509 Statement parseVersionStatement()
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2510 {
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2511 assert(token.type == T.Version);
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2512
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2513 nT(); // Skip version keyword.
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2514
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2515 Token* cond; // version ( Integer )
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2516 // version ( Identifier )
190
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2517 Statement versionBody, elseBody;
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2518
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2519 void parseIdentOrInt(ref Token* tok)
190
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2520 {
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2521 if (token.type == T.Int32 ||
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2522 token.type == T.Identifier)
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2523 {
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2524 tok = token;
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2525 nT();
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2526 }
190
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2527 else
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2528 expected(T.Identifier); // TODO: better error msg
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2529 }
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2530
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2531 // if (token.type == T.Assign)
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2532 // {
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2533 // parseIdentOrInt(identSpec, levelSpec);
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2534 // require(T.Semicolon);
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2535 // }
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2536 // else
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2537 {
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2538 // Condition:
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2539 // Integer
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2540 // Identifier
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2541
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2542 // ( Condition )
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2543 require(T.LParen);
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2544 parseIdentOrInt(cond);
190
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2545 require(T.RParen);
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2546
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2547 // version ( Condition ) Statement
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2548 versionBody = parseNoScopeStatement();
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2549
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2550 // else Statement
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2551 if (token.type == T.Else)
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2552 {
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2553 nT();
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2554 elseBody = parseNoScopeStatement();
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2555 }
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2556 }
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2557
264
50cc74026ea8 - Changed some string types to Token*.
aziz
parents: 263
diff changeset
2558 return new VersionStatement(cond, versionBody, elseBody);
190
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2559 }
d0712601fa47 - Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents: 188
diff changeset
2560
161
82c5cfc7d6d3 - Started implementation of parsing statements.
aziz
parents: 160
diff changeset
2561 /+++++++++++++++++++++++++++++
183
c9df82f6f6be - Added parseAsmStatement() stub.
aziz
parents: 182
diff changeset
2562 + Assembler parsing methods +
c9df82f6f6be - Added parseAsmStatement() stub.
aziz
parents: 182
diff changeset
2563 +++++++++++++++++++++++++++++/
c9df82f6f6be - Added parseAsmStatement() stub.
aziz
parents: 182
diff changeset
2564
c9df82f6f6be - Added parseAsmStatement() stub.
aziz
parents: 182
diff changeset
2565 Statement parseAsmStatement()
c9df82f6f6be - Added parseAsmStatement() stub.
aziz
parents: 182
diff changeset
2566 {
c9df82f6f6be - Added parseAsmStatement() stub.
aziz
parents: 182
diff changeset
2567 assert(token.type == T.Asm);
285
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2568 nT(); // Skip asm keyword.
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2569 require(T.LBrace);
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2570 auto ss = new Statements;
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2571 while (token.type != T.RBrace && token.type != T.EOF)
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2572 ss ~= parseAsmInstruction();
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2573 require(T.RBrace);
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2574 return new AsmStatement(ss);
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2575 }
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2576
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2577 Statement parseAsmInstruction()
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2578 {
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2579 auto begin = token;
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2580 Statement s;
374
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2581 typeof(token) ident;
285
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2582 switch (token.type)
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2583 {
374
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2584 // Keywords that are valid opcodes.
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2585 case T.In, T.Int, T.Out:
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2586 ident = token;
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2587 nT();
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2588 goto LOpcode;
285
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2589 case T.Identifier:
374
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2590 ident = token;
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2591 nT(); // Skip Identifier
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2592 if (token.type == T.Colon)
285
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2593 {
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2594 // Identifier : AsmInstruction
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2595 nT(); // Skip :
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2596 s = new LabeledStatement(ident, parseAsmInstruction());
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2597 break;
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2598 }
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2599
374
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2600 LOpcode:
285
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2601 // Opcode ;
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2602 // Opcode Operands ;
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2603 // Opcode
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2604 // Identifier
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2605 Expression[] es;
374
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2606 if (token.type != T.Semicolon)
285
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2607 {
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2608 while (1)
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2609 {
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2610 es ~= parseAsmExpression();
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2611 if (token.type != T.Comma)
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2612 break;
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2613 nT();
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2614 }
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2615 }
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2616 require(T.Semicolon);
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2617 s = new AsmInstruction(ident, es);
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2618 break;
374
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2619 case T.Align:
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2620 nT();
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2621 auto number = token;
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2622 switch (token.type)
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2623 {
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2624 case T.Int32, T.Int64, T.Uint32, T.Uint64:
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2625 number = token; nT(); break;
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2626 default:
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2627 if (token.type != T.Semicolon)
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2628 nT();
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2629 number = null;
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2630 // TODO: report error: number expected after asm align statement.
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2631 error(MID.ExpectedButFound, "integer", token.srcText);
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2632 }
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2633 require(T.Semicolon);
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2634 s = new AsmAlignStatement(number);
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2635 break;
285
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2636 case T.Semicolon:
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2637 s = new EmptyStatement();
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2638 nT();
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2639 break;
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2640 default:
374
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2641 error(MID.ExpectedButFound, "AsmInstruction", token.srcText);
285
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2642 s = new IllegalAsmInstruction(token);
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2643 nT();
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2644 }
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2645 set(s, begin);
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2646 return s;
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2647 }
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2648
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2649 Expression parseAsmExpression()
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2650 {
287
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2651 auto begin = token;
374
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2652 auto e = parseAsmOrOrExpression();
287
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2653 if (token.type == T.Question)
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2654 {
293
418c6548ce17 - Assigning to Node.children in several constructors that inherit from Node.
aziz
parents: 292
diff changeset
2655 auto tok = token;
287
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2656 nT();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2657 auto iftrue = parseAsmExpression();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2658 require(T.Colon);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2659 auto iffalse = parseAsmExpression();
293
418c6548ce17 - Assigning to Node.children in several constructors that inherit from Node.
aziz
parents: 292
diff changeset
2660 e = new CondExpression(e, iftrue, iffalse, tok);
287
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2661 set(e, begin);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2662 }
288
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2663 // TODO: create AsmExpression that contains e?
287
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2664 return e;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2665 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2666
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2667 Expression parseAsmOrOrExpression()
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2668 {
375
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 374
diff changeset
2669 alias parseAsmAndAndExpression parseNext;
287
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2670 auto begin = token;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2671 auto e = parseNext();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2672 while (token.type == T.OrLogical)
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2673 {
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2674 auto tok = token;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2675 nT();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2676 e = new OrOrExpression(e, parseNext(), tok);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2677 set(e, begin);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2678 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2679 return e;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2680 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2681
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2682 Expression parseAsmAndAndExpression()
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2683 {
375
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 374
diff changeset
2684 alias parseAsmOrExpression parseNext;
287
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2685 auto begin = token;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2686 auto e = parseNext();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2687 while (token.type == T.AndLogical)
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2688 {
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2689 auto tok = token;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2690 nT();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2691 e = new AndAndExpression(e, parseNext(), tok);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2692 set(e, begin);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2693 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2694 return e;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2695 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2696
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2697 Expression parseAsmOrExpression()
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2698 {
375
0bd21b746a04 - Added code to main() for recognizing options to the importgraph command.
aziz
parents: 374
diff changeset
2699 alias parseAsmXorExpression parseNext;
287
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2700 auto begin = token;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2701 auto e = parseNext();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2702 while (token.type == T.OrBinary)
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2703 {
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2704 auto tok = token;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2705 nT();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2706 e = new OrExpression(e, parseNext(), tok);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2707 set(e, begin);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2708 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2709 return e;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2710 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2711
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2712 Expression parseAsmXorExpression()
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2713 {
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2714 alias parseAsmAndExpression parseNext;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2715 auto begin = token;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2716 auto e = parseNext();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2717 while (token.type == T.Xor)
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2718 {
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2719 auto tok = token;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2720 nT();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2721 e = new XorExpression(e, parseNext(), tok);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2722 set(e, begin);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2723 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2724 return e;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2725 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2726
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2727 Expression parseAsmAndExpression()
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2728 {
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2729 alias parseAsmCmpExpression parseNext;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2730 auto begin = token;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2731 auto e = parseNext();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2732 while (token.type == T.AndBinary)
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2733 {
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2734 auto tok = token;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2735 nT();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2736 e = new AndExpression(e, parseNext(), tok);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2737 set(e, begin);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2738 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2739 return e;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2740 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2741
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2742 Expression parseAsmCmpExpression()
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2743 {
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2744 alias parseAsmShiftExpression parseNext;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2745 auto begin = token;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2746 auto e = parseNext();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2747
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2748 auto operator = token;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2749 switch (operator.type)
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2750 {
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2751 case T.Equal, T.NotEqual:
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2752 nT();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2753 e = new EqualExpression(e, parseNext(), operator);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2754 break;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2755 case T.LessEqual, T.Less, T.GreaterEqual, T.Greater:
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2756 nT();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2757 e = new RelExpression(e, parseNext(), operator);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2758 break;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2759 default:
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2760 return e;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2761 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2762 set(e, begin);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2763 return e;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2764 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2765
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2766 Expression parseAsmShiftExpression()
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2767 {
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2768 alias parseAsmAddExpression parseNext;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2769 auto begin = token;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2770 auto e = parseNext();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2771 while (1)
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2772 {
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2773 auto operator = token;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2774 switch (operator.type)
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2775 {
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2776 case T.LShift: nT(); e = new LShiftExpression(e, parseNext(), operator); break;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2777 case T.RShift: nT(); e = new RShiftExpression(e, parseNext(), operator); break;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2778 case T.URShift: nT(); e = new URShiftExpression(e, parseNext(), operator); break;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2779 default:
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2780 return e;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2781 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2782 set(e, begin);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2783 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2784 assert(0);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2785 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2786
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2787 Expression parseAsmAddExpression()
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2788 {
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2789 alias parseAsmMulExpression parseNext;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2790 auto begin = token;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2791 auto e = parseNext();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2792 while (1)
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2793 {
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2794 auto operator = token;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2795 switch (operator.type)
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2796 {
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2797 case T.Plus: nT(); e = new PlusExpression(e, parseNext(), operator); break;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2798 case T.Minus: nT(); e = new MinusExpression(e, parseNext(), operator); break;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2799 // Not allowed in asm
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2800 //case T.Tilde: nT(); e = new CatExpression(e, parseNext(), operator); break;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2801 default:
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2802 return e;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2803 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2804 set(e, begin);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2805 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2806 assert(0);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2807 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2808
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2809 Expression parseAsmMulExpression()
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2810 {
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2811 alias parseAsmPostExpression parseNext;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2812 auto begin = token;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2813 auto e = parseNext();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2814 while (1)
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2815 {
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2816 auto operator = token;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2817 switch (operator.type)
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2818 {
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2819 case T.Mul: nT(); e = new MulExpression(e, parseNext(), operator); break;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2820 case T.Div: nT(); e = new DivExpression(e, parseNext(), operator); break;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2821 case T.Mod: nT(); e = new ModExpression(e, parseNext(), operator); break;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2822 default:
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2823 return e;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2824 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2825 set(e, begin);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2826 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2827 assert(0);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2828 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2829
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2830 Expression parseAsmPostExpression()
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2831 {
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2832 auto begin = token;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2833 auto e = parseAsmUnaryExpression();
374
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2834 while (token.type == T.LBracket)
287
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2835 {
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2836 nT();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2837 e = parseAsmExpression();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2838 e = new AsmPostBracketExpression(e);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2839 require(T.RBracket);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2840 set(e, begin);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2841 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2842 return e;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2843 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2844
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2845 Expression parseAsmUnaryExpression()
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2846 {
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2847 auto begin = token;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2848 Expression e;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2849 switch (token.type)
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2850 {
374
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2851 case T.Byte, T.Short, T.Int,
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2852 T.Float, T.Double, T.Real:
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2853 goto LAsmTypePrefix;
287
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2854 case T.Identifier:
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2855 switch (token.identifier)
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2856 {
374
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2857 case "near", "far", /*"byte", "short", "int",*/
396
0a4619735ce9 Applied fixes to Lexer, Parser and other classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 391
diff changeset
2858 "word", "dword", "qword"/*, "float", "double", "real"*/:
374
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2859 LAsmTypePrefix:
287
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2860 nT();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2861 if (token.type == T.Identifier && token.identifier == "ptr")
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2862 nT();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2863 else
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2864 error(MID.ExpectedButFound, "ptr", token.srcText);
374
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2865 e = new AsmTypeExpression(parseAsmExpression());
287
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2866 break;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2867 case "offset":
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2868 nT();
374
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2869 e = new AsmOffsetExpression(parseAsmExpression());
287
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2870 break;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2871 case "seg":
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2872 nT();
374
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2873 e = new AsmSegExpression(parseAsmExpression());
287
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2874 break;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2875 default:
374
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2876 goto LparseAsmPrimaryExpression;
287
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2877 }
374
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2878 break;
287
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2879 case T.Minus:
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2880 case T.Plus:
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2881 nT();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2882 e = new SignExpression(parseAsmUnaryExpression());
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2883 break;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2884 case T.Not:
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2885 nT();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2886 e = new NotExpression(parseAsmUnaryExpression());
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2887 break;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2888 case T.Tilde:
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2889 nT();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2890 e = new CompExpression(parseAsmUnaryExpression());
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2891 default:
374
6d22f0b6a674 - Added class AsmAlignStatement.
aziz
parents: 369
diff changeset
2892 LparseAsmPrimaryExpression:
287
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2893 e = parseAsmPrimaryExpression();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2894 return e;
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2895 }
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2896 set(e, begin);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2897 return e;
183
c9df82f6f6be - Added parseAsmStatement() stub.
aziz
parents: 182
diff changeset
2898 }
c9df82f6f6be - Added parseAsmStatement() stub.
aziz
parents: 182
diff changeset
2899
285
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2900 Expression parseAsmPrimaryExpression()
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2901 {
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2902 auto begin = token;
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2903 Expression e;
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2904 switch (token.type)
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2905 {
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2906 case T.Int32, T.Int64, T.Uint32, T.Uint64:
399
ff1d11c27061 Renamed some Expression classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 398
diff changeset
2907 e = new IntExpression(token.type, token.ulong_);
285
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2908 nT();
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2909 break;
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2910 case T.Float32, T.Float64, T.Float80,
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2911 T.Imaginary32, T.Imaginary64, T.Imaginary80:
399
ff1d11c27061 Renamed some Expression classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 398
diff changeset
2912 e = new RealExpression(token.type, token.real_);
285
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2913 nT();
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2914 break;
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2915 case T.Dollar:
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2916 e = new DollarExpression();
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2917 nT();
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
2918 break;
287
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2919 case T.LBracket:
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2920 // [ AsmExpression ]
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2921 nT();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2922 e = parseAsmExpression();
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2923 require(T.RBracket);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2924 e = new AsmBracketExpression(e);
211bdd69397d - Added classes AsmTypeExpression, AsmOffsetExpression, AsmSegExpression, AsmPostBracketExpression and AsmBracketExpression.
aziz
parents: 285
diff changeset
2925 break;
288
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2926 case T.Identifier:
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2927 switch (token.identifier)
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2928 {
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2929 // __LOCAL_SIZE
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2930 case "__LOCAL_SIZE":
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2931 e = new AsmLocalSizeExpression();
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2932 nT();
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2933 break;
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2934 // Register
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2935 case "ST":
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2936 auto register = token;
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2937 nT();
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2938 // (1) - (7)
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2939 Token* number;
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2940 if (token.type == T.LParen)
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2941 {
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2942 nT();
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2943 if (token.type == T.Int32)
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2944 {
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2945 number = token;
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2946 nT();
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2947 }
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2948 else
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2949 expected(T.Int32);
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2950 require(T.RParen);
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2951 }
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2952 e = new AsmRegisterExpression(register, number);
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2953 break;
417
8af5c7e2f722 Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 415
diff changeset
2954 case "FS":
8af5c7e2f722 Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 415
diff changeset
2955 auto register = token;
8af5c7e2f722 Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 415
diff changeset
2956 nT();
8af5c7e2f722 Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 415
diff changeset
2957 // TODO: is the colon-number part optional?
8af5c7e2f722 Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 415
diff changeset
2958 Token* number;
8af5c7e2f722 Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 415
diff changeset
2959 if (token.type == T.Colon)
8af5c7e2f722 Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 415
diff changeset
2960 {
8af5c7e2f722 Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 415
diff changeset
2961 // :0, :4, :8
8af5c7e2f722 Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 415
diff changeset
2962 nT();
8af5c7e2f722 Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 415
diff changeset
2963 switch (token.srcText)
8af5c7e2f722 Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 415
diff changeset
2964 {
8af5c7e2f722 Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 415
diff changeset
2965 case "0", "4", "8":
8af5c7e2f722 Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 415
diff changeset
2966 number = token;
8af5c7e2f722 Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 415
diff changeset
2967 nT();
8af5c7e2f722 Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 415
diff changeset
2968 break;
8af5c7e2f722 Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 415
diff changeset
2969 default:
8af5c7e2f722 Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 415
diff changeset
2970 error(MID.ExpectedButFound, "0, 4 or 8", token.srcText);
8af5c7e2f722 Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 415
diff changeset
2971 }
8af5c7e2f722 Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 415
diff changeset
2972 }
8af5c7e2f722 Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 415
diff changeset
2973 e = new AsmRegisterExpression(register, number);
8af5c7e2f722 Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 415
diff changeset
2974 break;
288
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2975 case "AL", "AH", "AX", "EAX",
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2976 "BL", "BH", "BX", "EBX",
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2977 "CL", "CH", "CX", "ECX",
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2978 "DL", "DH", "DX", "EDX",
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2979 "BP", "EBP",
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2980 "SP", "ESP",
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2981 "DI", "EDI",
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2982 "SI", "ESI",
417
8af5c7e2f722 Fixed parsing asm FS register.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 415
diff changeset
2983 "ES", "CS", "SS", "DS", "GS",
288
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2984 "CR0", "CR2", "CR3", "CR4",
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2985 "DR0", "DR1", "DR2", "DR3", "DR6", "DR7",
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2986 "TR3", "TR4", "TR5", "TR6", "TR7",
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2987 "MM0", "MM1", "MM2", "MM3", "MM4", "MM5", "MM6", "MM7",
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2988 "XMM0", "XMM1", "XMM2", "XMM3", "XMM4", "XMM5", "XMM6", "XMM7":
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2989 e = new AsmRegisterExpression(token);
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2990 nT();
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2991 break;
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2992 default:
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2993 // DotIdentifier
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2994 auto begin2 = token;
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2995 Expression[] identList;
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2996 goto LenterLoop;
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2997 while (token.type == T.Dot)
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2998 {
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
2999 nT();
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
3000 begin2 = token;
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
3001 auto ident = requireId();
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
3002 LenterLoop:
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
3003 e = new IdentifierExpression(token);
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
3004 nT();
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
3005 set(e, begin2);
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
3006 identList ~= e;
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
3007 }
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
3008 e = new DotListExpression(identList);
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
3009 }
833b301497f4 - Added classes AsmLocalSizeExpression and AsmRegisterExpression.
aziz
parents: 287
diff changeset
3010 break;
285
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
3011 default:
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
3012 error(MID.ExpectedButFound, "Expression", token.srcText);
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
3013 e = new EmptyExpression();
414
9c69615a4876 Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 409
diff changeset
3014 if (!trying)
9c69615a4876 Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 409
diff changeset
3015 {
9c69615a4876 Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 409
diff changeset
3016 // Insert a dummy token and don't consume current one.
9c69615a4876 Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 409
diff changeset
3017 begin = lx.insertEmptyTokenBefore(token);
9c69615a4876 Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 409
diff changeset
3018 prevToken = begin;
9c69615a4876 Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 409
diff changeset
3019 }
285
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
3020 }
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
3021 set(e, begin);
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
3022 return e;
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
3023 }
104343e0f097 - Started implementation of asm statements parser.
aziz
parents: 284
diff changeset
3024
183
c9df82f6f6be - Added parseAsmStatement() stub.
aziz
parents: 182
diff changeset
3025 /+++++++++++++++++++++++++++++
102
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
3026 + Expression parsing methods +
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
3027 +++++++++++++++++++++++++++++/
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
3028
72
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3029 Expression parseExpression()
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3030 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3031 auto begin = token;
72
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3032 auto e = parseAssignExpression();
122
9849a263f148 - Added method parseDeclarationsBlock().
aziz
parents: 121
diff changeset
3033 while (token.type == T.Comma)
235
3384ac8878f7 - Fixed parseExpression(). Forgot to skip T.Comma.
aziz
parents: 234
diff changeset
3034 {
251
67a798459532 - Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents: 250
diff changeset
3035 auto comma = token;
235
3384ac8878f7 - Fixed parseExpression(). Forgot to skip T.Comma.
aziz
parents: 234
diff changeset
3036 nT();
251
67a798459532 - Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents: 250
diff changeset
3037 e = new CommaExpression(e, parseAssignExpression(), comma);
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3038 set(e, begin);
235
3384ac8878f7 - Fixed parseExpression(). Forgot to skip T.Comma.
aziz
parents: 234
diff changeset
3039 }
72
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3040 return e;
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3041 }
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3042
71
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
3043 Expression parseAssignExpression()
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
3044 {
319
83f1f9a4f248 - Removed assigment to 'begin' from loop. Initializing 'begin' at decl point.
aziz
parents: 318
diff changeset
3045 auto begin = token;
71
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
3046 auto e = parseCondExpression();
72
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3047 while (1)
71
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
3048 {
87
c9544b7d5c7d - Added member token and method nT(), which sets token to lx.token.
aziz
parents: 86
diff changeset
3049 switch (token.type)
72
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3050 {
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3051 case T.Assign:
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3052 nT(); e = new AssignExpression(e, parseAssignExpression());
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3053 break;
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3054 case T.LShiftAssign:
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3055 nT(); e = new LShiftAssignExpression(e, parseAssignExpression());
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3056 break;
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3057 case T.RShiftAssign:
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3058 nT(); e = new RShiftAssignExpression(e, parseAssignExpression());
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3059 break;
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3060 case T.URShiftAssign:
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3061 nT(); e = new URShiftAssignExpression(e, parseAssignExpression());
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3062 break;
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3063 case T.OrAssign:
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3064 nT(); e = new OrAssignExpression(e, parseAssignExpression());
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3065 break;
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3066 case T.AndAssign:
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3067 nT(); e = new AndAssignExpression(e, parseAssignExpression());
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3068 break;
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3069 case T.PlusAssign:
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3070 nT(); e = new PlusAssignExpression(e, parseAssignExpression());
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3071 break;
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3072 case T.MinusAssign:
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3073 nT(); e = new MinusAssignExpression(e, parseAssignExpression());
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3074 break;
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3075 case T.DivAssign:
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3076 nT(); e = new DivAssignExpression(e, parseAssignExpression());
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3077 break;
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3078 case T.MulAssign:
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3079 nT(); e = new MulAssignExpression(e, parseAssignExpression());
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3080 break;
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3081 case T.ModAssign:
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3082 nT(); e = new ModAssignExpression(e, parseAssignExpression());
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3083 break;
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3084 case T.XorAssign:
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3085 nT(); e = new XorAssignExpression(e, parseAssignExpression());
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3086 break;
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3087 case T.CatAssign:
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3088 nT(); e = new CatAssignExpression(e, parseAssignExpression());
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3089 break;
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3090 default:
218
6c0d274e0f3f - Removed goto from parseAssignExpression().
aziz
parents: 217
diff changeset
3091 return e;
72
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3092 }
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3093 set(e, begin);
71
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
3094 }
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
3095 return e;
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
3096 }
72
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3097
71
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
3098 Expression parseCondExpression()
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
3099 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3100 auto begin = token;
72
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3101 auto e = parseOrOrExpression();
87
c9544b7d5c7d - Added member token and method nT(), which sets token to lx.token.
aziz
parents: 86
diff changeset
3102 if (token.type == T.Question)
72
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3103 {
293
418c6548ce17 - Assigning to Node.children in several constructors that inherit from Node.
aziz
parents: 292
diff changeset
3104 auto tok = token;
72
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3105 nT();
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3106 auto iftrue = parseExpression();
87
c9544b7d5c7d - Added member token and method nT(), which sets token to lx.token.
aziz
parents: 86
diff changeset
3107 require(T.Colon);
72
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3108 auto iffalse = parseCondExpression();
293
418c6548ce17 - Assigning to Node.children in several constructors that inherit from Node.
aziz
parents: 292
diff changeset
3109 e = new CondExpression(e, iftrue, iffalse, tok);
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3110 set(e, begin);
72
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3111 }
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3112 return e;
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3113 }
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3114
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3115 Expression parseOrOrExpression()
f75e359f939f - Added parseExpression() method.
aziz
parents: 71
diff changeset
3116 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3117 auto begin = token;
73
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3118 alias parseAndAndExpression parseNext;
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3119 auto e = parseNext();
223
043722eed46e - Fix: if-statements should be while-statements.
aziz
parents: 222
diff changeset
3120 while (token.type == T.OrLogical)
73
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3121 {
251
67a798459532 - Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents: 250
diff changeset
3122 auto tok = token;
73
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3123 nT();
251
67a798459532 - Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents: 250
diff changeset
3124 e = new OrOrExpression(e, parseNext(), tok);
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3125 set(e, begin);
73
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3126 }
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3127 return e;
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3128 }
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3129
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3130 Expression parseAndAndExpression()
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3131 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3132 auto begin = token;
73
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3133 alias parseOrExpression parseNext;
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3134 auto e = parseNext();
223
043722eed46e - Fix: if-statements should be while-statements.
aziz
parents: 222
diff changeset
3135 while (token.type == T.AndLogical)
73
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3136 {
251
67a798459532 - Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents: 250
diff changeset
3137 auto tok = token;
73
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3138 nT();
251
67a798459532 - Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents: 250
diff changeset
3139 e = new AndAndExpression(e, parseNext(), tok);
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3140 set(e, begin);
73
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3141 }
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3142 return e;
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3143 }
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3144
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3145 Expression parseOrExpression()
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3146 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3147 auto begin = token;
73
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3148 alias parseXorExpression parseNext;
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3149 auto e = parseNext();
223
043722eed46e - Fix: if-statements should be while-statements.
aziz
parents: 222
diff changeset
3150 while (token.type == T.OrBinary)
73
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3151 {
251
67a798459532 - Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents: 250
diff changeset
3152 auto tok = token;
73
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3153 nT();
251
67a798459532 - Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents: 250
diff changeset
3154 e = new OrExpression(e, parseNext(), tok);
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3155 set(e, begin);
73
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3156 }
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3157 return e;
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3158 }
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3159
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3160 Expression parseXorExpression()
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3161 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3162 auto begin = token;
73
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3163 alias parseAndExpression parseNext;
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3164 auto e = parseNext();
223
043722eed46e - Fix: if-statements should be while-statements.
aziz
parents: 222
diff changeset
3165 while (token.type == T.Xor)
73
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3166 {
251
67a798459532 - Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents: 250
diff changeset
3167 auto tok = token;
73
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3168 nT();
251
67a798459532 - Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents: 250
diff changeset
3169 e = new XorExpression(e, parseNext(), tok);
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3170 set(e, begin);
73
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3171 }
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3172 return e;
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3173 }
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3174
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3175 Expression parseAndExpression()
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3176 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3177 auto begin = token;
73
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3178 alias parseCmpExpression parseNext;
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3179 auto e = parseNext();
223
043722eed46e - Fix: if-statements should be while-statements.
aziz
parents: 222
diff changeset
3180 while (token.type == T.AndBinary)
73
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3181 {
251
67a798459532 - Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents: 250
diff changeset
3182 auto tok = token;
73
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3183 nT();
251
67a798459532 - Added parameter Token* tok to some Expression constructors. Adapted parser accordingly.
aziz
parents: 250
diff changeset
3184 e = new AndExpression(e, parseNext(), tok);
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3185 set(e, begin);
73
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3186 }
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3187 return e;
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3188 }
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3189
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3190 Expression parseCmpExpression()
11572f4a138c - Added methods for parsing OrOrExpressions, AndAndExpressions, OrExpressions, XorExpressions and AndExpressions.
aziz
parents: 72
diff changeset
3191 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3192 auto begin = token;
74
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3193 auto e = parseShiftExpression();
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3194
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3195 auto operator = token;
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3196 switch (operator.type)
74
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3197 {
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3198 case T.Equal, T.NotEqual:
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3199 nT();
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3200 e = new EqualExpression(e, parseShiftExpression(), operator);
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3201 break;
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3202 case T.Not:
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
3203 if (peekNext() != T.Is)
74
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3204 break;
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3205 nT();
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3206 // fall through
225
8883c113c2f1 - Fix: case T.Identity should be T.Is.
aziz
parents: 224
diff changeset
3207 case T.Is:
74
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3208 nT();
83
9e6d66f647c9 - Fix: IsExpression was created instead of IdentityExpression.
aziz
parents: 81
diff changeset
3209 e = new IdentityExpression(e, parseShiftExpression(), operator);
74
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3210 break;
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3211 case T.LessEqual, T.Less, T.GreaterEqual, T.Greater,
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3212 T.Unordered, T.UorE, T.UorG, T.UorGorE,
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3213 T.UorL, T.UorLorE, T.LorEorG, T.LorG:
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3214 nT();
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3215 e = new RelExpression(e, parseShiftExpression(), operator);
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3216 break;
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3217 case T.In:
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3218 nT();
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3219 e = new InExpression(e, parseShiftExpression(), operator);
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3220 break;
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3221 default:
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3222 return e;
74
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3223 }
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3224 set(e, begin);
74
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3225 return e;
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3226 }
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3227
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3228 Expression parseShiftExpression()
30b0fb85dda9 - Implemented parseCmpExpression().
aziz
parents: 73
diff changeset
3229 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3230 auto begin = token;
75
3f976d9e0833 - Implemented parseShiftExpression().
aziz
parents: 74
diff changeset
3231 auto e = parseAddExpression();
3f976d9e0833 - Implemented parseShiftExpression().
aziz
parents: 74
diff changeset
3232 while (1)
3f976d9e0833 - Implemented parseShiftExpression().
aziz
parents: 74
diff changeset
3233 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3234 auto operator = token;
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3235 switch (operator.type)
75
3f976d9e0833 - Implemented parseShiftExpression().
aziz
parents: 74
diff changeset
3236 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3237 case T.LShift: nT(); e = new LShiftExpression(e, parseAddExpression(), operator); break;
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3238 case T.RShift: nT(); e = new RShiftExpression(e, parseAddExpression(), operator); break;
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3239 case T.URShift: nT(); e = new URShiftExpression(e, parseAddExpression(), operator); break;
228
a4c5ee9527b7 - Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents: 227
diff changeset
3240 default:
a4c5ee9527b7 - Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents: 227
diff changeset
3241 return e;
75
3f976d9e0833 - Implemented parseShiftExpression().
aziz
parents: 74
diff changeset
3242 }
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3243 set(e, begin);
75
3f976d9e0833 - Implemented parseShiftExpression().
aziz
parents: 74
diff changeset
3244 }
228
a4c5ee9527b7 - Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents: 227
diff changeset
3245 assert(0);
75
3f976d9e0833 - Implemented parseShiftExpression().
aziz
parents: 74
diff changeset
3246 }
3f976d9e0833 - Implemented parseShiftExpression().
aziz
parents: 74
diff changeset
3247
3f976d9e0833 - Implemented parseShiftExpression().
aziz
parents: 74
diff changeset
3248 Expression parseAddExpression()
3f976d9e0833 - Implemented parseShiftExpression().
aziz
parents: 74
diff changeset
3249 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3250 auto begin = token;
76
a85f9edf6ce7 - Implemented parseAddExpression().
aziz
parents: 75
diff changeset
3251 auto e = parseMulExpression();
a85f9edf6ce7 - Implemented parseAddExpression().
aziz
parents: 75
diff changeset
3252 while (1)
a85f9edf6ce7 - Implemented parseAddExpression().
aziz
parents: 75
diff changeset
3253 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3254 auto operator = token;
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3255 switch (operator.type)
76
a85f9edf6ce7 - Implemented parseAddExpression().
aziz
parents: 75
diff changeset
3256 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3257 case T.Plus: nT(); e = new PlusExpression(e, parseMulExpression(), operator); break;
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3258 case T.Minus: nT(); e = new MinusExpression(e, parseMulExpression(), operator); break;
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3259 case T.Tilde: nT(); e = new CatExpression(e, parseMulExpression(), operator); break;
228
a4c5ee9527b7 - Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents: 227
diff changeset
3260 default:
a4c5ee9527b7 - Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents: 227
diff changeset
3261 return e;
76
a85f9edf6ce7 - Implemented parseAddExpression().
aziz
parents: 75
diff changeset
3262 }
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3263 set(e, begin);
76
a85f9edf6ce7 - Implemented parseAddExpression().
aziz
parents: 75
diff changeset
3264 }
228
a4c5ee9527b7 - Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents: 227
diff changeset
3265 assert(0);
76
a85f9edf6ce7 - Implemented parseAddExpression().
aziz
parents: 75
diff changeset
3266 }
a85f9edf6ce7 - Implemented parseAddExpression().
aziz
parents: 75
diff changeset
3267
a85f9edf6ce7 - Implemented parseAddExpression().
aziz
parents: 75
diff changeset
3268 Expression parseMulExpression()
a85f9edf6ce7 - Implemented parseAddExpression().
aziz
parents: 75
diff changeset
3269 {
335
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3270 alias parsePostExpression parseNext;
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3271 auto begin = token;
335
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3272 auto e = parseNext();
77
7e21c4df1c02 - Implemented parseMulExpression().
aziz
parents: 76
diff changeset
3273 while (1)
7e21c4df1c02 - Implemented parseMulExpression().
aziz
parents: 76
diff changeset
3274 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3275 auto operator = token;
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3276 switch (operator.type)
77
7e21c4df1c02 - Implemented parseMulExpression().
aziz
parents: 76
diff changeset
3277 {
335
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3278 case T.Mul: nT(); e = new MulExpression(e, parseNext(), operator); break;
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3279 case T.Div: nT(); e = new DivExpression(e, parseNext(), operator); break;
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3280 case T.Mod: nT(); e = new ModExpression(e, parseNext(), operator); break;
228
a4c5ee9527b7 - Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents: 227
diff changeset
3281 default:
a4c5ee9527b7 - Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents: 227
diff changeset
3282 return e;
77
7e21c4df1c02 - Implemented parseMulExpression().
aziz
parents: 76
diff changeset
3283 }
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3284 set(e, begin);
77
7e21c4df1c02 - Implemented parseMulExpression().
aziz
parents: 76
diff changeset
3285 }
228
a4c5ee9527b7 - Replaced assert(0); with break; in case T.Static. Renamed local t to next.
aziz
parents: 227
diff changeset
3286 assert(0);
71
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
3287 }
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
3288
335
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3289 Expression parsePostExpression()
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3290 {
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3291 auto begin = token;
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3292 auto e = parseUnaryExpression();
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3293 while (1)
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3294 {
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3295 switch (token.type)
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3296 {
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3297 case T.Dot:
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3298 e = new PostDotListExpression(e, parseDotListExpression());
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3299 goto Lset;
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3300 case T.PlusPlus:
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3301 e = new PostIncrExpression(e);
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3302 break;
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3303 case T.MinusMinus:
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3304 e = new PostDecrExpression(e);
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3305 break;
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3306 case T.LParen:
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3307 e = new CallExpression(e, parseArguments(T.RParen));
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3308 goto Lset;
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3309 case T.LBracket:
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3310 // parse Slice- and IndexExpression
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3311 nT();
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3312 if (token.type == T.RBracket)
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3313 {
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3314 e = new SliceExpression(e, null, null);
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3315 break;
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3316 }
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3317
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3318 Expression[] es = [parseAssignExpression()];
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3319
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3320 if (token.type == T.Slice)
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3321 {
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3322 nT();
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3323 e = new SliceExpression(e, es[0], parseAssignExpression());
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3324 require(T.RBracket);
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3325 goto Lset;
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3326 }
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3327 else if (token.type == T.Comma)
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3328 {
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3329 es ~= parseArguments(T.RBracket);
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3330 }
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3331 else
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3332 require(T.RBracket);
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3333
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3334 e = new IndexExpression(e, es);
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3335 goto Lset;
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3336 default:
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3337 return e;
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3338 }
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3339 nT();
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3340 Lset:
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3341 set(e, begin);
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3342 }
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3343 assert(0);
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3344 }
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3345
91
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3346 Expression parseUnaryExpression()
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3347 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3348 auto begin = token;
91
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3349 Expression e;
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3350 switch (token.type)
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3351 {
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3352 case T.AndBinary:
257
6c58366ba1eb - Fix: need to allocate Parameters.
aziz
parents: 256
diff changeset
3353 nT();
243
461e544ebb53 - Added method requireId().
aziz
parents: 242
diff changeset
3354 e = new AddressExpression(parseUnaryExpression());
91
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3355 break;
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3356 case T.PlusPlus:
257
6c58366ba1eb - Fix: need to allocate Parameters.
aziz
parents: 256
diff changeset
3357 nT();
243
461e544ebb53 - Added method requireId().
aziz
parents: 242
diff changeset
3358 e = new PreIncrExpression(parseUnaryExpression());
91
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3359 break;
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3360 case T.MinusMinus:
257
6c58366ba1eb - Fix: need to allocate Parameters.
aziz
parents: 256
diff changeset
3361 nT();
243
461e544ebb53 - Added method requireId().
aziz
parents: 242
diff changeset
3362 e = new PreDecrExpression(parseUnaryExpression());
91
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3363 break;
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3364 case T.Mul:
257
6c58366ba1eb - Fix: need to allocate Parameters.
aziz
parents: 256
diff changeset
3365 nT();
243
461e544ebb53 - Added method requireId().
aziz
parents: 242
diff changeset
3366 e = new DerefExpression(parseUnaryExpression());
91
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3367 break;
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3368 case T.Minus:
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3369 case T.Plus:
257
6c58366ba1eb - Fix: need to allocate Parameters.
aziz
parents: 256
diff changeset
3370 nT();
243
461e544ebb53 - Added method requireId().
aziz
parents: 242
diff changeset
3371 e = new SignExpression(parseUnaryExpression());
91
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3372 break;
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3373 case T.Not:
257
6c58366ba1eb - Fix: need to allocate Parameters.
aziz
parents: 256
diff changeset
3374 nT();
243
461e544ebb53 - Added method requireId().
aziz
parents: 242
diff changeset
3375 e = new NotExpression(parseUnaryExpression());
91
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3376 break;
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3377 case T.Tilde:
257
6c58366ba1eb - Fix: need to allocate Parameters.
aziz
parents: 256
diff changeset
3378 nT();
243
461e544ebb53 - Added method requireId().
aziz
parents: 242
diff changeset
3379 e = new CompExpression(parseUnaryExpression());
91
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3380 break;
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3381 case T.New:
154
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
3382 e = parseNewExpression();
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3383 return e;
91
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3384 case T.Delete:
257
6c58366ba1eb - Fix: need to allocate Parameters.
aziz
parents: 256
diff changeset
3385 nT();
243
461e544ebb53 - Added method requireId().
aziz
parents: 242
diff changeset
3386 e = new DeleteExpression(parseUnaryExpression());
91
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3387 break;
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3388 case T.Cast:
99
6b8c248f5911 - Added member type to classes CastExpression and TypeidExpression.
aziz
parents: 98
diff changeset
3389 requireNext(T.LParen);
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3390 Type type;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3391 switch (token.type)
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3392 {
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3393 version(D2)
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3394 {
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3395 auto begin2 = token;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3396 case T.Const:
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3397 type = new ConstType(null);
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3398 goto case_break;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3399 case T.Invariant:
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3400 type = new InvariantType(null);
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3401 case_break:
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3402 nT();
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3403 set(type, begin2);
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3404 break;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3405 }
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3406 default:
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3407 type = parseType();
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3408 }
99
6b8c248f5911 - Added member type to classes CastExpression and TypeidExpression.
aziz
parents: 98
diff changeset
3409 require(T.RParen);
6b8c248f5911 - Added member type to classes CastExpression and TypeidExpression.
aziz
parents: 98
diff changeset
3410 e = new CastExpression(parseUnaryExpression(), type);
257
6c58366ba1eb - Fix: need to allocate Parameters.
aziz
parents: 256
diff changeset
3411 break;
91
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3412 case T.LParen:
102
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
3413 // ( Type ) . Identifier
225
8883c113c2f1 - Fix: case T.Identity should be T.Is.
aziz
parents: 224
diff changeset
3414 Type parseType_()
8883c113c2f1 - Fix: case T.Identity should be T.Is.
aziz
parents: 224
diff changeset
3415 {
8883c113c2f1 - Fix: case T.Identity should be T.Is.
aziz
parents: 224
diff changeset
3416 nT();
8883c113c2f1 - Fix: case T.Identity should be T.Is.
aziz
parents: 224
diff changeset
3417 auto type = parseType();
8883c113c2f1 - Fix: case T.Identity should be T.Is.
aziz
parents: 224
diff changeset
3418 require(T.RParen);
233
c2b601dcd57d - Added assert to parseDotListExpression().
aziz
parents: 232
diff changeset
3419 require(T.Dot);
225
8883c113c2f1 - Fix: case T.Identity should be T.Is.
aziz
parents: 224
diff changeset
3420 return type;
8883c113c2f1 - Fix: case T.Identity should be T.Is.
aziz
parents: 224
diff changeset
3421 }
8883c113c2f1 - Fix: case T.Identity should be T.Is.
aziz
parents: 224
diff changeset
3422 bool success;
423
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
3423 auto type = try_(&parseType_, success);
225
8883c113c2f1 - Fix: case T.Identity should be T.Is.
aziz
parents: 224
diff changeset
3424 if (success)
8883c113c2f1 - Fix: case T.Identity should be T.Is.
aziz
parents: 224
diff changeset
3425 {
243
461e544ebb53 - Added method requireId().
aziz
parents: 242
diff changeset
3426 auto ident = requireId();
225
8883c113c2f1 - Fix: case T.Identity should be T.Is.
aziz
parents: 224
diff changeset
3427 e = new TypeDotIdExpression(type, ident);
257
6c58366ba1eb - Fix: need to allocate Parameters.
aziz
parents: 256
diff changeset
3428 break;
225
8883c113c2f1 - Fix: case T.Identity should be T.Is.
aziz
parents: 224
diff changeset
3429 }
8883c113c2f1 - Fix: case T.Identity should be T.Is.
aziz
parents: 224
diff changeset
3430 goto default;
91
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3431 default:
335
b245b234fdd9 - Moved parsePostExpression() above parseUnaryExpression().
aziz
parents: 327
diff changeset
3432 e = parsePrimaryExpression();
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3433 return e;
91
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3434 }
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3435 assert(e !is null);
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3436 set(e, begin);
91
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3437 return e;
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3438 }
ac8610aaf622 - Moved parseUnaryExpression() one place up in the method list.
aziz
parents: 90
diff changeset
3439
79
df4e5c7ad58a - Implemented most of parsePostExpression() and parsePreExpression().
aziz
parents: 78
diff changeset
3440 Expression parsePrimaryExpression()
78
f043759fb59a - Added code to parseUnaryExpression(); not fully implemented.
aziz
parents: 77
diff changeset
3441 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3442 auto begin = token;
83
9e6d66f647c9 - Fix: IsExpression was created instead of IdentityExpression.
aziz
parents: 81
diff changeset
3443 Expression e;
87
c9544b7d5c7d - Added member token and method nT(), which sets token to lx.token.
aziz
parents: 86
diff changeset
3444 switch (token.type)
83
9e6d66f647c9 - Fix: IsExpression was created instead of IdentityExpression.
aziz
parents: 81
diff changeset
3445 {
154
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
3446 case T.Identifier, T.Dot, T.Typeof:
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
3447 e = parseDotListExpression();
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
3448 break;
84
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3449 case T.This:
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3450 nT();
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3451 e = new ThisExpression();
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3452 break;
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3453 case T.Super:
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3454 nT();
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3455 e = new SuperExpression();
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3456 break;
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3457 case T.Null:
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3458 nT();
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3459 e = new NullExpression();
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3460 break;
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3461 case T.True, T.False:
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3462 nT();
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3463 e = new BoolExpression();
84
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3464 break;
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3465 case T.Dollar:
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3466 nT();
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3467 e = new DollarExpression();
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3468 break;
97
1a83e5070a84 - Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents: 96
diff changeset
3469 case T.Int32, T.Int64, T.Uint32, T.Uint64:
399
ff1d11c27061 Renamed some Expression classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 398
diff changeset
3470 e = new IntExpression(token.type, token.ulong_);
97
1a83e5070a84 - Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents: 96
diff changeset
3471 nT();
1a83e5070a84 - Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents: 96
diff changeset
3472 break;
1a83e5070a84 - Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents: 96
diff changeset
3473 case T.Float32, T.Float64, T.Float80,
1a83e5070a84 - Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents: 96
diff changeset
3474 T.Imaginary32, T.Imaginary64, T.Imaginary80:
399
ff1d11c27061 Renamed some Expression classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 398
diff changeset
3475 e = new RealExpression(token.type, token.real_);
97
1a83e5070a84 - Added code for parsing IntNumber- and RealNumberExpressions.
aziz
parents: 96
diff changeset
3476 nT();
84
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3477 break;
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3478 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
3479 nT();
399
ff1d11c27061 Renamed some Expression classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 398
diff changeset
3480 e = new CharExpression();
84
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3481 break;
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3482 case T.String:
157
fdbd47d72614 - Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents: 156
diff changeset
3483 Token*[] stringLiterals;
fdbd47d72614 - Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents: 156
diff changeset
3484 do
84
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3485 {
157
fdbd47d72614 - Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents: 156
diff changeset
3486 stringLiterals ~= token;
84
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3487 nT();
157
fdbd47d72614 - Renamed class StringLiteralExpression to StringLiteralsExpression.
aziz
parents: 156
diff changeset
3488 } while (token.type == T.String)
399
ff1d11c27061 Renamed some Expression classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 398
diff changeset
3489 e = new StringExpression(stringLiterals);
84
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3490 break;
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3491 case T.LBracket:
85
d8dc3171440d - Fixed parsing CallExpression and IndexExpression.
aziz
parents: 84
diff changeset
3492 Expression[] values;
d8dc3171440d - Fixed parsing CallExpression and IndexExpression.
aziz
parents: 84
diff changeset
3493
d8dc3171440d - Fixed parsing CallExpression and IndexExpression.
aziz
parents: 84
diff changeset
3494 nT();
87
c9544b7d5c7d - Added member token and method nT(), which sets token to lx.token.
aziz
parents: 86
diff changeset
3495 if (token.type != T.RBracket)
85
d8dc3171440d - Fixed parsing CallExpression and IndexExpression.
aziz
parents: 84
diff changeset
3496 {
d8dc3171440d - Fixed parsing CallExpression and IndexExpression.
aziz
parents: 84
diff changeset
3497 e = parseAssignExpression();
87
c9544b7d5c7d - Added member token and method nT(), which sets token to lx.token.
aziz
parents: 86
diff changeset
3498 if (token.type == T.Colon)
85
d8dc3171440d - Fixed parsing CallExpression and IndexExpression.
aziz
parents: 84
diff changeset
3499 goto LparseAssocArray;
87
c9544b7d5c7d - Added member token and method nT(), which sets token to lx.token.
aziz
parents: 86
diff changeset
3500 else if (token.type == T.Comma)
143
e760d7552f66 - Renamed parseArgumentList() to parseArguments().
aziz
parents: 141
diff changeset
3501 values = [e] ~ parseArguments(T.RBracket);
87
c9544b7d5c7d - Added member token and method nT(), which sets token to lx.token.
aziz
parents: 86
diff changeset
3502 else
c9544b7d5c7d - Added member token and method nT(), which sets token to lx.token.
aziz
parents: 86
diff changeset
3503 require(T.RBracket);
85
d8dc3171440d - Fixed parsing CallExpression and IndexExpression.
aziz
parents: 84
diff changeset
3504 }
271
68987c1c59b6 - Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents: 270
diff changeset
3505 else
68987c1c59b6 - Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents: 270
diff changeset
3506 nT();
85
d8dc3171440d - Fixed parsing CallExpression and IndexExpression.
aziz
parents: 84
diff changeset
3507
d8dc3171440d - Fixed parsing CallExpression and IndexExpression.
aziz
parents: 84
diff changeset
3508 e = new ArrayLiteralExpression(values);
d8dc3171440d - Fixed parsing CallExpression and IndexExpression.
aziz
parents: 84
diff changeset
3509 break;
d8dc3171440d - Fixed parsing CallExpression and IndexExpression.
aziz
parents: 84
diff changeset
3510
d8dc3171440d - Fixed parsing CallExpression and IndexExpression.
aziz
parents: 84
diff changeset
3511 LparseAssocArray:
d8dc3171440d - Fixed parsing CallExpression and IndexExpression.
aziz
parents: 84
diff changeset
3512 Expression[] keys;
d8dc3171440d - Fixed parsing CallExpression and IndexExpression.
aziz
parents: 84
diff changeset
3513
d8dc3171440d - Fixed parsing CallExpression and IndexExpression.
aziz
parents: 84
diff changeset
3514 keys ~= e;
d8dc3171440d - Fixed parsing CallExpression and IndexExpression.
aziz
parents: 84
diff changeset
3515 nT(); // Skip colon.
271
68987c1c59b6 - Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents: 270
diff changeset
3516 goto LenterLoop;
68987c1c59b6 - Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents: 270
diff changeset
3517
68987c1c59b6 - Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents: 270
diff changeset
3518 while (1)
88
81cb24669ed3 - Fixed parser of AssocArrayLiteralExpression.
aziz
parents: 87
diff changeset
3519 {
271
68987c1c59b6 - Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents: 270
diff changeset
3520 keys ~= parseAssignExpression();
68987c1c59b6 - Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents: 270
diff changeset
3521 require(T.Colon);
68987c1c59b6 - Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents: 270
diff changeset
3522 LenterLoop:
68987c1c59b6 - Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents: 270
diff changeset
3523 values ~= parseAssignExpression();
68987c1c59b6 - Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents: 270
diff changeset
3524 if (token.type != T.Comma)
68987c1c59b6 - Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents: 270
diff changeset
3525 break;
68987c1c59b6 - Fixed parsing empty ArrayLiteralExpression. Needed to skip T.RBracket.
aziz
parents: 270
diff changeset
3526 nT();
88
81cb24669ed3 - Fixed parser of AssocArrayLiteralExpression.
aziz
parents: 87
diff changeset
3527 }
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3528 require(T.RBracket);
399
ff1d11c27061 Renamed some Expression classes.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 398
diff changeset
3529 e = new AArrayLiteralExpression(keys, values);
84
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3530 break;
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3531 case T.LBrace:
193
2a2975b6d539 - Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents: 192
diff changeset
3532 // DelegateLiteral := { Statements }
267
f3dfa6208ed3 - Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents: 266
diff changeset
3533 auto funcBody = parseFunctionBody();
289
a99357783c6f - Fix: assign targs to member targs of TraitsExpression.
aziz
parents: 288
diff changeset
3534 e = new FunctionLiteralExpression(funcBody);
84
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3535 break;
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3536 case T.Function, T.Delegate:
193
2a2975b6d539 - Using parseFunctionBody() when parsing FunctionLiteralExpression.
aziz
parents: 192
diff changeset
3537 // FunctionLiteral := (function|delegate) Type? '(' ArgumentList ')' '{' Statements '}'
133
3924b1ee1302 - Added code for parsing function and delegate literal expressions.
aziz
parents: 132
diff changeset
3538 nT(); // Skip function|delegate token.
3924b1ee1302 - Added code for parsing function and delegate literal expressions.
aziz
parents: 132
diff changeset
3539 Type returnType;
3924b1ee1302 - Added code for parsing function and delegate literal expressions.
aziz
parents: 132
diff changeset
3540 Parameters parameters;
3924b1ee1302 - Added code for parsing function and delegate literal expressions.
aziz
parents: 132
diff changeset
3541 if (token.type != T.LBrace)
3924b1ee1302 - Added code for parsing function and delegate literal expressions.
aziz
parents: 132
diff changeset
3542 {
3924b1ee1302 - Added code for parsing function and delegate literal expressions.
aziz
parents: 132
diff changeset
3543 if (token.type != T.LParen) // Optional return type
3924b1ee1302 - Added code for parsing function and delegate literal expressions.
aziz
parents: 132
diff changeset
3544 returnType = parseType();
143
e760d7552f66 - Renamed parseArgumentList() to parseArguments().
aziz
parents: 141
diff changeset
3545 parameters = parseParameterList();
133
3924b1ee1302 - Added code for parsing function and delegate literal expressions.
aziz
parents: 132
diff changeset
3546 }
267
f3dfa6208ed3 - Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents: 266
diff changeset
3547 auto funcBody = parseFunctionBody();
289
a99357783c6f - Fix: assign targs to member targs of TraitsExpression.
aziz
parents: 288
diff changeset
3548 e = new FunctionLiteralExpression(returnType, parameters, funcBody);
84
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3549 break;
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3550 case T.Assert:
86
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
3551 Expression msg;
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
3552 requireNext(T.LParen);
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
3553 e = parseAssignExpression();
87
c9544b7d5c7d - Added member token and method nT(), which sets token to lx.token.
aziz
parents: 86
diff changeset
3554 if (token.type == T.Comma)
86
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
3555 {
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
3556 nT();
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
3557 msg = parseAssignExpression();
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
3558 }
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
3559 require(T.RParen);
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
3560 e = new AssertExpression(e, msg);
84
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3561 break;
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3562 case T.Mixin:
86
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
3563 requireNext(T.LParen);
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
3564 e = parseAssignExpression();
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
3565 require(T.RParen);
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
3566 e = new MixinExpression(e);
84
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3567 break;
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3568 case T.Import:
86
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
3569 requireNext(T.LParen);
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
3570 e = parseAssignExpression();
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
3571 require(T.RParen);
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
3572 e = new ImportExpression(e);
84
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3573 break;
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3574 case T.Typeid:
86
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
3575 requireNext(T.LParen);
99
6b8c248f5911 - Added member type to classes CastExpression and TypeidExpression.
aziz
parents: 98
diff changeset
3576 auto type = parseType();
6b8c248f5911 - Added member type to classes CastExpression and TypeidExpression.
aziz
parents: 98
diff changeset
3577 require(T.RParen);
6b8c248f5911 - Added member type to classes CastExpression and TypeidExpression.
aziz
parents: 98
diff changeset
3578 e = new TypeidExpression(type);
84
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3579 break;
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3580 case T.Is:
100
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3581 requireNext(T.LParen);
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3582
248
63a15b082c0c - Removed class SpecializationType.
aziz
parents: 247
diff changeset
3583 Type type, specType;
253
4279b638c63e - Changed some string types to Token*. Adapted parser accordingly.
aziz
parents: 252
diff changeset
3584 Token* ident; // optional Identifier
248
63a15b082c0c - Removed class SpecializationType.
aziz
parents: 247
diff changeset
3585 Token* opTok, specTok;
100
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3586
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3587 type = parseDeclarator(ident, true);
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3588
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3589 switch (token.type)
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3590 {
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3591 case T.Colon, T.Equal:
248
63a15b082c0c - Removed class SpecializationType.
aziz
parents: 247
diff changeset
3592 opTok = token;
100
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3593 nT();
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3594 switch (token.type)
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3595 {
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3596 case T.Typedef,
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3597 T.Struct,
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3598 T.Union,
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3599 T.Class,
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3600 T.Interface,
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3601 T.Enum,
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3602 T.Function,
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3603 T.Delegate,
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3604 T.Super,
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3605 T.Return:
248
63a15b082c0c - Removed class SpecializationType.
aziz
parents: 247
diff changeset
3606 specTok = token;
102
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
3607 nT();
100
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3608 break;
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3609 default:
248
63a15b082c0c - Removed class SpecializationType.
aziz
parents: 247
diff changeset
3610 specType = parseType();
100
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3611 }
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3612 default:
538e8b546669 - Added code for parsing IsExpressions.
aziz
parents: 99
diff changeset
3613 }
377
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
3614
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
3615 TemplateParameters tparams;
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
3616 version(D2)
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
3617 {
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
3618 // is ( Type Identifier : TypeSpecialization , TemplateParameterList )
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
3619 // is ( Type Identifier == TypeSpecialization , TemplateParameterList )
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
3620 if (ident && specType && token.type == T.Comma)
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
3621 tparams = parseTemplateParameterList2();
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
3622 }
102
6e8b67ae15b7 - Added modules Declarations and Statements.
aziz
parents: 101
diff changeset
3623 require(T.RParen);
377
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
3624 e = new IsExpression(type, ident, opTok, specTok, specType, tparams);
84
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3625 break;
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3626 case T.LParen:
232
2a4e2c8ca094 - Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents: 231
diff changeset
3627 if (tokenAfterParenIs(T.LBrace))
130
0467f01ed524 - Fix: parameters can have optional identifier.
aziz
parents: 129
diff changeset
3628 {
232
2a4e2c8ca094 - Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents: 231
diff changeset
3629 auto parameters = parseParameterList();
143
e760d7552f66 - Renamed parseArgumentList() to parseArguments().
aziz
parents: 141
diff changeset
3630 // ( ParameterList ) FunctionBody
267
f3dfa6208ed3 - Removed parameter func from parseFunctionBody(). Creating new FunctionBody inside the method.
aziz
parents: 266
diff changeset
3631 auto funcBody = parseFunctionBody();
289
a99357783c6f - Fix: assign targs to member targs of TraitsExpression.
aziz
parents: 288
diff changeset
3632 e = new FunctionLiteralExpression(null, parameters, funcBody);
130
0467f01ed524 - Fix: parameters can have optional identifier.
aziz
parents: 129
diff changeset
3633 }
0467f01ed524 - Fix: parameters can have optional identifier.
aziz
parents: 129
diff changeset
3634 else
0467f01ed524 - Fix: parameters can have optional identifier.
aziz
parents: 129
diff changeset
3635 {
131
ce636f3981cc - Removed TOK.Number.
aziz
parents: 130
diff changeset
3636 // ( Expression )
130
0467f01ed524 - Fix: parameters can have optional identifier.
aziz
parents: 129
diff changeset
3637 nT();
0467f01ed524 - Fix: parameters can have optional identifier.
aziz
parents: 129
diff changeset
3638 e = parseExpression();
0467f01ed524 - Fix: parameters can have optional identifier.
aziz
parents: 129
diff changeset
3639 require(T.RParen);
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3640 // TODO: create ParenExpression?
130
0467f01ed524 - Fix: parameters can have optional identifier.
aziz
parents: 129
diff changeset
3641 }
84
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3642 break;
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
3643 // IntegralType . Identifier
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
3644 case T.Char, T.Wchar, T.Dchar, T.Bool,
94
0fe650a7a8d1 - Renamed Type enum to InfoType in module Information.
aziz
parents: 93
diff changeset
3645 T.Byte, T.Ubyte, T.Short, T.Ushort,
0fe650a7a8d1 - Renamed Type enum to InfoType in module Information.
aziz
parents: 93
diff changeset
3646 T.Int, T.Uint, T.Long, T.Ulong,
0fe650a7a8d1 - Renamed Type enum to InfoType in module Information.
aziz
parents: 93
diff changeset
3647 T.Float, T.Double, T.Real,
0fe650a7a8d1 - Renamed Type enum to InfoType in module Information.
aziz
parents: 93
diff changeset
3648 T.Ifloat, T.Idouble, T.Ireal,
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
3649 T.Cfloat, T.Cdouble, T.Creal, T.Void:
280
1eb54f6f392e - Made class Type abstract.
aziz
parents: 272
diff changeset
3650 auto type = new IntegralType(token.type);
247
11a67ec83281 - Call set() on type variable.
aziz
parents: 246
diff changeset
3651 nT();
11a67ec83281 - Call set() on type variable.
aziz
parents: 246
diff changeset
3652 set(type, begin);
11a67ec83281 - Call set() on type variable.
aziz
parents: 246
diff changeset
3653 require(T.Dot);
243
461e544ebb53 - Added method requireId().
aziz
parents: 242
diff changeset
3654 auto ident = requireId();
86
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
3655
94
0fe650a7a8d1 - Renamed Type enum to InfoType in module Information.
aziz
parents: 93
diff changeset
3656 e = new TypeDotIdExpression(type, ident);
98
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3657 break;
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3658 version(D2)
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3659 {
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3660 case T.Traits:
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3661 nT();
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3662 require(T.LParen);
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3663 auto id = requireId();
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3664 TemplateArguments args;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3665 if (token.type == T.Comma)
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3666 {
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3667 args = parseTemplateArguments2();
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3668 }
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3669 else
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3670 require(T.RParen);
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3671 e = new TraitsExpression(id, args);
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3672 break;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3673 }
84
ac8d961d10d1 - Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
aziz
parents: 83
diff changeset
3674 default:
343
95f1b6e43214 - Removed TOK.Special and added an own entry for each special token.
aziz
parents: 342
diff changeset
3675 if (token.isSpecialToken)
95f1b6e43214 - Removed TOK.Special and added an own entry for each special token.
aziz
parents: 342
diff changeset
3676 {
95f1b6e43214 - Removed TOK.Special and added an own entry for each special token.
aziz
parents: 342
diff changeset
3677 e = new SpecialTokenExpression(token);
95f1b6e43214 - Removed TOK.Special and added an own entry for each special token.
aziz
parents: 342
diff changeset
3678 nT();
95f1b6e43214 - Removed TOK.Special and added an own entry for each special token.
aziz
parents: 342
diff changeset
3679 break;
95f1b6e43214 - Removed TOK.Special and added an own entry for each special token.
aziz
parents: 342
diff changeset
3680 }
95f1b6e43214 - Removed TOK.Special and added an own entry for each special token.
aziz
parents: 342
diff changeset
3681
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
3682 error(MID.ExpectedButFound, "Expression", token.srcText);
136
96468715ea79 - Returning EmptyExpression in parsePrimaryExpression() when no token matched.
aziz
parents: 135
diff changeset
3683 e = new EmptyExpression();
414
9c69615a4876 Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 409
diff changeset
3684 if (!trying)
9c69615a4876 Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 409
diff changeset
3685 {
9c69615a4876 Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 409
diff changeset
3686 // Insert a dummy token and don't consume current one.
9c69615a4876 Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 409
diff changeset
3687 begin = lx.insertEmptyTokenBefore(token);
9c69615a4876 Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 409
diff changeset
3688 prevToken = begin;
9c69615a4876 Added method insertEmptyTokenBefore() to Lexer. Made some fixes, too.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 409
diff changeset
3689 }
83
9e6d66f647c9 - Fix: IsExpression was created instead of IdentityExpression.
aziz
parents: 81
diff changeset
3690 }
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3691 set(e, begin);
83
9e6d66f647c9 - Fix: IsExpression was created instead of IdentityExpression.
aziz
parents: 81
diff changeset
3692 return e;
77
7e21c4df1c02 - Implemented parseMulExpression().
aziz
parents: 76
diff changeset
3693 }
7e21c4df1c02 - Implemented parseMulExpression().
aziz
parents: 76
diff changeset
3694
154
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
3695 Expression parseNewExpression(/*Expression e*/)
81
aa1ea2548dd9 - Fixed parseExpression() method.
aziz
parents: 80
diff changeset
3696 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3697 auto begin = token;
144
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3698 assert(token.type == T.New);
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3699 nT(); // Skip new keyword.
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3700
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3701 Expression[] newArguments;
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3702 Expression[] ctorArguments;
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3703
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3704 if (token.type == T.LParen)
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3705 newArguments = parseArguments(T.RParen);
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3706
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3707 // NewAnonClassExpression:
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3708 // new (ArgumentList)opt class (ArgumentList)opt SuperClassopt InterfaceClassesopt ClassBody
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3709 if (token.type == T.Class)
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3710 {
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3711 nT();
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3712 if (token.type == T.LParen)
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3713 ctorArguments = parseArguments(T.RParen);
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3714
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3715 BaseClass[] bases = token.type != T.LBrace ? parseBaseClasses(false) : null ;
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3716
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
3717 auto decls = parseDeclarationDefinitionsBlock();
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3718 return set(new NewAnonClassExpression(/*e, */newArguments, bases, ctorArguments, decls), begin);
144
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3719 }
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3720
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3721 // NewExpression:
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3722 // NewArguments Type [ AssignExpression ]
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3723 // NewArguments Type ( ArgumentList )
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3724 // NewArguments Type
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3725 auto type = parseType();
302
d04a79e795a2 - Fix in parseNewExpression(): removed check for type id.
aziz
parents: 301
diff changeset
3726
d04a79e795a2 - Fix in parseNewExpression(): removed check for type id.
aziz
parents: 301
diff changeset
3727 if (token.type == T.LParen)
144
cfd890b250e6 - Added bool parameter to parseBaseClasses. BaseClasses in anonymous classes don't start with a colon.
aziz
parents: 143
diff changeset
3728 ctorArguments = parseArguments(T.RParen);
302
d04a79e795a2 - Fix in parseNewExpression(): removed check for type id.
aziz
parents: 301
diff changeset
3729
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3730 return set(new NewExpression(/*e, */newArguments, type, ctorArguments), begin);
81
aa1ea2548dd9 - Fixed parseExpression() method.
aziz
parents: 80
diff changeset
3731 }
aa1ea2548dd9 - Fixed parseExpression() method.
aziz
parents: 80
diff changeset
3732
98
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3733 Type parseType()
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3734 {
104
b535016f8c3f - DeclaratorSuffix must be parsed after an Identifier.
aziz
parents: 103
diff changeset
3735 return parseBasicType2(parseBasicType());
98
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3736 }
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3737
94
0fe650a7a8d1 - Renamed Type enum to InfoType in module Information.
aziz
parents: 93
diff changeset
3738 Type parseBasicType()
0fe650a7a8d1 - Renamed Type enum to InfoType in module Information.
aziz
parents: 93
diff changeset
3739 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3740 auto begin = token;
94
0fe650a7a8d1 - Renamed Type enum to InfoType in module Information.
aziz
parents: 93
diff changeset
3741 Type t;
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
3742 // IdentifierType tident;
94
0fe650a7a8d1 - Renamed Type enum to InfoType in module Information.
aziz
parents: 93
diff changeset
3743
0fe650a7a8d1 - Renamed Type enum to InfoType in module Information.
aziz
parents: 93
diff changeset
3744 switch (token.type)
0fe650a7a8d1 - Renamed Type enum to InfoType in module Information.
aziz
parents: 93
diff changeset
3745 {
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
3746 case T.Char, T.Wchar, T.Dchar, T.Bool,
94
0fe650a7a8d1 - Renamed Type enum to InfoType in module Information.
aziz
parents: 93
diff changeset
3747 T.Byte, T.Ubyte, T.Short, T.Ushort,
0fe650a7a8d1 - Renamed Type enum to InfoType in module Information.
aziz
parents: 93
diff changeset
3748 T.Int, T.Uint, T.Long, T.Ulong,
0fe650a7a8d1 - Renamed Type enum to InfoType in module Information.
aziz
parents: 93
diff changeset
3749 T.Float, T.Double, T.Real,
0fe650a7a8d1 - Renamed Type enum to InfoType in module Information.
aziz
parents: 93
diff changeset
3750 T.Ifloat, T.Idouble, T.Ireal,
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
3751 T.Cfloat, T.Cdouble, T.Creal, T.Void:
280
1eb54f6f392e - Made class Type abstract.
aziz
parents: 272
diff changeset
3752 t = new IntegralType(token.type);
94
0fe650a7a8d1 - Renamed Type enum to InfoType in module Information.
aziz
parents: 93
diff changeset
3753 nT();
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3754 set(t, begin);
94
0fe650a7a8d1 - Renamed Type enum to InfoType in module Information.
aziz
parents: 93
diff changeset
3755 break;
153
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
3756 case T.Identifier, T.Typeof, T.Dot:
154
0e7cefb15e43 - Renamed IdentifierListExpression to DotListExpression, and parseIdentifierListExpression() to parseDotListExpression().
aziz
parents: 153
diff changeset
3757 t = parseDotListType();
153
66790fc2c0a2 - Added method parseIdentifierListType().
aziz
parents: 152
diff changeset
3758 break;
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3759 version(D2)
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3760 {
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3761 case T.Const:
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3762 // const ( Type )
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3763 nT();
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3764 require(T.LParen);
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3765 t = parseType();
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3766 require(T.RParen);
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3767 t = new ConstType(t);
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3768 set(t, begin);
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3769 break;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3770 case T.Invariant:
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3771 // invariant ( Type )
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3772 nT();
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3773 require(T.LParen);
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3774 t = parseType();
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3775 require(T.RParen);
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3776 t = new InvariantType(t);
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3777 set(t, begin);
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
3778 break;
369
27767e203d64 - Added override attribute to ImportParser.start().
aziz
parents: 368
diff changeset
3779 } // version(D2)
94
0fe650a7a8d1 - Renamed Type enum to InfoType in module Information.
aziz
parents: 93
diff changeset
3780 default:
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
3781 error(MID.ExpectedButFound, "BasicType", token.srcText);
134
a31aa0d6dd5e - Added class UndefinedType. Returning it in parseBasicType() when no token matched the basic type list.
aziz
parents: 133
diff changeset
3782 t = new UndefinedType();
259
8118da6fee44 - Moved nT() below statement where an attribute class is constructed.
aziz
parents: 258
diff changeset
3783 nT();
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3784 set(t, begin);
94
0fe650a7a8d1 - Renamed Type enum to InfoType in module Information.
aziz
parents: 93
diff changeset
3785 }
0fe650a7a8d1 - Renamed Type enum to InfoType in module Information.
aziz
parents: 93
diff changeset
3786 return t;
0fe650a7a8d1 - Renamed Type enum to InfoType in module Information.
aziz
parents: 93
diff changeset
3787 }
0fe650a7a8d1 - Renamed Type enum to InfoType in module Information.
aziz
parents: 93
diff changeset
3788
95
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
3789 Type parseBasicType2(Type t)
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
3790 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3791 typeof(token) begin;
95
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
3792 while (1)
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
3793 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3794 begin = token;
95
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
3795 switch (token.type)
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
3796 {
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
3797 case T.Mul:
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
3798 t = new PointerType(t);
98
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3799 nT();
95
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
3800 break;
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
3801 case T.LBracket:
106
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3802 t = parseArrayType(t);
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3803 continue;
98
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3804 case T.Function, T.Delegate:
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3805 TOK tok = token.type;
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3806 nT();
143
e760d7552f66 - Renamed parseArgumentList() to parseArguments().
aziz
parents: 141
diff changeset
3807 auto parameters = parseParameterList();
135
145e0d68ec95 - Added enum TID to module Type.
aziz
parents: 134
diff changeset
3808 if (tok == T.Function)
291
c0e857931ff6 - Changed FunctionType and DelegateType. Both receive return type and parameters.
aziz
parents: 290
diff changeset
3809 t = new FunctionType(t, parameters);
135
145e0d68ec95 - Added enum TID to module Type.
aziz
parents: 134
diff changeset
3810 else
291
c0e857931ff6 - Changed FunctionType and DelegateType. Both receive return type and parameters.
aziz
parents: 290
diff changeset
3811 t = new DelegateType(t, parameters);
98
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3812 break;
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3813 default:
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3814 return t;
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3815 }
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3816 set(t, begin);
98
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3817 }
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3818 assert(0);
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3819 }
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3820
232
2a4e2c8ca094 - Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents: 231
diff changeset
3821 bool tokenAfterParenIs(TOK tok)
196
ea3f66901fa4 - Added code for parsing template parameter lists for functions.
aziz
parents: 195
diff changeset
3822 {
ea3f66901fa4 - Added code for parsing template parameter lists for functions.
aziz
parents: 195
diff changeset
3823 // We count nested parentheses tokens because template types may appear inside parameter lists; e.g. (int x, Foo!(int) y).
232
2a4e2c8ca094 - Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents: 231
diff changeset
3824 assert(token.type == T.LParen);
239
7911f6a92e6e - Added 'new' and 'delete' declarations to Token and uncommented next and prev members. Added HEAD to TOK.
aziz
parents: 238
diff changeset
3825 Token* next = token;
196
ea3f66901fa4 - Added code for parsing template parameter lists for functions.
aziz
parents: 195
diff changeset
3826 uint level = 1;
434
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
3827 auto state = lx.getState();
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
3828 Loop:
196
ea3f66901fa4 - Added code for parsing template parameter lists for functions.
aziz
parents: 195
diff changeset
3829 while (1)
ea3f66901fa4 - Added code for parsing template parameter lists for functions.
aziz
parents: 195
diff changeset
3830 {
232
2a4e2c8ca094 - Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents: 231
diff changeset
3831 lx.peek(next);
2a4e2c8ca094 - Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents: 231
diff changeset
3832 switch (next.type)
196
ea3f66901fa4 - Added code for parsing template parameter lists for functions.
aziz
parents: 195
diff changeset
3833 {
ea3f66901fa4 - Added code for parsing template parameter lists for functions.
aziz
parents: 195
diff changeset
3834 case T.RParen:
ea3f66901fa4 - Added code for parsing template parameter lists for functions.
aziz
parents: 195
diff changeset
3835 if (--level == 0)
434
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
3836 { // Last, closing parentheses found.
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
3837 do
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
3838 lx.peek(next);
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
3839 while (next.isWhitespace)
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
3840 break Loop;
196
ea3f66901fa4 - Added code for parsing template parameter lists for functions.
aziz
parents: 195
diff changeset
3841 }
434
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
3842 break;
196
ea3f66901fa4 - Added code for parsing template parameter lists for functions.
aziz
parents: 195
diff changeset
3843 case T.LParen:
ea3f66901fa4 - Added code for parsing template parameter lists for functions.
aziz
parents: 195
diff changeset
3844 ++level;
434
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
3845 break;
196
ea3f66901fa4 - Added code for parsing template parameter lists for functions.
aziz
parents: 195
diff changeset
3846 case T.EOF:
434
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
3847 break Loop;
196
ea3f66901fa4 - Added code for parsing template parameter lists for functions.
aziz
parents: 195
diff changeset
3848 default:
ea3f66901fa4 - Added code for parsing template parameter lists for functions.
aziz
parents: 195
diff changeset
3849 }
ea3f66901fa4 - Added code for parsing template parameter lists for functions.
aziz
parents: 195
diff changeset
3850 }
434
cac9c8d637ad Fix: members related to error info weren't updated correctly.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 429
diff changeset
3851 lx.restoreState(state);
232
2a4e2c8ca094 - Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents: 231
diff changeset
3852 return next.type == tok;
196
ea3f66901fa4 - Added code for parsing template parameter lists for functions.
aziz
parents: 195
diff changeset
3853 }
ea3f66901fa4 - Added code for parsing template parameter lists for functions.
aziz
parents: 195
diff changeset
3854
98
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3855 Type parseDeclaratorSuffix(Type t)
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3856 {
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
3857 switch (token.type)
98
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3858 {
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
3859 case T.LBracket:
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
3860 // Type Identifier ArrayType
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
3861 // ArrayType := [] or [Type] or [Expression..Expression]
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
3862 do
106
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3863 t = parseArrayType(t);
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
3864 while (token.type == T.LBracket)
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
3865 break;
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
3866 /+ // parsed in parseDeclaration()
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
3867 case T.LParen:
258
112a57f433f2 - Created class TemplateParameters.
aziz
parents: 257
diff changeset
3868 TemplateParameters tparams;
232
2a4e2c8ca094 - Renamed method isTemplateParameterList() to tokenAfterParenIs().
aziz
parents: 231
diff changeset
3869 if (tokenAfterParenIs(T.LParen))
196
ea3f66901fa4 - Added code for parsing template parameter lists for functions.
aziz
parents: 195
diff changeset
3870 {
ea3f66901fa4 - Added code for parsing template parameter lists for functions.
aziz
parents: 195
diff changeset
3871 // ( TemplateParameterList ) ( ParameterList )
ea3f66901fa4 - Added code for parsing template parameter lists for functions.
aziz
parents: 195
diff changeset
3872 tparams = parseTemplateParameterList();
ea3f66901fa4 - Added code for parsing template parameter lists for functions.
aziz
parents: 195
diff changeset
3873 }
ea3f66901fa4 - Added code for parsing template parameter lists for functions.
aziz
parents: 195
diff changeset
3874
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
3875 auto params = parseParameterList();
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
3876 // ReturnType FunctionName ( ParameterList )
196
ea3f66901fa4 - Added code for parsing template parameter lists for functions.
aziz
parents: 195
diff changeset
3877 t = new FunctionType(t, params, tparams);
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
3878 break;
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
3879 +/
192
5c898f80b436 - Started implementation of parseDeclaration().
aziz
parents: 191
diff changeset
3880 default:
98
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3881 break;
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3882 }
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3883 return t;
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3884 }
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3885
106
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3886 Type parseArrayType(Type t)
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3887 {
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3888 assert(token.type == T.LBracket);
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3889 auto begin = token;
106
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3890 nT();
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3891 if (token.type == T.RBracket)
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3892 {
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3893 t = new ArrayType(t);
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3894 nT();
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3895 }
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3896 else
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3897 {
214
45fc474c1678 - Changed 'failed' parameter of try_() to 'success'.
aziz
parents: 213
diff changeset
3898 bool success;
369
27767e203d64 - Added override attribute to ImportParser.start().
aziz
parents: 368
diff changeset
3899 Type parseAAType()
27767e203d64 - Added override attribute to ImportParser.start().
aziz
parents: 368
diff changeset
3900 {
27767e203d64 - Added override attribute to ImportParser.start().
aziz
parents: 368
diff changeset
3901 auto type = parseType();
27767e203d64 - Added override attribute to ImportParser.start().
aziz
parents: 368
diff changeset
3902 require(T.RBracket);
27767e203d64 - Added override attribute to ImportParser.start().
aziz
parents: 368
diff changeset
3903 return type;
27767e203d64 - Added override attribute to ImportParser.start().
aziz
parents: 368
diff changeset
3904 }
423
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
3905 auto assocType = try_(&parseAAType, success);
214
45fc474c1678 - Changed 'failed' parameter of try_() to 'success'.
aziz
parents: 213
diff changeset
3906 if (success)
106
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3907 t = new ArrayType(t, assocType);
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3908 else
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3909 {
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3910 Expression e = parseExpression(), e2;
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3911 if (token.type == T.Slice)
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3912 {
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3913 nT();
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3914 e2 = parseExpression();
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3915 }
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3916 t = new ArrayType(t, e, e2);
369
27767e203d64 - Added override attribute to ImportParser.start().
aziz
parents: 368
diff changeset
3917 require(T.RBracket);
106
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3918 }
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3919 }
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
3920 set(t, begin);
106
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3921 return t;
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3922 }
441962b0f526 - Added parseArrayType() method.
aziz
parents: 105
diff changeset
3923
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
3924 Type parseCFunctionPointerType(Type type, ref Token* ident, bool optionalParamList)
409
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3925 {
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3926 assert(token.type == T.LParen);
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
3927 assert(type !is null);
409
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3928 auto begin = token;
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3929 nT(); // Skip (
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3930 type = parseBasicType2(type);
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3931 if (token.type == T.LParen)
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3932 {
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3933 // Can be nested.
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
3934 type = parseCFunctionPointerType(type, ident, true);
409
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3935 }
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3936 else if (token.type == T.Identifier)
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3937 {
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3938 // The identifier of the function pointer and the declaration.
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3939 ident = token;
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3940 nT();
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3941 type = parseDeclaratorSuffix(type);
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3942 }
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3943 require(T.RParen);
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
3944
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
3945 Parameters params;
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
3946 if (optionalParamList)
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
3947 params = token.type == T.LParen ? parseParameterList() : null;
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
3948 else
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
3949 params = parseParameterList();
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
3950
409
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3951 type = set(new CFuncPointerType(type, params), begin);
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3952 return type;
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3953 }
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3954
253
4279b638c63e - Changed some string types to Token*. Adapted parser accordingly.
aziz
parents: 252
diff changeset
3955 Type parseDeclarator(ref Token* ident, bool identOptional = false)
98
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3956 {
104
b535016f8c3f - DeclaratorSuffix must be parsed after an Identifier.
aziz
parents: 103
diff changeset
3957 auto t = parseType();
98
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3958
409
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3959 if (token.type == T.LParen)
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3960 {
483
180711cc4b66 Fixed parsing of C-style function pointers.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 434
diff changeset
3961 t = parseCFunctionPointerType(t, ident, true);
409
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3962 }
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3963 else if (token.type == T.Identifier)
98
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3964 {
253
4279b638c63e - Changed some string types to Token*. Adapted parser accordingly.
aziz
parents: 252
diff changeset
3965 ident = token;
95
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
3966 nT();
104
b535016f8c3f - DeclaratorSuffix must be parsed after an Identifier.
aziz
parents: 103
diff changeset
3967 t = parseDeclaratorSuffix(t);
95
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
3968 }
409
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3969
38fccd2640eb Added code for parsing C function pointer declarations.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 406
diff changeset
3970 if (ident is null && !identOptional)
124
d4c4cea6ee7f - Renamed method errorIfNot() to expected().
aziz
parents: 123
diff changeset
3971 expected(T.Identifier);
98
aec3b16144fe - Added code for parsing (Expression) in parsePrimaryExpression(). Added missing break statement.
aziz
parents: 97
diff changeset
3972
104
b535016f8c3f - DeclaratorSuffix must be parsed after an Identifier.
aziz
parents: 103
diff changeset
3973 return t;
95
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
3974 }
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
3975
143
e760d7552f66 - Renamed parseArgumentList() to parseArguments().
aziz
parents: 141
diff changeset
3976 Expression[] parseArguments(TOK terminator)
138
91b5187ed775 - Moved parseArgumentList() down a bit.
aziz
parents: 137
diff changeset
3977 {
155
cd4394ef4b59 - Added two asserts to parseArguments().
aziz
parents: 154
diff changeset
3978 assert(token.type == T.LParen || token.type == T.LBracket || token.type == T.Comma);
cd4394ef4b59 - Added two asserts to parseArguments().
aziz
parents: 154
diff changeset
3979 assert(terminator == T.RParen || terminator == T.RBracket);
139
d48f345b05f8 - Implemented parseTemplateArgumentList().
aziz
parents: 138
diff changeset
3980 Expression[] args;
138
91b5187ed775 - Moved parseArgumentList() down a bit.
aziz
parents: 137
diff changeset
3981
91b5187ed775 - Moved parseArgumentList() down a bit.
aziz
parents: 137
diff changeset
3982 nT();
91b5187ed775 - Moved parseArgumentList() down a bit.
aziz
parents: 137
diff changeset
3983 if (token.type == terminator)
91b5187ed775 - Moved parseArgumentList() down a bit.
aziz
parents: 137
diff changeset
3984 {
91b5187ed775 - Moved parseArgumentList() down a bit.
aziz
parents: 137
diff changeset
3985 nT();
91b5187ed775 - Moved parseArgumentList() down a bit.
aziz
parents: 137
diff changeset
3986 return null;
91b5187ed775 - Moved parseArgumentList() down a bit.
aziz
parents: 137
diff changeset
3987 }
91b5187ed775 - Moved parseArgumentList() down a bit.
aziz
parents: 137
diff changeset
3988
139
d48f345b05f8 - Implemented parseTemplateArgumentList().
aziz
parents: 138
diff changeset
3989 goto LenterLoop;
d48f345b05f8 - Implemented parseTemplateArgumentList().
aziz
parents: 138
diff changeset
3990 do
138
91b5187ed775 - Moved parseArgumentList() down a bit.
aziz
parents: 137
diff changeset
3991 {
139
d48f345b05f8 - Implemented parseTemplateArgumentList().
aziz
parents: 138
diff changeset
3992 nT();
d48f345b05f8 - Implemented parseTemplateArgumentList().
aziz
parents: 138
diff changeset
3993 LenterLoop:
d48f345b05f8 - Implemented parseTemplateArgumentList().
aziz
parents: 138
diff changeset
3994 args ~= parseAssignExpression();
d48f345b05f8 - Implemented parseTemplateArgumentList().
aziz
parents: 138
diff changeset
3995 } while (token.type == T.Comma)
d48f345b05f8 - Implemented parseTemplateArgumentList().
aziz
parents: 138
diff changeset
3996
d48f345b05f8 - Implemented parseTemplateArgumentList().
aziz
parents: 138
diff changeset
3997 require(terminator);
d48f345b05f8 - Implemented parseTemplateArgumentList().
aziz
parents: 138
diff changeset
3998 return args;
138
91b5187ed775 - Moved parseArgumentList() down a bit.
aziz
parents: 137
diff changeset
3999 }
91b5187ed775 - Moved parseArgumentList() down a bit.
aziz
parents: 137
diff changeset
4000
143
e760d7552f66 - Renamed parseArgumentList() to parseArguments().
aziz
parents: 141
diff changeset
4001 Parameters parseParameterList()
117
79857de26e86 - Moved class Parameter to module Types. Added struct Parameters.
aziz
parents: 116
diff changeset
4002 out(params)
96
d12d31d5fc17 - Added out-contract to parseParameters().
aziz
parents: 95
diff changeset
4003 {
117
79857de26e86 - Moved class Parameter to module Types. Added struct Parameters.
aziz
parents: 116
diff changeset
4004 if (params.length > 1)
79857de26e86 - Moved class Parameter to module Types. Added struct Parameters.
aziz
parents: 116
diff changeset
4005 foreach (param; params.items[0..$-1])
96
d12d31d5fc17 - Added out-contract to parseParameters().
aziz
parents: 95
diff changeset
4006 {
117
79857de26e86 - Moved class Parameter to module Types. Added struct Parameters.
aziz
parents: 116
diff changeset
4007 if (param.isVariadic())
96
d12d31d5fc17 - Added out-contract to parseParameters().
aziz
parents: 95
diff changeset
4008 assert(0, "variadic arguments can only appear at the end of the parameter list.");
d12d31d5fc17 - Added out-contract to parseParameters().
aziz
parents: 95
diff changeset
4009 }
d12d31d5fc17 - Added out-contract to parseParameters().
aziz
parents: 95
diff changeset
4010 }
d12d31d5fc17 - Added out-contract to parseParameters().
aziz
parents: 95
diff changeset
4011 body
95
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4012 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
4013 auto begin = token;
95
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4014 require(T.LParen);
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4015
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
4016 auto params = new Parameters();
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
4017
95
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4018 if (token.type == T.RParen)
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4019 {
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4020 nT();
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
4021 return set(params, begin);
95
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4022 }
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4023
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4024 while (1)
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4025 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
4026 auto paramBegin = token;
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
4027 Token* stcTok;
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4028 StorageClass stc, tmp;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4029
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4030 if (token.type == T.Ellipses)
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4031 {
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4032 nT();
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4033 params ~= set(new Parameter(null, null, null, null), paramBegin);
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4034 break; // Exit loop.
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4035 }
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4036
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4037 Lstc_loop:
95
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4038 switch (token.type)
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4039 {
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4040 version(D2)
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4041 {
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4042 case T.Invariant: // D2.0
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4043 if (peekNext() == T.LParen)
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4044 goto default;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4045 tmp = StorageClass.Invariant;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4046 goto Lcommon;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4047 case T.Const: // D2.0
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4048 if (peekNext() == T.LParen)
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4049 goto default;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4050 tmp = StorageClass.Const;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4051 goto Lcommon;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4052 case T.Final: // D2.0
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4053 tmp = StorageClass.Final;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4054 goto Lcommon;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4055 case T.Scope: // D2.0
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4056 tmp = StorageClass.Scope;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4057 goto Lcommon;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4058 case T.Static: // D2.0
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4059 tmp = StorageClass.Static;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4060 goto Lcommon;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4061 case T.In:
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4062 tmp = StorageClass.In;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4063 goto Lcommon;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4064 case T.Out:
282
74113a9aa77c - Fix: assigned wrong StorageClass to variable.
aziz
parents: 280
diff changeset
4065 tmp = StorageClass.Out;
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4066 goto Lcommon;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4067 case T.Inout, T.Ref:
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4068 tmp = StorageClass.Ref;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4069 goto Lcommon;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4070 case T.Lazy:
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4071 tmp = StorageClass.Lazy;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4072 goto Lcommon;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4073 Lcommon:
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4074 if (stc & tmp)
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4075 error(MID.RedundantStorageClass, token.srcText);
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4076 else
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4077 stc |= tmp;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4078 nT();
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4079 goto Lstc_loop;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4080 }
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4081 else // else body of version(D2)
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4082 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
4083 case T.In, T.Out, T.Inout, T.Ref, T.Lazy:
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
4084 stcTok = token;
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
4085 nT();
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
4086 goto default;
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4087 }
95
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4088 default:
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4089 version(D2)
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4090 {
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4091 if (stc != StorageClass.None)
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4092 stcTok = begin;
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4093 }
253
4279b638c63e - Changed some string types to Token*. Adapted parser accordingly.
aziz
parents: 252
diff changeset
4094 Token* ident;
130
0467f01ed524 - Fix: parameters can have optional identifier.
aziz
parents: 129
diff changeset
4095 auto type = parseDeclarator(ident, true);
99
6b8c248f5911 - Added member type to classes CastExpression and TypeidExpression.
aziz
parents: 98
diff changeset
4096
95
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4097 Expression assignExpr;
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4098 if (token.type == T.Assign)
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4099 {
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4100 nT();
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4101 assignExpr = parseAssignExpression();
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4102 }
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4103
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4104 if (token.type == T.Ellipses)
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4105 {
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
4106 auto p = set(new Parameter(stcTok, type, ident, assignExpr), paramBegin);
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
4107 p.stc |= StorageClass.Variadic;
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
4108 params ~= p;
95
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4109 nT();
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
4110 break; // Exit loop.
95
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4111 }
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4112
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
4113 params ~= set(new Parameter(stcTok, type, ident, assignExpr), paramBegin);
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
4114
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
4115 if (token.type != T.Comma)
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
4116 break; // Exit loop.
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
4117 nT();
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
4118 continue;
95
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4119 }
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
4120 break; // Exit loop.
95
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4121 }
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4122 require(T.RParen);
242
7ec7ad8df9da - Changed type of member tok in class BinaryExpression to Token*.
aziz
parents: 240
diff changeset
4123 return set(params, begin);
95
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4124 }
0eb4c8a5b32b - Added TOK.Invalid.
aziz
parents: 94
diff changeset
4125
150
753bc07bf3a0 - Forgot to pass ident to constructor of TemplateArgument.
aziz
parents: 149
diff changeset
4126 TemplateArguments parseTemplateArguments()
139
d48f345b05f8 - Implemented parseTemplateArgumentList().
aziz
parents: 138
diff changeset
4127 {
376
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4128 TemplateArguments targs;
139
d48f345b05f8 - Implemented parseTemplateArgumentList().
aziz
parents: 138
diff changeset
4129 require(T.LParen);
255
7ba0229af908 - Fixed parseTemplateArguments. Removed a return path and put the while loop into an if-statement.
aziz
parents: 254
diff changeset
4130 if (token.type != T.RParen)
376
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4131 targs = parseTemplateArguments_();
139
d48f345b05f8 - Implemented parseTemplateArgumentList().
aziz
parents: 138
diff changeset
4132 require(T.RParen);
376
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4133 return targs;
139
d48f345b05f8 - Implemented parseTemplateArgumentList().
aziz
parents: 138
diff changeset
4134 }
376
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4135
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4136 version(D2)
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4137 {
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4138 TemplateArguments parseTemplateArguments2()
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4139 {
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4140 assert(token.type == T.Comma);
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4141 nT();
376
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4142 TemplateArguments targs;
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4143 if (token.type != T.RParen)
376
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4144 targs = parseTemplateArguments_();
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4145 else
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4146 error(MID.ExpectedButFound, "Type/Expression", ")");
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4147 require(T.RParen);
376
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4148 return targs;
269
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4149 }
a416e09c08ea - Implemented D 2.0 additions.
aziz
parents: 268
diff changeset
4150 } // version(D2)
376
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4151
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4152 TemplateArguments parseTemplateArguments_()
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4153 {
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4154 auto begin = token;
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4155 auto targs = new TemplateArguments;
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4156 while (1)
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4157 {
379
a92f7826a4fa - Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents: 377
diff changeset
4158 Type parseType_()
a92f7826a4fa - Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents: 377
diff changeset
4159 {
a92f7826a4fa - Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents: 377
diff changeset
4160 auto type = parseType();
a92f7826a4fa - Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents: 377
diff changeset
4161 if (token.type == T.Comma || token.type == T.RParen)
a92f7826a4fa - Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents: 377
diff changeset
4162 return type;
a92f7826a4fa - Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents: 377
diff changeset
4163 ++errorCount; // Cause try_() to fail.
a92f7826a4fa - Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents: 377
diff changeset
4164 return null;
a92f7826a4fa - Fix in parseTemplateArguments_(): calling nested parseType_() instead of parseType() in try_().
aziz
parents: 377
diff changeset
4165 }
376
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4166 bool success;
423
6057113f9a44 Refactored Parser.try_().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 422
diff changeset
4167 auto typeArgument = try_(&parseType_, success);
376
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4168 if (success)
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4169 // TemplateArgument:
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4170 // Type
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4171 // Symbol
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4172 targs ~= typeArgument;
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4173 else
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4174 // TemplateArgument:
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4175 // AssignExpression
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4176 targs ~= parseAssignExpression();
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4177 if (token.type != T.Comma)
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4178 break; // Exit loop.
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4179 nT();
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4180 }
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4181 set(targs, begin);
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4182 return targs;
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4183 }
5ebe80ce84f2 - Separated common code to parseTemplateArguments_().
aziz
parents: 375
diff changeset
4184
258
112a57f433f2 - Created class TemplateParameters.
aziz
parents: 257
diff changeset
4185 TemplateParameters parseTemplateParameterList()
137
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4186 {
377
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4187 TemplateParameters tparams;
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4188 require(T.LParen);
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4189 if (token.type != T.RParen)
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4190 tparams = parseTemplateParameterList_();
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4191 require(T.RParen);
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4192 return tparams;
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4193 }
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4194
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4195 version(D2)
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4196 {
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4197 TemplateParameters parseTemplateParameterList2()
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4198 {
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4199 assert(token.type == T.Comma);
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4200 nT();
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4201 TemplateParameters tparams;
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4202 if (token.type != T.RParen)
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4203 tparams = parseTemplateParameterList_();
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4204 else
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4205 error(MID.ExpectedButFound, "Type/Expression", ")");
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4206 return tparams;
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4207 }
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4208 } // version(D2)
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4209
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4210 TemplateParameters parseTemplateParameterList_()
906599374b69 - Added tparams member to IsExpression.
aziz
parents: 376
diff changeset
4211 {
258
112a57f433f2 - Created class TemplateParameters.
aziz
parents: 257
diff changeset
4212 auto begin = token;
295
75b47c71a34c - Assigning to Node.children in several constructors that inherit from Node.
aziz
parents: 293
diff changeset
4213 auto tparams = new TemplateParameters;
75b47c71a34c - Assigning to Node.children in several constructors that inherit from Node.
aziz
parents: 293
diff changeset
4214
137
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4215 while (1)
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4216 {
258
112a57f433f2 - Created class TemplateParameters.
aziz
parents: 257
diff changeset
4217 auto paramBegin = token;
340
1accb3013bd2 - Changed class TemplateParameter to an abstract class.
aziz
parents: 335
diff changeset
4218 TemplateParameter tp;
253
4279b638c63e - Changed some string types to Token*. Adapted parser accordingly.
aziz
parents: 252
diff changeset
4219 Token* ident;
137
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4220 Type specType, defType;
340
1accb3013bd2 - Changed class TemplateParameter to an abstract class.
aziz
parents: 335
diff changeset
4221
1accb3013bd2 - Changed class TemplateParameter to an abstract class.
aziz
parents: 335
diff changeset
4222 void parseSpecAndOrDefaultType()
137
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4223 {
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4224 // : SpecializationType
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4225 if (token.type == T.Colon)
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4226 {
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4227 nT();
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4228 specType = parseType();
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4229 }
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4230 // = DefaultType
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4231 if (token.type == T.Assign)
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4232 {
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4233 nT();
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4234 defType = parseType();
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4235 }
340
1accb3013bd2 - Changed class TemplateParameter to an abstract class.
aziz
parents: 335
diff changeset
4236 }
1accb3013bd2 - Changed class TemplateParameter to an abstract class.
aziz
parents: 335
diff changeset
4237
1accb3013bd2 - Changed class TemplateParameter to an abstract class.
aziz
parents: 335
diff changeset
4238 switch (token.type)
1accb3013bd2 - Changed class TemplateParameter to an abstract class.
aziz
parents: 335
diff changeset
4239 {
1accb3013bd2 - Changed class TemplateParameter to an abstract class.
aziz
parents: 335
diff changeset
4240 case T.Alias:
1accb3013bd2 - Changed class TemplateParameter to an abstract class.
aziz
parents: 335
diff changeset
4241 // TemplateAliasParameter:
1accb3013bd2 - Changed class TemplateParameter to an abstract class.
aziz
parents: 335
diff changeset
4242 // alias Identifier
1accb3013bd2 - Changed class TemplateParameter to an abstract class.
aziz
parents: 335
diff changeset
4243 nT(); // Skip alias keyword.
1accb3013bd2 - Changed class TemplateParameter to an abstract class.
aziz
parents: 335
diff changeset
4244 ident = requireId();
1accb3013bd2 - Changed class TemplateParameter to an abstract class.
aziz
parents: 335
diff changeset
4245 parseSpecAndOrDefaultType();
1accb3013bd2 - Changed class TemplateParameter to an abstract class.
aziz
parents: 335
diff changeset
4246 tp = new TemplateAliasParameter(ident, specType, defType);
137
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4247 break;
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4248 case T.Identifier:
253
4279b638c63e - Changed some string types to Token*. Adapted parser accordingly.
aziz
parents: 252
diff changeset
4249 ident = token;
238
f3c6c15961bb - Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents: 237
diff changeset
4250 switch (peekNext())
137
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4251 {
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4252 case T.Ellipses:
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4253 // TemplateTupleParameter:
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4254 // Identifier ...
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4255 nT(); // Skip Identifier.
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4256 nT(); // Skip Ellipses.
341
3ac651ea83fb - Fix: created TemplateAliasParameter instead of TemplateTypeParameter.
aziz
parents: 340
diff changeset
4257 if (token.type == T.Comma)
342
f13d551d7c4f - Added error messages MID.InContract and MID.OutContract.
aziz
parents: 341
diff changeset
4258 error(MID.TemplateTupleParameter);
340
1accb3013bd2 - Changed class TemplateParameter to an abstract class.
aziz
parents: 335
diff changeset
4259 tp = new TemplateTupleParameter(ident);
137
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4260 break;
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4261 case T.Comma, T.RParen, T.Colon, T.Assign:
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4262 // TemplateTypeParameter:
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4263 // Identifier
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4264 nT(); // Skip Identifier.
340
1accb3013bd2 - Changed class TemplateParameter to an abstract class.
aziz
parents: 335
diff changeset
4265 parseSpecAndOrDefaultType();
341
3ac651ea83fb - Fix: created TemplateAliasParameter instead of TemplateTypeParameter.
aziz
parents: 340
diff changeset
4266 tp = new TemplateTypeParameter(ident, specType, defType);
137
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4267 break;
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4268 default:
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4269 // TemplateValueParameter:
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4270 // Declarator
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4271 ident = null;
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4272 goto LTemplateValueParameter;
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4273 }
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4274 break;
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4275 default:
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4276 LTemplateValueParameter:
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4277 // TemplateValueParameter:
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4278 // Declarator
340
1accb3013bd2 - Changed class TemplateParameter to an abstract class.
aziz
parents: 335
diff changeset
4279 Expression specValue, defValue;
1accb3013bd2 - Changed class TemplateParameter to an abstract class.
aziz
parents: 335
diff changeset
4280 auto valueType = parseDeclarator(ident);
137
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4281 // : SpecializationValue
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4282 if (token.type == T.Colon)
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4283 {
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4284 nT();
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4285 specValue = parseCondExpression();
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4286 }
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4287 // = DefaultValue
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4288 if (token.type == T.Assign)
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4289 {
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4290 nT();
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4291 defValue = parseCondExpression();
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4292 }
340
1accb3013bd2 - Changed class TemplateParameter to an abstract class.
aziz
parents: 335
diff changeset
4293 tp = new TemplateValueParameter(valueType, ident, specValue, defValue);
137
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4294 }
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4295
340
1accb3013bd2 - Changed class TemplateParameter to an abstract class.
aziz
parents: 335
diff changeset
4296 // Push template parameter.
1accb3013bd2 - Changed class TemplateParameter to an abstract class.
aziz
parents: 335
diff changeset
4297 tparams ~= set(tp, paramBegin);
137
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4298
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4299 if (token.type != T.Comma)
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4300 break;
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4301 nT();
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4302 }
258
112a57f433f2 - Created class TemplateParameters.
aziz
parents: 257
diff changeset
4303 set(tparams, begin);
137
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4304 return tparams;
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4305 }
b49903801f14 - Implemented parseTemplateParameters().
aziz
parents: 136
diff changeset
4306
124
d4c4cea6ee7f - Renamed method errorIfNot() to expected().
aziz
parents: 123
diff changeset
4307 void expected(TOK tok)
86
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
4308 {
87
c9544b7d5c7d - Added member token and method nT(), which sets token to lx.token.
aziz
parents: 86
diff changeset
4309 if (token.type != tok)
327
a48a987f7515 - Added package dil to import declarations.
aziz
parents: 326
diff changeset
4310 error(MID.ExpectedButFound, Token.toString(tok), token.srcText);
86
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
4311 }
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
4312
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
4313 void require(TOK tok)
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
4314 {
87
c9544b7d5c7d - Added member token and method nT(), which sets token to lx.token.
aziz
parents: 86
diff changeset
4315 if (token.type == tok)
86
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
4316 nT();
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
4317 else
327
a48a987f7515 - Added package dil to import declarations.
aziz
parents: 326
diff changeset
4318 error(MID.ExpectedButFound, Token.toString(tok), token.srcText);
86
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
4319 }
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
4320
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
4321 void requireNext(TOK tok)
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
4322 {
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
4323 nT();
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
4324 require(tok);
86
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
4325 }
0459c902a370 - Added code for parsing Assert-, Mixin-, Import-, Typeid- and TypeDotIdExpressions.
aziz
parents: 85
diff changeset
4326
243
461e544ebb53 - Added method requireId().
aziz
parents: 242
diff changeset
4327 Token* requireId()
461e544ebb53 - Added method requireId().
aziz
parents: 242
diff changeset
4328 {
461e544ebb53 - Added method requireId().
aziz
parents: 242
diff changeset
4329 if (token.type == T.Identifier)
461e544ebb53 - Added method requireId().
aziz
parents: 242
diff changeset
4330 {
461e544ebb53 - Added method requireId().
aziz
parents: 242
diff changeset
4331 auto id = token;
461e544ebb53 - Added method requireId().
aziz
parents: 242
diff changeset
4332 nT();
461e544ebb53 - Added method requireId().
aziz
parents: 242
diff changeset
4333 return id;
461e544ebb53 - Added method requireId().
aziz
parents: 242
diff changeset
4334 }
461e544ebb53 - Added method requireId().
aziz
parents: 242
diff changeset
4335 else
461e544ebb53 - Added method requireId().
aziz
parents: 242
diff changeset
4336 error(MID.ExpectedButFound, "Identifier", token.srcText);
461e544ebb53 - Added method requireId().
aziz
parents: 242
diff changeset
4337 return null;
461e544ebb53 - Added method requireId().
aziz
parents: 242
diff changeset
4338 }
461e544ebb53 - Added method requireId().
aziz
parents: 242
diff changeset
4339
391
33b566df6af4 Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 379
diff changeset
4340 void error(MID mid, ...)
71
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
4341 {
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
4342 if (trying)
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
4343 {
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
4344 ++errorCount;
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
4345 return;
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 206
diff changeset
4346 }
422
ad7977fe315a Added support for column numbers in error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 417
diff changeset
4347 lx.updateErrorLoc(token.start);
ad7977fe315a Added support for column numbers in error messages.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 417
diff changeset
4348 errors ~= new Information(InfoType.Parser, mid, lx.errorLoc.clone, Format(_arguments, _argptr, GetMsg(mid)));
71
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
4349 }
65
6c21ae79fbb3 - Renamed function Token.span to Token.srcText.
aziz
parents: 0
diff changeset
4350 }