annotate trunk/src/Parser.d @ 116:f0c1883cdd4c

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