annotate trunk/src/Parser.d @ 113:20d8ae8a3fd9

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