summaryrefslogtreecommitdiffstats
path: root/kturtle/src/token.h
blob: 2c0e76223ddea32fee3664c927cda13a79bdcef4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
    Copyright (C) 2003 by Walter Schreppers 
    Copyright (C) 2004 by Cies Breijs   
     
    This program is free software; you can redistribute it and/or
    modify it under the terms of version 2 of the GNU General Public
    License as published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

    
#ifndef _TOKEN_H_
#define _TOKEN_H_

#include <qstring.h>

#include "value.h"


struct Pos // convenience, it codes a bit nicer with this, i.e.: "int row = tok.start.row"
{
	uint     row;
	uint     col;
};

struct Token
{
	int      type;  // filled with enumed tokenTypes
	QString  look;  // the way the token looks in the text editor
	Value    value; // if the token is a number it can be stored here
	Pos      start; // row'n'col of the starting/ending point of the token
	Pos      end;
};


enum tokenTypes
{
	tokNotSet  = 0, // inittial type of all tokens
	tokError   = 1,  // when there is an error
	tokUnknown = 2,  // when no token was found, a tokUnknown is often a variable, function or error
	
	tokIf, // the execution controlling tokens
	tokElse,
	tokWhile,
	tokFor,
	tokTo,
	tokStep,
	tokForEach,
	tokIn,
	tokBreak,
	tokReturn,

	tokBegin, // the scope delimiting tokens
	tokEnd,

	tokNumber, // the containers
	tokString,

	tokAssign, // for assignments
	
	tokAnd, // and, or, not
	tokOr,
	tokNot,
	
	tokEq, // ==, !=, >=, >, <=, <
	tokNe,
	tokGe,
	tokGt,
	tokLe,
	tokLt,
	
	tokBraceOpen, // (, ), +, -, *, /
	tokBraceClose,
	tokPlus,
	tokMinus,
	tokMul,
	tokDev,
	
	tokComma,
	
	tokEOL, // End Of Line token
	tokEOF, // End Of File token

	tokLearn, // learn command
	
	tokClear, // the 'regular' command tokens
	tokGo,
	tokGoX,
	tokGoY,
	tokForward,
	tokBackward,
	tokDirection,
	tokTurnLeft,
	tokTurnRight,
	tokCenter,
	tokSetPenWidth,
	tokPenUp,
	tokPenDown,
	tokSetFgColor,
	tokSetBgColor,
	tokResizeCanvas,
	tokSpriteShow,
	tokSpriteHide,
	tokSpritePress,
	tokSpriteChange,
	tokMessage,
	tokInputWindow,
	tokPrint,
	tokFontType,
	tokFontSize,
	tokRepeat,
	tokRandom,
	tokWait,
	tokWrapOn,
	tokWrapOff,
	tokReset,
	tokRun,

	tokDo // a dummy command
};

// const QString tokenTypeNames[] =
// {
// 	/* tokNotSet  = 0 */   "",
// 	/* tokError   = 1 */   "",
// 	/* tokUnknown = 2 */   "name",
// 
// 	/* tokIf */            "if",
// 	/* tokElse */          "else",
// 	/* tokWhile */         "while",
// 	/* tokFor */           "for",
// 	/* tokTo */            "to",
// 	/* tokStep */          "step",
// 	/* tokForEach */       "each",
// 	/* tokIn */            "in",
// 	/* tokBreak */         "break",
// 	/* tokReturn */        "return",
// 	
// 	/* tokBegin */         "",
// 	/* tokEnd */           "",
// 	
// 	/* tokNumber */        "number",
// 	/* tokString */        "string",
// 	
// 	/* tokAssign */        "asignment",
// 
// 	/* tokAnd */           "and",
// 	/* tokOr */            "or",
// 	/* tokNot */           "not",
// 
// 	/* tokEq */            "questions",
// 	/* tokNe */            "questions",
// 	/* tokGe */            "questions",
// 	/* tokGt */            "questions",
// 	/* tokLe */            "questions",
// 	/* tokLt */            "questions",
// 
// 	/* tokBraceOpen */     "math",
// 	/* tokBraceClose */    "math",
// 	/* tokPlus */          "math",
// 	/* tokMinus */         "math",
// 	/* tokMul */           "math",
// 	/* tokDev */           "math",
// 
// 	/* tokComma */         "",
// 
// 	/* tokEOL */           "",
// 	/* tokEOF */           "",
// 
// 	/* tokLearn */         "learn",
// 
// 	/* tokClear */         "clear",
// 	/* tokGo */            "go",
// 	/* tokGoX */           "gox",
// 	/* tokGoY */           "goy",
// 	/* tokForward */       "forward",
// 	/* tokBackward */      "backward",
// 	/* tokDirection */     "direction",
// 	/* tokTurnLeft */      "turnleft",
// 	/* tokTurnRight */     "turnright",
// 	/* tokCenter */        "center",
// 	/* tokSetPenWidth */   "setpenwidth",
// 	/* tokPenUp */         "penup",
// 	/* tokPenDown */       "pendown",
// 	/* tokSetFgColor */    "setfgcolor",
// 	/* tokSetBgColor */    "setbgcolor",
// 	/* tokResizeCanvas */  "resizecanvas",
// 	/* tokSpriteShow */    "spriteshow",
// 	/* tokSpriteHide */    "spritehide",
// 	/* tokSpritePress */   "",
// 	/* tokSpriteChange */  "",
// 	/* tokMessage */       "message",
// 	/* tokInputWindow */   "inputwindow",
// 	/* tokPrint */         "print",
// 	/* tokFontType */      "",
// 	/* tokFontSize */      "fontsize",
// 	/* tokRepeat */        "repeat",
// 	/* tokRandom */        "random",
// 	/* tokWait */          "wait",
// 	/* tokWrapOn */        "wrapon",
// 	/* tokWrapOff */       "wrapoff",
// 	/* tokReset */         "reset",
// 	/* tokRun */           "run",
// 	
// 	/* tokDo */            "",
// };
// 
// // QString Token::tokenType2name(int tokenType)
// // {
// // 	if (tokenType >= 0) return tokenTypeNames[tokenType];
// // 	else                return "";
// // }

#endif // _TOKEN_H_