bzr branch
http://gegoxaren.bato24.eu/bzr/lenasys/0.1
4.1.2
by c11emian
I have begun to fix the javascript so that it conforms to our codestandard. |
1 |
/*
|
2 |
* Token class and storage definition
|
|
3 |
*/
|
|
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
4 |
|
5 |
function token(kind, val, fromchar, tochar, row) { |
|
4.1.2
by c11emian
I have begun to fix the javascript so that it conforms to our codestandard. |
6 |
this.kind = kind; |
7 |
this.val = val; |
|
8 |
this.from = fromchar; |
|
9 |
this.to = tochar; |
|
10 |
this.row = row; |
|
11 |
}
|
|
12 |
||
13 |
// Array to hold the tokens
|
|
14 |
var tokens = []; |
|
15 |
/*
|
|
16 |
* Store token in tokens array
|
|
17 |
* Creates a new token object using the constructor
|
|
18 |
*/
|
|
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
19 |
|
4.2.9
by c11emian
Adjusted the file showcode.php so that it conforms to our code standard. |
20 |
function makeToken(kind, val, from, to, rowno) { |
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
21 |
newtoken = new token(kind, val, from, to, rowno); |
4.1.2
by c11emian
I have begun to fix the javascript so that it conforms to our codestandard. |
22 |
tokens.push(newtoken); |
23 |
}
|
|
24 |
||
25 |
/*
|
|
26 |
* Writes error from tokenizer
|
|
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
27 |
*/ |
28 |
|
|
29 |
function error(str, val, row) { |
|
30 |
alert("Tokenizer Error: " + str + val + " at row " + row); |
|
4.1.2
by c11emian
I have begun to fix the javascript so that it conforms to our codestandard. |
31 |
}
|
32 |
||
33 |
/*
|
|
34 |
* Tokenize function
|
|
35 |
* Tokenizer partly based on ideas from the very clever tokenizer written by Douglas Cockford
|
|
36 |
* The tokenizer is passed a string, and a string of prefix and suffix terminators
|
|
37 |
*/
|
|
38 |
|
|
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
39 |
function tokenize(instring, inprefix, insuffix) { |
4.1.2
by c11emian
I have begun to fix the javascript so that it conforms to our codestandard. |
40 |
// index of the start of the token. |
41 |
var from; |
|
42 |
// index of the current character. |
|
43 |
var i = 0; |
|
44 |
// length of the string |
|
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
45 |
var length = instring.length; |
4.1.2
by c11emian
I have begun to fix the javascript so that it conforms to our codestandard. |
46 |
// current character. |
47 |
var c; |
|
48 |
// current numerical value |
|
49 |
var n; |
|
50 |
// current quote character |
|
51 |
var q; |
|
52 |
// current string value. |
|
53 |
var str; |
|
54 |
// current row value |
|
55 |
var row=1; |
|
56 |
c = instring.charAt(i); |
|
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
57 |
while(c) { |
4.1.2
by c11emian
I have begun to fix the javascript so that it conforms to our codestandard. |
58 |
from = i; |
59 |
// White space |
|
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
60 |
if(c <= ' ') { |
4.1.2
by c11emian
I have begun to fix the javascript so that it conforms to our codestandard. |
61 |
// Add row if this white space is a row terminator |
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
62 |
if((c == '\n') || (c == '\r') || (c == '')) { |
4.1.2
by c11emian
I have begun to fix the javascript so that it conforms to our codestandard. |
63 |
row++; |
64 |
} |
|
65 |
i++; |
|
66 |
c = instring.charAt(i); |
|
67 |
// Names i.e. Text |
|
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
68 |
} else if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { |
4.1.2
by c11emian
I have begun to fix the javascript so that it conforms to our codestandard. |
69 |
str = c; |
70 |
i++; |
|
71 |
for(;;) { |
|
72 |
c = instring.charAt(i); |
|
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
73 |
if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')|| (c == '_')) { |
4.1.2
by c11emian
I have begun to fix the javascript so that it conforms to our codestandard. |
74 |
str += c; |
75 |
i++; |
|
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
76 |
} else { |
4.1.2
by c11emian
I have begun to fix the javascript so that it conforms to our codestandard. |
77 |
break; |
78 |
} |
|
79 |
} |
|
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
80 |
maketoken('name', str, from, i, row); |
4.1.2
by c11emian
I have begun to fix the javascript so that it conforms to our codestandard. |
81 |
// Number token |
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
82 |
} else if (c >= '0' && c <= '9') { |
4.1.2
by c11emian
I have begun to fix the javascript so that it conforms to our codestandard. |
83 |
str = c; |
84 |
i++; |
|
85 |
for(;;) { |
|
86 |
c = instring.charAt(i); |
|
87 |
if(c < '0' || c > '9') { |
|
88 |
break; |
|
89 |
} |
|
90 |
i++; |
|
91 |
str += c; |
|
92 |
} |
|
93 |
if(c == '.') { |
|
94 |
i++; |
|
95 |
str += c; |
|
96 |
for(;;){ |
|
97 |
c=instring.charAt(i); |
|
98 |
if(c < '0' || c > '9'){ |
|
99 |
break; |
|
100 |
} |
|
101 |
i++; |
|
102 |
str += c; |
|
103 |
} |
|
104 |
} |
|
105 |
if(c == 'e' || c =='E') { |
|
106 |
i++; |
|
107 |
str += c; |
|
108 |
c=instring.charAt(i); |
|
109 |
if(c == '-' || c == '+') { |
|
110 |
i++; |
|
111 |
str += c; |
|
112 |
c=instring.charAt(i); |
|
113 |
} |
|
114 |
if(c < '0' || c > '9') { |
|
115 |
error('Bad Exponent in Number: ',str,row); |
|
116 |
} |
|
117 |
do { |
|
118 |
i++; |
|
119 |
str += c; |
|
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
120 |
c = instring.charAt(i); |
121 |
} while(c >= '0' && c <= '9'); |
|
4.1.1
by c11emian
Added <head> and <title> tags |
122 |
} |
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
123 |
if(c >= 'a' && c <= 'z') { |
4.1.1
by c11emian
Added <head> and <title> tags |
124 |
str += c; |
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
125 |
i++; |
126 |
error('Bad Number: ',str,row); |
|
127 |
} |
|
128 |
n =+ str; |
|
129 |
if(isFinite(n)) { |
|
130 |
maketoken('number', n, from, i, row); |
|
131 |
} else { |
|
132 |
error('Bad Number: ', str, row); |
|
133 |
} |
|
4.2.9
by c11emian
Adjusted the file showcode.php so that it conforms to our code standard. |
134 |
// String .. handles c style breaking codes |
135 |
} else if (c == '\'' || c == '"') { |
|
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
136 |
str = ''; |
137 |
q = c; |
|
4.1.1
by c11emian
Added <head> and <title> tags |
138 |
i++; |
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
139 |
for(;;) { |
140 |
c = instring.charAt(i); |
|
141 |
if(c < ' ') { |
|
142 |
if((c == '\n') || (c == '\r') || (c == '')) { |
|
143 |
// Add row if this white space is a row terminator |
|
144 |
row++; |
|
145 |
} else { |
|
146 |
error('Unterminated String: ', str, row); |
|
147 |
} |
|
4.1.1
by c11emian
Added <head> and <title> tags |
148 |
} |
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
149 |
if (c == q) { |
150 |
break; |
|
151 |
} |
|
152 |
if(c == '\\') { |
|
153 |
i++; |
|
154 |
if(i >= length) { |
|
155 |
error('Unterminated String: ', str, row); |
|
4.1.1
by c11emian
Added <head> and <title> tags |
156 |
} |
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
157 |
c = instring.charAt(i); |
158 |
if(c == 'b') { |
|
159 |
c = '\b'; |
|
160 |
break; |
|
161 |
} |
|
162 |
if(c == 'f') { |
|
163 |
c = '\f'; |
|
164 |
break; |
|
165 |
} |
|
166 |
if(c == 'n') { |
|
167 |
c = '\n'; |
|
168 |
break; |
|
169 |
} |
|
170 |
if(c == 'r') { |
|
171 |
c = '\r'; |
|
172 |
break; |
|
173 |
} |
|
174 |
if(c == 't') { |
|
175 |
c = '\t'; |
|
176 |
break; |
|
177 |
} |
|
178 |
if(c == 'u') { |
|
179 |
if(i >= length) { |
|
180 |
error('Unterminated String: ', str, row); |
|
4.1.1
by c11emian
Added <head> and <title> tags |
181 |
} |
182 |
c = parseInt(this.substr(i + 1, 4), 16); |
|
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
183 |
if(!isFinite(c) || c < 0) { |
184 |
error('Unterminated String: ', str, row); |
|
4.1.1
by c11emian
Added <head> and <title> tags |
185 |
} |
186 |
c = String.fromCharCode(c); |
|
187 |
i+=4; |
|
188 |
break; |
|
189 |
} |
|
190 |
} |
|
191 |
str += c; |
|
192 |
i++; |
|
193 |
} |
|
194 |
i++; |
|
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
195 |
maketoken('string', str, from, i, row); |
196 |
c = instring.charAt(i); |
|
197 |
// Comment of // type ... does not cover block comments |
|
198 |
} else if (c == '/' && instring.charAt(i+1) == '/') { |
|
4.1.1
by c11emian
Added <head> and <title> tags |
199 |
i++; |
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
200 |
for(;;) { |
201 |
c=instring.charAt(i); |
|
202 |
if(c == '\n' || c == '\r' || c == '') { |
|
4.1.1
by c11emian
Added <head> and <title> tags |
203 |
row++; |
204 |
break; |
|
205 |
} |
|
206 |
i++; |
|
207 |
} |
|
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
208 |
// Block comment of /* type |
209 |
} else if (c == '/' && instring.charAt(i+1) == '*') { |
|
4.1.1
by c11emian
Added <head> and <title> tags |
210 |
i++; |
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
211 |
for(;;) { |
212 |
c=instring.charAt(i); |
|
213 |
if((c == '*' && instring.charAt(i+1) == '/') || (i == length)) { |
|
4.1.1
by c11emian
Added <head> and <title> tags |
214 |
i+=2; |
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
215 |
c=instring.charAt(i); |
4.1.1
by c11emian
Added <head> and <title> tags |
216 |
break; |
217 |
} |
|
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
218 |
if(c == '\n' || c == '\r' || c == '') { |
4.1.1
by c11emian
Added <head> and <title> tags |
219 |
row++; |
220 |
} |
|
221 |
i++; |
|
222 |
} |
|
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
223 |
// Multi-character Operators |
224 |
} else if (inprefix.indexOf(c) >= 0) { |
|
4.1.1
by c11emian
Added <head> and <title> tags |
225 |
str = c; |
226 |
i++; |
|
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
227 |
while(true) { |
228 |
c=instring.charAt(i); |
|
229 |
if(i >= length || insuffix.indexOf(c) < 0) { |
|
4.1.1
by c11emian
Added <head> and <title> tags |
230 |
break; |
231 |
} |
|
232 |
str += c; |
|
233 |
i++; |
|
234 |
} |
|
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
235 |
// Single-character Operators |
236 |
maketoken('operator', str, from, i, row); |
|
237 |
} else { |
|
4.1.1
by c11emian
Added <head> and <title> tags |
238 |
i++; |
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
239 |
maketoken('operator', c, from, i, row); |
4.1.1
by c11emian
Added <head> and <title> tags |
240 |
c = instring.charAt(i); |
241 |
} |
|
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
242 |
} |
4.1.1
by c11emian
Added <head> and <title> tags |
243 |
} |
4.2.9
by c11emian
Adjusted the file showcode.php so that it conforms to our code standard. |
244 |
function newButton() |
4.1.1
by c11emian
Added <head> and <title> tags |
245 |
{ |
4.1.3
by c11emian
Fixed the indentation in Parser_Test.js |
246 |
var funclist; |
247 |
var oplist; |
|
248 |
oplist = document.getElementById('infobox'); |
|
249 |
string_tokenize = "foo // Lederhosen\nsin'foo'(200.0*r)+(-21.4/1.51e-6)+/*Plodder*/(Feeeb+400)*ln(3000);\ncos(200.1-atan2(41.0,51.0));\nHello+85-4*2.6-1.51e-6;"; |
|
250 |
tokenize(string_tokenize, "<>+-&","=>&:"); |
|
251 |
// Iterate over token objects and print kind of each token and token type in window |
|
252 |
printout = document.getElementById('infobox'); |
|
253 |
for(i = 0;i < tokens.length;i++) { |
|
254 |
printout.innerHTML += tokens[i].kind + " " + tokens[i].val + " (" + tokens[i].from + "-" + tokens[i].to + ") at: " + tokens[i].row + "<br>"; |
|
255 |
} |
|
4.1.1
by c11emian
Added <head> and <title> tags |
256 |
} |