annotate trunk/src/Parser.d @ 71:b3777cca323c

- Added Identity and NotIdentity tokens. - Added constructor to Parser. Added error method and parseCondExpression(). - Added parseAssignExpression() method. - Moved arguments() function from error() method of Lexer to module Information. - Added members and constructor to BinaryExpression. - Added XYZAssignExpression classes. - Added calls to super() to classes that inherit from BinaryExpression.
author aziz
date Sun, 01 Jul 2007 16:16:05 +0000
parents 0d3ef6daec04
children f75e359f939f
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;
70
0d3ef6daec04 - Added Expression class stubs.
aziz
parents: 69
diff changeset
10 import Expressions;
65
6c21ae79fbb3 - Renamed function Token.span to Token.srcText.
aziz
parents: 0
diff changeset
11
68
7eb83dd38901 - Simplified suffix rule and added a few more numbers to unittest.
aziz
parents: 65
diff changeset
12 enum STC
7eb83dd38901 - Simplified suffix rule and added a few more numbers to unittest.
aziz
parents: 65
diff changeset
13 {
7eb83dd38901 - Simplified suffix rule and added a few more numbers to unittest.
aziz
parents: 65
diff changeset
14 Abstract,
7eb83dd38901 - Simplified suffix rule and added a few more numbers to unittest.
aziz
parents: 65
diff changeset
15 Auto,
7eb83dd38901 - Simplified suffix rule and added a few more numbers to unittest.
aziz
parents: 65
diff changeset
16 Const,
7eb83dd38901 - Simplified suffix rule and added a few more numbers to unittest.
aziz
parents: 65
diff changeset
17 Deprecated,
7eb83dd38901 - Simplified suffix rule and added a few more numbers to unittest.
aziz
parents: 65
diff changeset
18 Extern,
7eb83dd38901 - Simplified suffix rule and added a few more numbers to unittest.
aziz
parents: 65
diff changeset
19 Final,
7eb83dd38901 - Simplified suffix rule and added a few more numbers to unittest.
aziz
parents: 65
diff changeset
20 Invariant,
7eb83dd38901 - Simplified suffix rule and added a few more numbers to unittest.
aziz
parents: 65
diff changeset
21 Override,
7eb83dd38901 - Simplified suffix rule and added a few more numbers to unittest.
aziz
parents: 65
diff changeset
22 Scope,
7eb83dd38901 - Simplified suffix rule and added a few more numbers to unittest.
aziz
parents: 65
diff changeset
23 Static,
7eb83dd38901 - Simplified suffix rule and added a few more numbers to unittest.
aziz
parents: 65
diff changeset
24 Synchronized
7eb83dd38901 - Simplified suffix rule and added a few more numbers to unittest.
aziz
parents: 65
diff changeset
25 }
7eb83dd38901 - Simplified suffix rule and added a few more numbers to unittest.
aziz
parents: 65
diff changeset
26
71
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
27 private alias TOK T;
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
28
65
6c21ae79fbb3 - Renamed function Token.span to Token.srcText.
aziz
parents: 0
diff changeset
29 class Parser
6c21ae79fbb3 - Renamed function Token.span to Token.srcText.
aziz
parents: 0
diff changeset
30 {
71
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
31 Lexer lx;
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
32 TOK delegate() nT;
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
33
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
34 Information[] errors;
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
35
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
36 this(char[] srcText, string fileName)
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
37 {
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
38 lx = new Lexer(srcText, fileName);
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
39 nT = &lx.nextToken;
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
40 }
70
0d3ef6daec04 - Added Expression class stubs.
aziz
parents: 69
diff changeset
41
71
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
42 Expression parseAssignExpression()
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
43 {
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
44 auto e = parseCondExpression();
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
45 switch (lx.token.type)
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
46 {
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
47 case T.Assign:
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
48 nT(); e = new AssignExpression(e, parseAssignExpression());
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
49 break;
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
50 case T.LShiftAssign:
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
51 nT(); e = new LShiftAssignExpression(e, parseAssignExpression());
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
52 break;
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
53 case T.RShiftAssign:
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
54 nT(); e = new RShiftAssignExpression(e, parseAssignExpression());
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
55 break;
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
56 case T.URShiftAssign:
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
57 nT(); e = new URShiftAssignExpression(e, parseAssignExpression());
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
58 break;
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
59 case T.OrAssign:
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
60 nT(); e = new OrAssignExpression(e, parseAssignExpression());
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
61 break;
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
62 case T.AndAssign:
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
63 nT(); e = new AndAssignExpression(e, parseAssignExpression());
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
64 break;
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
65 case T.PlusAssign:
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
66 nT(); e = new PlusAssignExpression(e, parseAssignExpression());
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
67 break;
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
68 case T.MinusAssign:
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
69 nT(); e = new MinusAssignExpression(e, parseAssignExpression());
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
70 break;
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
71 case T.DivAssign:
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
72 nT(); e = new DivAssignExpression(e, parseAssignExpression());
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
73 break;
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
74 case T.MulAssign:
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
75 nT(); e = new MulAssignExpression(e, parseAssignExpression());
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
76 break;
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
77 case T.ModAssign:
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
78 nT(); e = new ModAssignExpression(e, parseAssignExpression());
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
79 break;
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
80 case T.XorAssign:
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
81 nT(); e = new XorAssignExpression(e, parseAssignExpression());
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
82 break;
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
83 case T.CatAssign:
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
84 nT(); e = new CatAssignExpression(e, parseAssignExpression());
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
85 break;
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
86 default:
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
87 break;
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
88 }
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
89 return e;
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
90 }
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
91 Expression parseCondExpression()
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
92 {
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
93 return new Expression();
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
94 }
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
95
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
96 void error(MID id, ...)
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
97 {
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
98 errors ~= new Information(Information.Type.Parser, id, lx.loc, arguments(_arguments, _argptr));
b3777cca323c - Added Identity and NotIdentity tokens.
aziz
parents: 70
diff changeset
99 }
65
6c21ae79fbb3 - Renamed function Token.span to Token.srcText.
aziz
parents: 0
diff changeset
100 }