annotate parser/Parser.d @ 136:2be29b296081

Lots of changes: - Parsing classes and interfaces - Fixed some seg faults in sema - Supporting "private" to some extend - And a lot of other small fixes
author johnsen@johnsen-laptop
date Fri, 11 Jul 2008 21:47:57 +0200
parents c3b24e7e8cf8
children 927ae00bd9d2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
1 module parser.Parser;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
2
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
3 import lexer.Lexer,
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
4 lexer.Token;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
5
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
6 import parser.Action;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
7
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
8 import basic.Message,
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
9 basic.Attribute;
21
0fb2d13dce37 Now working with gdc also (gdc use reverse paremeter validating on function calls)
johnsen@johnsen-laptop
parents: 12
diff changeset
10
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 84
diff changeset
11 import basic.SmallArray,
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 84
diff changeset
12 basic.SourceManager;
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
13
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
14 import tango.io.Stdout,
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
15 Integer = tango.text.convert.Integer;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
16
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
17 class Parser
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
18 {
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
19 Action action;
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
20 MessageHandler messages;
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
21 alias Object Exp;
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
22 alias Object Stmt;
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
23 alias Object Decl;
94
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
24 alias Object Module;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
25
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
26 this(MessageHandler messages)
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
27 {
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
28 this.messages = messages;
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
29 }
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
30
94
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
31 Module parse(SourceManager sm, Lexer lexer, Action act)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
32 {
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 84
diff changeset
33 this.sm = sm;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
34 this.lexer = lexer;
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 84
diff changeset
35 this.action = act;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
36
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
37 Module m;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
38 if (lexer.peek.type == Tok.Module)
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
39 {
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
40 Token _module = lexer.next;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
41 ModuleName name = parseModuleName();
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
42 m = action.actOnModule(_module, sm.getText(name.asRange()));
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
43 require(Tok.Seperator);
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
44 }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
45 else
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
46 {
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
47 SLoc loc = lexer.peek.location;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
48 m = action.actOnImplicitModule(loc, sm.getFile(loc));
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
49 }
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
50
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
51 Attribute att;
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
52 while (lexer.peek.type != Tok.EOF)
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
53 foreach (d; parseDeclDef(&att))
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
54 action.actOnModuleDecl(m, d);
94
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
55
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
56 return m;
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
57 }
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
58
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
59 private:
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
60 Decl[] parseDeclDef(Attribute* a)
94
48bb2287c035 Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents: 92
diff changeset
61 {
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
62 Token t = lexer.peek;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
63 if (t.type == Tok.Import)
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
64 return parseImports();
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
65 else
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
66 return [parseDecl(a)];
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
67 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
68
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
69 Decl parseDecl(Attribute* all_res)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
70 {
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
71 Token t = lexer.peek;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
72
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
73 Attribute att = *all_res;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
74
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
75 while ( t.isAttribute )
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
76 {
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
77 Attribute* a = &att;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
78 bool sco;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
79 if(lexer.peek(1).type == Tok.Colon)
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
80 sco = true;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
81
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
82 LSwitch: switch(t.type)
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
83 {
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
84 case Tok.Public:
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
85 a.setProtection(Protection.Public);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
86 break;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
87 case Tok.Private:
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
88 a.setProtection(Protection.Private);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
89 break;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
90 case Tok.Package:
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
91 a.setProtection(Protection.Package);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
92 break;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
93 case Tok.Protected:
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
94 a.setProtection(Protection.Protected);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
95 break;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
96 case Tok.Export:
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
97 a.setProtection(Protection.Export);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
98 break;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
99 case Tok.Static:
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
100 a.setStatic;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
101 break;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
102 case Tok.Final:
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
103 a.setFinal;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
104 break;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
105 case Tok.Const:
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
106 a.setConst;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
107 break;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
108 case Tok.Abstract:
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
109 a.setAbstract;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
110 break;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
111 case Tok.Override:
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
112 a.setOverride;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
113 break;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
114 case Tok.Depracted:
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
115 a.setDepracted;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
116 break;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
117 case Tok.Auto:
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
118 a.setAuto;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
119 break;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
120 }
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
121 if(sco)
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
122 {
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
123 sco = false;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
124 a = all_res;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
125 lexer.next;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
126 goto LSwitch;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
127 }
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
128 lexer.next;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
129 t = lexer.peek;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
130 }
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
131
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
132
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
133 if (t.isBasicType || t.isIdentifier)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
134 {
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
135 Id type;
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
136 Id iden;
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
137 int len = peekParseType;
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
138 if(lexer.peek(len).type == Tok.Identifier && len != 0)
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
139 {
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
140 type = parseType;
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
141 parseDeclAfterInvalidType:
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
142 iden = Id(require(Tok.Identifier));
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
143 Token next = lexer.peek();
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
144 if (next.type == Tok.Seperator)
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
145 {
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
146 Token sep = lexer.next();
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
147 return action.actOnDeclarator(type, iden, null, att);
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
148 }
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
149 else if (next.type == Tok.Assign)
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
150 {
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
151 Token assign = lexer.next();
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
152 Exp exp = parseExpression();
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
153 require(Tok.Seperator);
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
154 return action.actOnDeclarator(type, iden, exp, att);
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
155 }
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
156 else if (next.type == Tok.OpenParentheses)
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
157 return parseFunc(type, iden, att);
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
158 else
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
159 messages.report(UnexpectedTok, next.location).arg(next.getType);
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
160 return null;
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
161 }
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
162 t = lexer.peek(len);
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
163 messages.report(InvalidDeclType, t.location)
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
164 .arg(sm.getText(t.asRange));
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
165 while(len--)
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
166 lexer.next;
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
167 while(lexer.peek.type != Tok.Identifier)
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
168 lexer.next;
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
169 type = Id(lexer.peek);
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
170 goto parseDeclAfterInvalidType;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
171 }
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
172 else if (t.type == Tok.Struct)
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
173 {
53
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
174 Id type = Id(lexer.next);
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
175 Id iden = Id(require(Tok.Identifier));
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
176
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
177 return parseStruct(type, iden, att);
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
178 }
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
179 else if (t.type == Tok.Class)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
180 {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
181 Id type = Id(lexer.next);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
182 Id iden = Id(require(Tok.Identifier));
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
183
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
184 return parseClass(type, iden, att);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
185 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
186 else if (t.type == Tok.Interface)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
187 {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
188 Id type = Id(lexer.next);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
189 Id iden = Id(require(Tok.Identifier));
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
190
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
191 return parseClass(type, iden, att);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
192 }
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
193 messages.report(UnexpectedTok, t.location)
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
194 .arg(t.getType)
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
195 .arg(Tok.Identifier)
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
196 .fatal(ExitLevel.Parser);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
197 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
198
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
199 /**
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
200 Parse a series of imports belonging to a single import token.
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
201 */
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
202 Decl[] parseImports()
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
203 {
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
204 Token _import = require(Tok.Import);
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
205 SmallArray!(Decl) res;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
206 void addToRes(Decl d) { res ~= d; }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
207
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
208 bool done = false;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
209 while (!done && !on_a(Tok.Seperator))
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
210 {
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
211 ModuleName mod = parseModuleName();
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
212 Token tok = lexer.peek;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
213 switch (tok.type)
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
214 {
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
215 case Tok.Comma:
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
216 // import A, B.C;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
217 // parse another module-name
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
218 lexer.next();
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
219 res ~= action.actOnImport(_import, mod, null);
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
220 break;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
221 case Tok.Assign:
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
222 // import B = A.A;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
223 // ^- must be a single identifier
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
224 // renamed import
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
225 if (mod.packages.length != 0)
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
226 {
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
227 SLoc loc = mod.packages[0].tok.location;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
228 messages.report(RenameMustBeSingleIdent, loc);
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
229 }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
230 //if (isStatic)
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
231 // error("Static imports cannot be renamed");
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
232 lexer.next();
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
233 Id name = mod.id;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
234 mod = parseModuleName();
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
235 // create from mod and rename to `name`
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
236 res ~= action.actOnImport(_import, mod, &name);
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
237 break;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
238 case Tok.Colon:
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
239 // import A : a;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
240 // selective imports, potentially import A : print = a
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
241 lexer.next();
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
242 Decl d = action.actOnImport(_import, mod, null);
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
243 // do-while on a comma:
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
244 // add explicit symbol
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
245 do
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
246 {
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
247 Id sym = parseIdentifier();
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
248 Id dummy;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
249 Id* name = null;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
250 if (skip(Tok.Assign))
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
251 {
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
252 dummy = sym;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
253 name = &dummy;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
254 sym = parseIdentifier();
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
255 }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
256 action.addSelectiveImport(d, sym, name);
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
257
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
258 } while (skip(Tok.Comma));
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
259 require(Tok.Seperator);
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
260 res ~= d;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
261 return res.safe();
100
5f258eaf9517 Loading modules in. Just need to add them to the scope of the "main" Module now.
Anders Johnsen <skabet@gmail.com>
parents: 99
diff changeset
262 case Tok.Seperator:
5f258eaf9517 Loading modules in. Just need to add them to the scope of the "main" Module now.
Anders Johnsen <skabet@gmail.com>
parents: 99
diff changeset
263 done = true;
5f258eaf9517 Loading modules in. Just need to add them to the scope of the "main" Module now.
Anders Johnsen <skabet@gmail.com>
parents: 99
diff changeset
264 break;
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
265 default:
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
266 goto Lerror;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
267 }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
268 res ~= action.actOnImport(_import, mod, null);
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
269 }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
270
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
271 require(Tok.Seperator);
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
272 return res.safe();
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
273 Lerror:
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
274 while (!on_a (Tok.Seperator))
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
275 lexer.next();
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
276 return res.safe();
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
277 }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
278
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
279 /**
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
280 Parse interface
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
281 */
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
282 Decl parseInterface(Id type, Id iden, Attribute att)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
283 {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
284 auto decl = action.actOnDeclarator(type, iden, null, att);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
285
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
286 if (lexer.peek.type == Tok.Colon)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
287 // SuperInterfaces
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
288 {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
289 lexer.next; // Remove colon.
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
290
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
291 Token identifier;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
292
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
293 // The identifier
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
294 identifier = require(Tok.Identifier);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
295
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
296 // FIXME: Register Interface here
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
297
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
298 // We should now have an optional list of items, each starting ','
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
299 while (lexer.peek.type == Tok.Comma)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
300 {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
301 lexer.next; // Remove comma
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
302
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
303 // The identifier
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
304 identifier = require(Tok.Identifier);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
305
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
306 // FIXME: Register Interface here
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
307 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
308 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
309
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
310 require(Tok.OpenBrace);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
311
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
312 Attribute a;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
313 while(lexer.peek.isBasicType || lexer.peek.isIdentifier || lexer.peek.isAttribute)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
314 {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
315 auto m_decl = parseDecl(&a);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
316 action.actOnStructMember(decl, m_decl);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
317 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
318
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
319 require(Tok.CloseBrace);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
320
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
321 return decl;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
322 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
323
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
324 /**
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
325 Parse class
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
326 */
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
327 Decl parseClass(Id type, Id iden, Attribute att)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
328 {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
329 auto decl = action.actOnDeclarator(type, iden, null, att);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
330
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
331 if (lexer.peek.type == Tok.Colon)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
332 // BaseClassList - Super class and interfaces(in that order)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
333 {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
334 lexer.next; // Remove colon.
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
335
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
336 Token protection, identifier;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
337
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
338 // First we expect an optional protection level.
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
339 if (lexer.peek.isBaseClassProtection)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
340 protection = lexer.next;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
341 // Then the identifier
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
342 identifier = require(Tok.Identifier);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
343
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
344 // FIXME: Register Interface here
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
345
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
346 // We should now have an optional list of items, each starting ','
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
347 while (lexer.peek.type == Tok.Comma)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
348 {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
349 lexer.next; // Remove comma
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
350
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
351 // First we expect an optional protection level.
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
352 if (lexer.peek.isBaseClassProtection)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
353 protection = lexer.next;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
354 // Then the identifier
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
355 identifier = require(Tok.Identifier);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
356 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
357 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
358
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
359 require(Tok.OpenBrace);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
360
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
361 Attribute a;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
362 while(lexer.peek.isBasicType || lexer.peek.isIdentifier || lexer.peek.isAttribute)
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
363 {
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
364 auto m_decl = parseDecl(&a);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
365 action.actOnStructMember(decl, m_decl); // FIXME: Should call actOnClassMember
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
366 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
367
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
368 require(Tok.CloseBrace);
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
369
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
370 return decl;
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
371 }
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
372
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
373 /**
53
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
374 Parse struct
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
375 */
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
376 Decl parseStruct(Id type, Id iden, Attribute att)
53
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
377 {
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
378 auto decl = action.actOnDeclarator(type, iden, null, att);
53
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
379
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
380 require(Tok.OpenBrace);
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
381
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
382 Attribute a;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
383 while(lexer.peek.isBasicType || lexer.peek.isIdentifier || lexer.peek.isAttribute)
53
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
384 {
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
385 auto m_decl = parseDecl(&a);
102
cd066f3b539a Parsing methods in structs - error on semantics though.
Anders Johnsen <skabet@gmail.com>
parents: 100
diff changeset
386 action.actOnStructMember(decl, m_decl);
53
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
387 }
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
388
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
389 require(Tok.CloseBrace);
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
390
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
391 return decl;
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
392 }
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
393
53
da551f90e03f Added struct decl and forward ref. A note on structs: they need to make a new scope when declared. Otherwise you could access struct members as globals
Anders Johnsen <skabet@gmail.com>
parents: 51
diff changeset
394 /**
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
395 Parse statements.
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
396
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
397 This is the place to attack!
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
398 */
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
399 Stmt parseStatement()
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
400 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
401 Token t = lexer.peek;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
402
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
403 if (t.isReturn)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
404 {
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
405 Token ret = lexer.next;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
406 Exp exp;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
407 if (lexer.peek.type != Tok.Seperator)
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
408 exp = parseExpression();
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
409 require(Tok.Seperator);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
410 return action.actOnReturnStmt(ret, exp);
5
2c5a8f4c254a Added very simple if support.
Anders Halager <halager@gmail.com>
parents: 1
diff changeset
411
45
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
412 /*
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
413 if (cond)
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
414 single statement | compound statement
45
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
415 [else
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
416 single statement | compound statement]
45
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
417 */
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
418 }
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
419 else if (t.isIf)
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
420 {
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
421 Token _if = lexer.next();
45
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
422
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
423 require(Tok.OpenParentheses);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
424 Exp cond = parseExpression();
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
425 require(Tok.CloseParentheses);
45
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
426
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
427 Stmt thenB = parseSingleOrCompoundStatement();
45
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
428
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
429 // if there is no else part we use the if as token, to have
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
430 // something than can be passed along
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
431 Token _else = _if;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
432 Stmt elseB;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
433 if (lexer.peek.type == Tok.Else)
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
434 {
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
435 _else = lexer.next;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
436 elseB = parseSingleOrCompoundStatement();
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
437 }
45
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
438
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
439 return action.actOnIfStmt(_if, cond, thenB, _else, elseB);
5
2c5a8f4c254a Added very simple if support.
Anders Halager <halager@gmail.com>
parents: 1
diff changeset
440
47
b0a691727a0c Stricter while - the () was optional before
Anders Halager <halager@gmail.com>
parents: 46
diff changeset
441 /*
b0a691727a0c Stricter while - the () was optional before
Anders Halager <halager@gmail.com>
parents: 46
diff changeset
442 while (cond)
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
443 single statement | compound statement
47
b0a691727a0c Stricter while - the () was optional before
Anders Halager <halager@gmail.com>
parents: 46
diff changeset
444 */
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
445 }
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
446 else if (t.isWhile)
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
447 {
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
448 Token _while = lexer.next;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
449 require(Tok.OpenParentheses);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
450 Exp cond = parseExpression();
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
451 require(Tok.CloseParentheses);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
452 Stmt bodyStmt = parseSingleOrCompoundStatement();
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
453 return action.actOnWhileStmt(_while, cond, bodyStmt);
5
2c5a8f4c254a Added very simple if support.
Anders Halager <halager@gmail.com>
parents: 1
diff changeset
454
48
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
455 /*
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
456 One of four things:
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
457 A declaration of a function/variable `type id ...`
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
458 A direct assignment `id = exp;`
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
459 An indirect assignment `id.id = exp`
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
460 Some sort of free standing expression
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
461
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
462 The assignments should be handled as binary expressions?
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
463 */
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
464 }
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
465 else if (t.isBasicType || t.isIdentifier)
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
466 {
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
467 Token iden = lexer.peek;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
468 Token n = lexer.peek(1);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
469 // Must be an decl, if we start with a basic type, or two
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
470 // identifiers in a row
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
471 if ( n.type == Tok.Star || n.type == Tok.OpenBracket)
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
472 {
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
473 int len = peekParseType;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
474 if(lexer.peek(len).type == Tok.Identifier && len != 0)
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
475 return action.actOnDeclStmt(parseVarDecl());
84
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
476
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
477 Exp exp = parseExpression();
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
478 require(Tok.Seperator);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
479 return action.actOnExprStmt(exp);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
480 }
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
481
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
482 if (n.isIdentifier())
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
483 return action.actOnDeclStmt(parseVarDecl());
76
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
484
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
485 // Expression: a.b, a = b, a(b) etc.
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
486 Exp exp = parseExpression();
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
487 require(Tok.Seperator);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
488 return action.actOnExprStmt(exp);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
489 }
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
490 else if(t.isSwitch)
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
491 {
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
492 messages.report(UnexpectedTok, lexer.peek.location).arg(lexer.next.getType);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
493 return null;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
494 }
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
495 else
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
496 {
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
497 if (t.type == Tok.Star)
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
498 {
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
499 auto exp = parseExpression();
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
500 require(Tok.Seperator);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
501 return action.actOnExprStmt(exp);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
502 }
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
503 messages.report(UnexpectedBeginStmt, lexer.peek.location).arg(lexer.next.getType);
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
504 return null;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
505 }
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
506 messages.report(UnexpectedTok, t.location);
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
507 return null;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
508 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
509
76
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
510 Decl parseVarDecl()
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
511 {
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
512 // manually hardcoded to only support "type id [= exp];"
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
513 // as that is the only thing the codegen understands
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
514 Id type = parseType;
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
515 Id id = Id(lexer.next);
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
516 Exp init;
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
517 if (skip(Tok.Assign))
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
518 init = parseExpression();
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
519 require(Tok.Seperator);
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
520 Attribute att;
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
521 Decl d = action.actOnDeclarator(type, id, init, att);
76
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
522 return d;
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
523 }
9171f04dd9ee Now parsing varDecls a lot nicer!
Anders Johnsen <skabet@gmail.com>
parents: 75
diff changeset
524
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
525 /**
48
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
526 Parses a function/method given the already parsed return type and name
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
527 */
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
528 Decl parseFunc(ref Id type, ref Id name, Attribute att)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
529 {
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
530 Decl func = action.actOnStartOfFunctionDef(type, name, att);
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
531 parseFuncArgs(func);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
532
82
06dda301ea61 Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents: 81
diff changeset
533 if(lexer.peek.type == Tok.Seperator)
06dda301ea61 Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents: 81
diff changeset
534 {
06dda301ea61 Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents: 81
diff changeset
535 lexer.next;
06dda301ea61 Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents: 81
diff changeset
536 return func;
06dda301ea61 Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents: 81
diff changeset
537 }
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
538 Stmt stmt = parseCompoundStatement();
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
539
48
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
540 return action.actOnEndOfFunction(func, stmt);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
541 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
542
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
543 /**
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
544 Parse the function arguments, assumes current token is (.
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
545
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
546 Both the intitial paren and the ending paren is consumed.
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
547 */
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
548 void parseFuncArgs(Decl func)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
549 {
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
550 require(Tok.OpenParentheses); // Remove the "(" token.
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
551
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
552 while(lexer.peek.type != Tok.CloseParentheses)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
553 {
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
554 auto t = parseType();
82
06dda301ea61 Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents: 81
diff changeset
555 Id i;
06dda301ea61 Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents: 81
diff changeset
556 if(lexer.peek.type == Tok.Identifier)
06dda301ea61 Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents: 81
diff changeset
557 i = parseIdentifier();
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
558 action.addFuncArg(func, t, i);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
559
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
560 if(lexer.peek.type == Tok.Comma)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
561 lexer.next;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
562 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
563
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
564 require(Tok.CloseParentheses); // Remove the ")"
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
565 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
566
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
567 /**
45
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
568 Parse either a block, or a single statement as allowed after if, while
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
569 and for.
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
570 */
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
571 Stmt parseSingleOrCompoundStatement()
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
572 {
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
573 if (lexer.peek.type == Tok.OpenBrace)
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
574 return parseCompoundStatement();
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
575 return parseStatement();
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
576 }
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
577
45
9bc660cbdbec If statements are back
Anders Halager <halager@gmail.com>
parents: 44
diff changeset
578 /**
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
579 Parses a function-body or similar, expects an opening brace to be the
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
580 current token.
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
581
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
582 Will consume both the starting { and ending }
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
583 */
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
584 Stmt parseCompoundStatement()
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
585 {
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
586 Token lbrace = require(Tok.OpenBrace);
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
587 SmallArray!(Stmt, 32) stmts; // Try to use the stack only
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
588 while (lexer.peek.type != Tok.CloseBrace)
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
589 stmts ~= parseStatement();
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
590 Token rbrace = require(Tok.CloseBrace);
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
591 return action.actOnCompoundStmt(lbrace, rbrace, stmts.unsafe());
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
592 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
593
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
594 Id parseIdentifier()
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
595 {
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
596 Token tok = lexer.next;
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
597
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
598 if (tok.type is Tok.Identifier)
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
599 return Id(tok);
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
600
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
601 messages.report(UnexpectedTokSingle, tok.location)
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
602 .arg(tok.getType)
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
603 .arg(Tok.Identifier);
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
604 }
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
605
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
606 ModuleName parseModuleName()
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
607 {
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
608 auto id = parseIdentifier();
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
609 ModuleName mod;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
610 while (skip(Tok.Dot))
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
611 {
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
612 mod.packages ~= id;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
613 if (lexer.peek.type != Tok.Identifier) {
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
614 messages.report(ExpectedIdAfterPackage, lexer.peek.location);
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
615 goto Lerror;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
616 }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
617 id = parseIdentifier();
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
618 }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
619 mod.id = id;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
620 return mod;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
621 Lerror:
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
622 while (!skip(Tok.Seperator))
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
623 lexer.next();
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
624 return mod;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
625 }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
626
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
627
75
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
628 /**
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
629 Parse a type - this includes pointer and array(at some point) types.
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
630 */
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
631 Id parseType()
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
632 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
633 Token type = lexer.next;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
634
75
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
635 Id currentType;
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
636
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
637 if ( !(type.isBasicType || type.type == Tok.Identifier) )
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
638 messages.report(InvalidType, type.location);
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
639
75
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
640 currentType = Id(type);
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
641 type = lexer.peek;
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
642
81
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
643 while(type.type == Tok.Star || type.type == Tok.OpenBracket)
75
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
644 {
81
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
645 if(type.type == Tok.Star)
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
646 {
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
647 currentType = PointerId(currentType);
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
648 lexer.next;
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
649 }
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
650 else
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
651 {
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
652 lexer.next;
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
653 if(lexer.peek.type == Tok.Integer)
136
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
654 currentType = StaticArrayId(
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
655 currentType,
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
656 action.actOnNumericConstant(
2be29b296081 Lots of changes:
johnsen@johnsen-laptop
parents: 126
diff changeset
657 require(Tok.Integer)));
81
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
658 require(Tok.CloseBracket);
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
659
110c7e1c4ca2 Now you can declare array
Anders Johnsen <skabet@gmail.com>
parents: 80
diff changeset
660 }
75
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
661 type = lexer.peek;
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
662 }
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
663
86aec2160221 Parsing "int* x"
Anders Johnsen <skabet@gmail.com>
parents: 74
diff changeset
664 return currentType;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
665 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
666
84
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
667 int peekParseType()
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
668 {
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
669 int i;
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
670 Token type = lexer.peek(i);
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
671
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
672 Id currentType;
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
673
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
674 if ( !(type.isBasicType || type.type == Tok.Identifier) )
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
675 return 0;
84
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
676
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
677 currentType = Id(type);
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
678 type = lexer.peek(++i);
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
679
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
680 while(type.type == Tok.Star || type.type == Tok.OpenBracket)
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
681 {
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
682 if(type.type == Tok.Star)
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
683 {
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
684 i++;
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
685 }
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
686 else
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
687 {
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
688 if(lexer.peek(i++).type != Tok.OpenBracket)
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
689 return 0;
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
690 if(lexer.peek(i).type == Tok.Integer)
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
691 {
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
692 i++;
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
693 if(lexer.peek(i++).type != Tok.CloseBracket)
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
694 return 0;
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
695 }
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
696 else
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
697 if(lexer.peek(i++).type != Tok.CloseBracket)
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
698 return 0;
84
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
699
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
700 }
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
701 type = lexer.peek(i);
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
702 }
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
703
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
704 return i;
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
705 }
cc05c041e6a3 Assign stuff to arrays.
Anders Johnsen <skabet@gmail.com>
parents: 83
diff changeset
706
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
707 private:
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
708 // -- Expression parsing -- //
83
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 82
diff changeset
709 Exp parsePostfixExp(Exp target)
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
710 {
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
711 switch(lexer.peek.type)
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
712 {
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
713 case Tok.Dot:
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
714 switch(lexer.peek(1).type)
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
715 {
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
716 case Tok.Identifier:
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
717 Token op = lexer.next;
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
718 Id member = Id(lexer.next);
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
719 Exp exp = action.actOnMemberReference(target, op.location, member);
83
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 82
diff changeset
720 return parsePostfixExp(exp);
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
721 default:
30
3147a52d1247 Ooops.. should have compiled before commit.. now works again
Anders Halager <halager@gmail.com>
parents: 29
diff changeset
722 Token t = lexer.peek(1);
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
723 messages.report(ExpectedIdAfterDot, t.location);
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
724 }
83
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 82
diff changeset
725 case Tok.OpenBracket:
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 82
diff changeset
726 Token open = lexer.next;
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 82
diff changeset
727 Exp index = parseExpression();
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 82
diff changeset
728 Token close = require(Tok.CloseBracket);
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 82
diff changeset
729 return action.actOnIndexEpr(target, open, index, close);
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
730 default:
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
731 return target;
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
732 }
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
733 }
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
734
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
735 Exp parseExpression(int p = 0)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
736 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
737 auto exp = P();
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
738 Token next = lexer.peek();
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
739 BinOp* op = null;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
740 while ((op = binary(next.type)) != null && op.prec >= p)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
741 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
742 lexer.next();
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
743 int q = op.leftAssoc? 1 + op.prec : op.prec;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
744 auto exp2 = parseExpression(q);
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 84
diff changeset
745 exp = action.actOnBinaryOp(next.location, op.operator, exp, exp2);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
746 next = lexer.peek();
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
747 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
748
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
749 return exp;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
750 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
751
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
752 Exp P()
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
753 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
754 Token next = lexer.next();
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
755 if (auto op = unary(next.type))
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
756 return action.actOnUnaryOp(next, parseExpression(op.prec));
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
757 else if (next.type == Tok.OpenParentheses)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
758 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
759 auto e = parseExpression(0);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
760 require(Tok.CloseParentheses);
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
761 return e;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
762 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
763 else if (next.type == Tok.Identifier)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
764 {
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
765 Exp value = action.actOnIdentifierExp(Id(next));
83
9e90694f5da0 Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents: 82
diff changeset
766 Exp iden = parsePostfixExp(value);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
767 switch(lexer.peek.type)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
768 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
769 case Tok.OpenParentheses:
48
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
770 Token lp = lexer.next;
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
771 SmallArray!(Exp, 8) args;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
772 while(lexer.peek.type != Tok.CloseParentheses)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
773 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
774 if(lexer.peek.type == Tok.Comma)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
775 lexer.next;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
776 args ~= parseExpression();
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
777 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
778
48
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
779 Token rp = lexer.next();
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
780 return action.actOnCallExpr(iden, lp, args.unsafe(), rp);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
781
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
782 default:
28
69464d465284 Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents: 22
diff changeset
783 return iden;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
784 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
785 }
68
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 62
diff changeset
786 else if (next.type == Tok.Cast)
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 84
diff changeset
787 return parseCast(next);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
788 else if (next.type == Tok.Integer)
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
789 return action.actOnNumericConstant(next);
104
7ff4bc2accf2 Lexing more types of strings. Now all's left is to parse the string in the AST.
Anders Johnsen <skabet@gmail.com>
parents: 102
diff changeset
790 else if (next.type == Tok.String)
7ff4bc2accf2 Lexing more types of strings. Now all's left is to parse the string in the AST.
Anders Johnsen <skabet@gmail.com>
parents: 102
diff changeset
791 return action.actOnStringExp(next);
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
792
92
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
793 messages.report(ExpectedExp, next.location)
771ac63898e2 A few better parser errors plus renaming most of the sema classes to match that they do now. Some have changes a lot.
Anders Johnsen <skabet@gmail.com>
parents: 89
diff changeset
794 .fatal(ExitLevel.Parser);
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
795 return null;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
796 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
797
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 84
diff changeset
798 Exp parseCast(ref Token _cast)
68
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 62
diff changeset
799 {
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 62
diff changeset
800 require(Tok.OpenParentheses);
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 62
diff changeset
801 auto next = lexer.next;
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 62
diff changeset
802 if(!next.isBasicType && !next.isIdentifier)
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
803 messages.report(ExpectedCastType, next.location);
68
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 62
diff changeset
804
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 62
diff changeset
805 require(Tok.CloseParentheses);
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 62
diff changeset
806 auto exp = P();
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 84
diff changeset
807 return action.actOnCastExpr(_cast, Id(next), exp);
68
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 62
diff changeset
808 }
381975d76baf A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents: 62
diff changeset
809
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
810 struct UnOp
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
811 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
812 Tok tokenType;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
813 int prec;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
814 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
815
78
ad956143dcdc Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents: 76
diff changeset
816 static const UnOp[] _unary =
ad956143dcdc Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents: 76
diff changeset
817 [
ad956143dcdc Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents: 76
diff changeset
818 {Tok.Minus, 4},
ad956143dcdc Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents: 76
diff changeset
819 {Tok.Star, 4}
ad956143dcdc Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents: 76
diff changeset
820 ];
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
821 UnOp* unary(Tok t)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
822 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
823 foreach (ref op; _unary)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
824 if (op.tokenType == t)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
825 return &op;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
826 return null;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
827 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
828
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
829 struct BinOp
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
830 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
831 Tok tokenType;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
832 int prec;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
833 bool leftAssoc;
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
834 Operator operator;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
835 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
836
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
837 static const BinOp[] _binary =
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
838 [
126
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
839 {Tok.Assign, 1, false, Operator.Assign},
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
840 {Tok.PlusAssign, 1, false, Operator.AddAssign},
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
841 {Tok.MinusAssign, 1, false, Operator.SubAssign},
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
842 {Tok.StarAssign, 1, false, Operator.MulAssign},
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
843 {Tok.SlashAssign, 1, false, Operator.DivAssign},
c3b24e7e8cf8 Carius changes to the parser. Parsing attributes, lexing many keywords(not all yet).
Anders Johnsen <skabet@gmail.com>
parents: 123
diff changeset
844 {Tok.PercentAssign, 1, false, Operator.ModAssign},
48
b6c1dc30ca4b Only tests that dont pass now are structs and switches
Anders Halager <halager@gmail.com>
parents: 47
diff changeset
845
116
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
846 // =, += etc. 1
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
847 // (need special-case for the ternary operator at this level)
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
848 // ||, 2
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
849 // &&, 3
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
850 // |, 4
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
851 // &, 5
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
852 // ^, 6
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
853 // ==, !=, is, !is, 7
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
854 // <, <= etc, 7
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
855 // in, 7
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
856 // <<, >>, >>>, 8
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
857 // +, -, ~, 9
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
858 // *, /, %, 10
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
859 // unary operators here
0cd8d6ab3f89 Add in the types for float and co.
Anders Halager <halager@gmail.com>
parents: 104
diff changeset
860
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
861 {Tok.Eq, 2, true, Operator.Eq},
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
862 {Tok.Ne, 2, true, Operator.Ne},
10
2f493057cf17 Some support for the rest of the boolean operators
Anders Halager <halager@gmail.com>
parents: 7
diff changeset
863
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
864 {Tok.Lt, 2, true, Operator.Lt},
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
865 {Tok.Le, 2, true, Operator.Le},
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
866 {Tok.Gt, 2, true, Operator.Gt},
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
867 {Tok.Ge, 2, true, Operator.Ge},
10
2f493057cf17 Some support for the rest of the boolean operators
Anders Halager <halager@gmail.com>
parents: 7
diff changeset
868
74
192da4976daa Renamed Add, Sub, Mul, Div and Mod in lexer to what they are (Plus, Minus....)
johnsen@johnsen-laptop
parents: 71
diff changeset
869 {Tok.Plus, 3, true, Operator.Add},
192da4976daa Renamed Add, Sub, Mul, Div and Mod in lexer to what they are (Plus, Minus....)
johnsen@johnsen-laptop
parents: 71
diff changeset
870 {Tok.Minus, 3, true, Operator.Sub},
44
495188f9078e Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents: 37
diff changeset
871
74
192da4976daa Renamed Add, Sub, Mul, Div and Mod in lexer to what they are (Plus, Minus....)
johnsen@johnsen-laptop
parents: 71
diff changeset
872 {Tok.Star, 5, true, Operator.Mul},
192da4976daa Renamed Add, Sub, Mul, Div and Mod in lexer to what they are (Plus, Minus....)
johnsen@johnsen-laptop
parents: 71
diff changeset
873 {Tok.Slash, 5, true, Operator.Div},
123
6a5f745d351c Parsing <<, >> and >>>.
Anders Johnsen <skabet@gmail.com>
parents: 116
diff changeset
874 {Tok.Percent, 5, true, Operator.Mod},
6a5f745d351c Parsing <<, >> and >>>.
Anders Johnsen <skabet@gmail.com>
parents: 116
diff changeset
875
6a5f745d351c Parsing <<, >> and >>>.
Anders Johnsen <skabet@gmail.com>
parents: 116
diff changeset
876 {Tok.LeftShift, 8, true, Operator.LeftShift},
6a5f745d351c Parsing <<, >> and >>>.
Anders Johnsen <skabet@gmail.com>
parents: 116
diff changeset
877 {Tok.RightShift, 8, true, Operator.RightShift},
6a5f745d351c Parsing <<, >> and >>>.
Anders Johnsen <skabet@gmail.com>
parents: 116
diff changeset
878 {Tok.UnsignedRightShift, 8, true, Operator.UnsignedRightShift}
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
879 ];
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
880 BinOp* binary(Tok t)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
881 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
882 foreach (ref op; _binary)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
883 if (op.tokenType == t)
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
884 return &op;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
885 return null;
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
886 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
887
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
888 private:
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
889
36
ce17bea8e9bd Switch statements support
Anders Halager <halager@gmail.com>
parents: 33
diff changeset
890 Token require(Tok t)
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
891 {
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
892 if (lexer.peek().type != t)
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
893 messages.report(UnexpectedTokSingle, lexer.peek.location)
29
41d23f2762c3 Merge, and updated Error class
Anders Halager <halager@gmail.com>
parents: 28
diff changeset
894 .arg(lexer.peek.getType)
89
a49bb982a7b0 Using the new SourceLocation system to handle errors. Also, this is the first push for making the errors don't throw, but continue to check the source.
Anders Johnsen <skabet@gmail.com>
parents: 88
diff changeset
895 .arg(t);
36
ce17bea8e9bd Switch statements support
Anders Halager <halager@gmail.com>
parents: 33
diff changeset
896 return lexer.next();
ce17bea8e9bd Switch statements support
Anders Halager <halager@gmail.com>
parents: 33
diff changeset
897 }
ce17bea8e9bd Switch statements support
Anders Halager <halager@gmail.com>
parents: 33
diff changeset
898
ce17bea8e9bd Switch statements support
Anders Halager <halager@gmail.com>
parents: 33
diff changeset
899 bool skip(Tok t)
ce17bea8e9bd Switch statements support
Anders Halager <halager@gmail.com>
parents: 33
diff changeset
900 {
ce17bea8e9bd Switch statements support
Anders Halager <halager@gmail.com>
parents: 33
diff changeset
901 if (lexer.peek().type != t)
ce17bea8e9bd Switch statements support
Anders Halager <halager@gmail.com>
parents: 33
diff changeset
902 return false;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
903 lexer.next();
36
ce17bea8e9bd Switch statements support
Anders Halager <halager@gmail.com>
parents: 33
diff changeset
904 return true;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
905 }
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
906
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
907 bool on_a(Tok t)
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
908 {
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
909 return lexer.peek.type == t;
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
910 }
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
911
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
912 Lexer lexer;
88
eb5b2c719a39 Major change to locations, tokens and expressions.
Anders Halager <halager@gmail.com>
parents: 84
diff changeset
913 SourceManager sm;
1
2168f4cb73f1 First push
johnsen@johnsen-desktop
parents:
diff changeset
914 }
99
857f0d530789 Imports and improved module statement
Anders Halager <halager@gmail.com>
parents: 94
diff changeset
915