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 | T_INTEGER = 1001
|
47 | T_DOUBLE = 1002
|
48 | T_SYMBOL = 1003
|
49 | T_FUNCTION = 1004
|
50 | T_NEWLINE = 1006
|
51 | T_STRING = 1007
|
52 | T_GTEQ = 1008
|
53 | T_LTEQ = 1009
|
54 | T_EQ = 1010
|
55 | T_NEQ = 1011
|
56 | T_QUOTASSIGN = 1012
|
57 |
|
58 | token = ""
|
59 | newline_flag = 0
|
60 | meta_mode = 0
|
61 |
|
62 | input_str = 0
|
63 | scan_str = 0
|
64 | token_str = 0
|
65 | token_buf = 0
|
66 |
|
67 | lastFoundSymbol = null
|
68 | symbolsRightOfAssignment = null
|
69 | symbolsLeftOfAssignment = null
|
70 | isSymbolLeftOfAssignment = null
|
71 | scanningParameters = null
|
72 | functionInvokationsScanningStack = null
|
73 | skipRootVariableToBeSolved = false
|
74 | assignmentFound = null
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 | scanned = ""
|
84 | scan = (s) ->
|
85 | if DEBUG then console.log "#### scanning " + s
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | lastFoundSymbol = null
|
94 | symbolsRightOfAssignment = []
|
95 | symbolsLeftOfAssignment = []
|
96 | isSymbolLeftOfAssignment = true
|
97 | scanningParameters = []
|
98 | functionInvokationsScanningStack = [""]
|
99 | assignmentFound = false
|
100 |
|
101 |
|
102 | scanned = s
|
103 | meta_mode = 0
|
104 | expanding++
|
105 | input_str = 0
|
106 | scan_str = 0
|
107 | get_next_token()
|
108 | if (token == "")
|
109 | push(symbol(NIL))
|
110 | expanding--
|
111 | return 0
|
112 | scan_stmt()
|
113 | expanding--
|
114 |
|
115 | if !assignmentFound
|
116 | symbolsInExpressionsWithoutAssignments = symbolsInExpressionsWithoutAssignments.concat symbolsLeftOfAssignment
|
117 |
|
118 | return token_str - input_str
|
119 |
|
120 |
|
121 | scan_meta = (s) ->
|
122 | scanned = s
|
123 | meta_mode = 1
|
124 | expanding++
|
125 | input_str = 0
|
126 | scan_str = 0
|
127 | get_next_token()
|
128 | if (token == "")
|
129 | push(symbol(NIL))
|
130 | expanding--
|
131 | return 0
|
132 | scan_stmt()
|
133 | expanding--
|
134 | return token_str - input_str
|
135 |
|
136 | scan_stmt = ->
|
137 | scan_relation()
|
138 |
|
139 | assignmentIsOfQuotedType = false
|
140 |
|
141 | if token == T_QUOTASSIGN
|
142 | assignmentIsOfQuotedType = true
|
143 |
|
144 | if (token == T_QUOTASSIGN or token == '=')
|
145 | symbolLeftOfAssignment = lastFoundSymbol
|
146 | if DEBUG then console.log("assignment!")
|
147 | assignmentFound = true
|
148 | isSymbolLeftOfAssignment = false
|
149 |
|
150 | get_next_token()
|
151 | push_symbol(SETQ)
|
152 | swap()
|
153 |
|
154 |
|
155 | if (assignmentIsOfQuotedType)
|
156 | push_symbol(QUOTE)
|
157 |
|
158 | scan_relation()
|
159 |
|
160 |
|
161 |
|
162 | if assignmentIsOfQuotedType
|
163 | list(2)
|
164 |
|
165 | list(3)
|
166 |
|
167 | isSymbolLeftOfAssignment = true
|
168 |
|
169 | if codeGen
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 | indexOfSymbolLeftOfAssignment = symbolsRightOfAssignment.indexOf(symbolLeftOfAssignment)
|
176 | if indexOfSymbolLeftOfAssignment != -1
|
177 | symbolsRightOfAssignment.splice(indexOfSymbolLeftOfAssignment, 1)
|
178 | symbolsHavingReassignments.push symbolLeftOfAssignment
|
179 |
|
180 |
|
181 | if DEBUG
|
182 | console.log "locally, " + symbolLeftOfAssignment + " depends on: "
|
183 | for i in symbolsRightOfAssignment
|
184 | console.log " " + i
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 | symbolsDependencies[symbolLeftOfAssignment] ?= []
|
191 | existingDependencies = symbolsDependencies[symbolLeftOfAssignment]
|
192 |
|
193 |
|
194 |
|
195 | for i in symbolsRightOfAssignment
|
196 | if existingDependencies.indexOf(i) == -1
|
197 | existingDependencies.push i
|
198 |
|
199 | symbolsRightOfAssignment = []
|
200 |
|
201 | scan_relation = ->
|
202 | scan_expression()
|
203 | switch (token)
|
204 | when T_EQ
|
205 | push_symbol(TESTEQ)
|
206 | swap()
|
207 | get_next_token()
|
208 | scan_expression()
|
209 | list(3)
|
210 | when T_NEQ
|
211 | push_symbol(NOT)
|
212 | swap()
|
213 | push_symbol(TESTEQ)
|
214 | swap()
|
215 | get_next_token()
|
216 | scan_expression()
|
217 | list(3)
|
218 | list(2)
|
219 | when T_LTEQ
|
220 | push_symbol(TESTLE)
|
221 | swap()
|
222 | get_next_token()
|
223 | scan_expression()
|
224 | list(3)
|
225 | when T_GTEQ
|
226 | push_symbol(TESTGE)
|
227 | swap()
|
228 | get_next_token()
|
229 | scan_expression()
|
230 | list(3)
|
231 | when '<'
|
232 | push_symbol(TESTLT)
|
233 | swap()
|
234 | get_next_token()
|
235 | scan_expression()
|
236 | list(3)
|
237 | when '>'
|
238 | push_symbol(TESTGT)
|
239 | swap()
|
240 | get_next_token()
|
241 | scan_expression()
|
242 | list(3)
|
243 |
|
244 | scan_expression = ->
|
245 | h = tos
|
246 | switch token
|
247 | when '+'
|
248 | get_next_token()
|
249 | scan_term()
|
250 | when '-'
|
251 | get_next_token()
|
252 | scan_term()
|
253 | negate()
|
254 | else
|
255 | scan_term()
|
256 |
|
257 | while (newline_flag == 0 && (token == '+' || token == '-'))
|
258 | if (token == '+')
|
259 | get_next_token()
|
260 | scan_term()
|
261 | else
|
262 | get_next_token()
|
263 | scan_term()
|
264 | negate()
|
265 |
|
266 | if (tos - h > 1)
|
267 | list(tos - h)
|
268 | push_symbol(ADD)
|
269 | swap()
|
270 | cons()
|
271 |
|
272 | is_factor = ->
|
273 |
|
274 | if token.charCodeAt?(0) == dotprod_unicode
|
275 | return 1
|
276 |
|
277 | switch (token)
|
278 | when '*', '/'
|
279 | return 1
|
280 | when '(', T_SYMBOL, T_FUNCTION, T_INTEGER, T_DOUBLE, T_STRING
|
281 | if (newline_flag)
|
282 | scan_str = token_str
|
283 | return 0
|
284 | else
|
285 | return 1
|
286 | return 0
|
287 |
|
288 |
|
289 | simplify_1_in_products = (tos,h) ->
|
290 | if (tos > h && isrational(stack[tos - 1]) && equaln(stack[tos - 1], 1))
|
291 | pop()
|
292 |
|
293 |
|
294 | multiply_consecutive_constants = (tos,h)->
|
295 | if (tos > h + 1 && isnum(stack[tos - 2]) && isnum(stack[tos - 1]))
|
296 | multiply()
|
297 |
|
298 |
|
299 | scan_term = ->
|
300 | h = tos
|
301 |
|
302 | scan_factor()
|
303 |
|
304 | if parse_time_simplifications
|
305 | simplify_1_in_products(tos,h)
|
306 |
|
307 | while (is_factor())
|
308 | if (token == '*')
|
309 | get_next_token()
|
310 | scan_factor()
|
311 | else if (token == '/')
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 | simplify_1_in_products(tos,h)
|
319 | get_next_token()
|
320 | scan_factor()
|
321 | inverse()
|
322 | else if (token.charCodeAt?(0) == dotprod_unicode)
|
323 | get_next_token()
|
324 | push_symbol(INNER)
|
325 | swap()
|
326 | scan_factor()
|
327 | list(3)
|
328 |
|
329 | else
|
330 | scan_factor()
|
331 |
|
332 | if parse_time_simplifications
|
333 | multiply_consecutive_constants(tos,h)
|
334 | simplify_1_in_products(tos,h)
|
335 |
|
336 | if (h == tos)
|
337 | push_integer(1)
|
338 | else if (tos - h > 1)
|
339 | list(tos - h)
|
340 | push_symbol(MULTIPLY)
|
341 | swap()
|
342 | cons()
|
343 |
|
344 | scan_power = ->
|
345 | if (token == '^')
|
346 | get_next_token()
|
347 | push_symbol(POWER)
|
348 | swap()
|
349 | scan_factor()
|
350 | list(3)
|
351 |
|
352 | scan_index = (h) ->
|
353 |
|
354 | get_next_token()
|
355 | push_symbol(INDEX)
|
356 | swap()
|
357 | scan_expression()
|
358 | while (token == ',')
|
359 | get_next_token()
|
360 | scan_expression()
|
361 | if (token != ']')
|
362 | scan_error("] expected")
|
363 | get_next_token()
|
364 | list(tos - h)
|
365 |
|
366 |
|
367 | scan_factor = ->
|
368 |
|
369 | h = tos
|
370 |
|
371 |
|
372 |
|
373 | if (token == '(')
|
374 | scan_subexpr()
|
375 | else if (token == T_SYMBOL)
|
376 | scan_symbol()
|
377 | else if (token == T_FUNCTION)
|
378 | scan_function_call_with_function_name()
|
379 | else if token == '['
|
380 |
|
381 |
|
382 | scan_tensor()
|
383 | else if (token == T_INTEGER)
|
384 | bignum_scan_integer(token_buf)
|
385 | get_next_token()
|
386 | else if (token == T_DOUBLE)
|
387 | bignum_scan_float(token_buf)
|
388 | get_next_token()
|
389 | else if (token == T_STRING)
|
390 | scan_string()
|
391 | else
|
392 | scan_error("syntax error")
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 | while token == '[' or token == '(' and newline_flag == 0
|
406 | if token == '['
|
407 | scan_index(h)
|
408 | else if token == '('
|
409 |
|
410 | scan_function_call_without_function_name()
|
411 |
|
412 |
|
413 |
|
414 | while (token == '!')
|
415 | get_next_token()
|
416 | push_symbol(FACTORIAL)
|
417 | swap()
|
418 | list(2)
|
419 |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 |
|
425 | while (token.charCodeAt?(0) == transpose_unicode)
|
426 | get_next_token()
|
427 | push_symbol(TRANSPOSE)
|
428 | swap()
|
429 | list(2)
|
430 |
|
431 | scan_power()
|
432 |
|
433 |
|
434 | addSymbolRightOfAssignment = (theSymbol) ->
|
435 | if predefinedSymbolsInGlobalScope_doNotTrackInDependencies.indexOf(theSymbol) == -1 and
|
436 | symbolsRightOfAssignment.indexOf(theSymbol) == -1 and
|
437 | symbolsRightOfAssignment.indexOf("'"+theSymbol) == -1 and
|
438 | !skipRootVariableToBeSolved
|
439 | if DEBUG then console.log("... adding symbol: " + theSymbol + " to the set of the symbols right of assignment")
|
440 | prefixVar = ""
|
441 | for i in [1...functionInvokationsScanningStack.length]
|
442 | if functionInvokationsScanningStack[i] != ""
|
443 | prefixVar += functionInvokationsScanningStack[i] + "_" + i + "_"
|
444 |
|
445 | theSymbol = prefixVar + theSymbol
|
446 | symbolsRightOfAssignment.push theSymbol
|
447 |
|
448 | addSymbolLeftOfAssignment = (theSymbol) ->
|
449 | if predefinedSymbolsInGlobalScope_doNotTrackInDependencies.indexOf(theSymbol) == -1 and
|
450 | symbolsLeftOfAssignment.indexOf(theSymbol) == -1 and
|
451 | symbolsLeftOfAssignment.indexOf("'"+theSymbol) == -1 and
|
452 | !skipRootVariableToBeSolved
|
453 | if DEBUG then console.log("... adding symbol: " + theSymbol + " to the set of the symbols left of assignment")
|
454 | prefixVar = ""
|
455 | for i in [1...functionInvokationsScanningStack.length]
|
456 | if functionInvokationsScanningStack[i] != ""
|
457 | prefixVar += functionInvokationsScanningStack[i] + "_" + i + "_"
|
458 |
|
459 | theSymbol = prefixVar + theSymbol
|
460 | symbolsLeftOfAssignment.push theSymbol
|
461 |
|
462 | scan_symbol = ->
|
463 | if (token != T_SYMBOL)
|
464 | scan_error("symbol expected")
|
465 | if (meta_mode && token_buf.length == 1)
|
466 | switch (token_buf[0])
|
467 | when 'a'
|
468 | push(symbol(METAA))
|
469 | when 'b'
|
470 | push(symbol(METAB))
|
471 | when 'x'
|
472 | push(symbol(METAX))
|
473 | else
|
474 | push(usr_symbol(token_buf))
|
475 | else
|
476 | push(usr_symbol(token_buf))
|
477 |
|
478 |
|
479 | if scanningParameters.length == 0
|
480 | if DEBUG then console.log "out of scanning parameters, processing " + token_buf
|
481 | lastFoundSymbol = token_buf
|
482 | if isSymbolLeftOfAssignment
|
483 | addSymbolLeftOfAssignment token_buf
|
484 | else
|
485 | if DEBUG then console.log "still scanning parameters, skipping " + token_buf
|
486 | if isSymbolLeftOfAssignment
|
487 | addSymbolRightOfAssignment "'" + token_buf
|
488 |
|
489 | if DEBUG then console.log("found symbol: " + token_buf + " left of assignment: " + isSymbolLeftOfAssignment)
|
490 |
|
491 |
|
492 |
|
493 |
|
494 | if !isSymbolLeftOfAssignment
|
495 | addSymbolRightOfAssignment token_buf
|
496 | get_next_token()
|
497 |
|
498 | scan_string = ->
|
499 | new_string(token_buf)
|
500 | get_next_token()
|
501 |
|
502 | scan_function_call_with_function_name = ->
|
503 | if DEBUG then console.log "-- scan_function_call_with_function_name start"
|
504 | n = 1
|
505 | p = new U()
|
506 | p = usr_symbol(token_buf)
|
507 |
|
508 | push(p)
|
509 | get_next_token()
|
510 | functionName = token_buf
|
511 | if functionName == "roots" or functionName == "defint" or functionName == "sum" or functionName == "product" or functionName == "for"
|
512 | functionInvokationsScanningStack.push token_buf
|
513 | lastFoundSymbol = token_buf
|
514 | if !isSymbolLeftOfAssignment
|
515 | addSymbolRightOfAssignment token_buf
|
516 |
|
517 | get_next_token()
|
518 | scanningParameters.push true
|
519 | if (token != ')')
|
520 | scan_stmt()
|
521 | n++
|
522 | while (token == ',')
|
523 | get_next_token()
|
524 |
|
525 | if n == 2 and functionInvokationsScanningStack[functionInvokationsScanningStack.length - 1].indexOf("roots") != -1
|
526 | symbolsRightOfAssignment = symbolsRightOfAssignment.filter (x) -> !(new RegExp("roots_" + (functionInvokationsScanningStack.length - 1) + "_" + token_buf)).test(x)
|
527 | skipRootVariableToBeSolved = true
|
528 |
|
529 | if n == 2 and functionInvokationsScanningStack[functionInvokationsScanningStack.length - 1].indexOf("sum") != -1
|
530 | symbolsRightOfAssignment = symbolsRightOfAssignment.filter (x) -> !(new RegExp("sum_" + (functionInvokationsScanningStack.length - 1) + "_" + token_buf)).test(x)
|
531 | skipRootVariableToBeSolved = true
|
532 |
|
533 | if n == 2 and functionInvokationsScanningStack[functionInvokationsScanningStack.length - 1].indexOf("product") != -1
|
534 | symbolsRightOfAssignment = symbolsRightOfAssignment.filter (x) -> !(new RegExp("product_" + (functionInvokationsScanningStack.length - 1) + "_" + token_buf)).test(x)
|
535 | skipRootVariableToBeSolved = true
|
536 |
|
537 | if n == 2 and functionInvokationsScanningStack[functionInvokationsScanningStack.length - 1].indexOf("for") != -1
|
538 | symbolsRightOfAssignment = symbolsRightOfAssignment.filter (x) -> !(new RegExp("for_" + (functionInvokationsScanningStack.length - 1) + "_" + token_buf)).test(x)
|
539 | skipRootVariableToBeSolved = true
|
540 |
|
541 | if functionInvokationsScanningStack[functionInvokationsScanningStack.length - 1].indexOf("defint") != -1 and
|
542 | (n == 2 or (n>2 and ((n-2) % 3 == 0)))
|
543 | symbolsRightOfAssignment = symbolsRightOfAssignment.filter (x) -> !(new RegExp("defint_" + (functionInvokationsScanningStack.length - 1) + "_" + token_buf)).test(x)
|
544 | skipRootVariableToBeSolved = true
|
545 |
|
546 | scan_stmt()
|
547 | skipRootVariableToBeSolved = false
|
548 | n++
|
549 |
|
550 |
|
551 |
|
552 | if n == 2 and functionInvokationsScanningStack[functionInvokationsScanningStack.length - 1].indexOf("roots") != -1
|
553 | symbolsRightOfAssignment = symbolsRightOfAssignment.filter (x) -> !(new RegExp("roots_" + (functionInvokationsScanningStack.length - 1) + "_" + "x")).test(x)
|
554 |
|
555 | scanningParameters.pop()
|
556 |
|
557 | for i in [0..symbolsRightOfAssignment.length]
|
558 | if symbolsRightOfAssignment[i]?
|
559 | if functionName == "roots"
|
560 | symbolsRightOfAssignment[i] = symbolsRightOfAssignment[i].replace(new RegExp("roots_" + (functionInvokationsScanningStack.length - 1) + "_"),"")
|
561 | if functionName == "defint"
|
562 | symbolsRightOfAssignment[i] = symbolsRightOfAssignment[i].replace(new RegExp("defint_" + (functionInvokationsScanningStack.length - 1) + "_"),"")
|
563 | if functionName == "sum"
|
564 | symbolsRightOfAssignment[i] = symbolsRightOfAssignment[i].replace(new RegExp("sum_" + (functionInvokationsScanningStack.length - 1) + "_"),"")
|
565 | if functionName == "product"
|
566 | symbolsRightOfAssignment[i] = symbolsRightOfAssignment[i].replace(new RegExp("product_" + (functionInvokationsScanningStack.length - 1) + "_"),"")
|
567 | if functionName == "for"
|
568 | symbolsRightOfAssignment[i] = symbolsRightOfAssignment[i].replace(new RegExp("for_" + (functionInvokationsScanningStack.length - 1) + "_"),"")
|
569 |
|
570 | if (token != ')')
|
571 | scan_error(") expected")
|
572 |
|
573 | get_next_token()
|
574 | list(n)
|
575 | if functionName == "roots" or functionName == "defint" or functionName == "sum" or functionName == "product" or functionName == "for"
|
576 | functionInvokationsScanningStack.pop()
|
577 | if functionName == symbol(PATTERN).printname
|
578 | patternHasBeenFound = true
|
579 |
|
580 | if DEBUG then console.log "-- scan_function_call_with_function_name end"
|
581 |
|
582 | scan_function_call_without_function_name = ->
|
583 | if DEBUG then console.log "-- scan_function_call_without_function_name start"
|
584 |
|
585 |
|
586 |
|
587 | push_symbol(EVAL)
|
588 | swap()
|
589 | list(2)
|
590 |
|
591 | n = 1
|
592 | get_next_token()
|
593 | scanningParameters.push true
|
594 | if (token != ')')
|
595 | scan_stmt()
|
596 | n++
|
597 | while (token == ',')
|
598 | get_next_token()
|
599 | scan_stmt()
|
600 | n++
|
601 |
|
602 | scanningParameters.pop()
|
603 |
|
604 |
|
605 | if (token != ')')
|
606 | scan_error(") expected")
|
607 |
|
608 | get_next_token()
|
609 | list(n)
|
610 |
|
611 | if DEBUG then console.log "-- scan_function_call_without_function_name end: " + stack[tos-1]
|
612 |
|
613 |
|
614 |
|
615 | scan_subexpr = ->
|
616 | n = 0
|
617 | if (token != '(')
|
618 | scan_error("( expected")
|
619 | get_next_token()
|
620 | scan_stmt()
|
621 | if (token != ')')
|
622 | scan_error(") expected")
|
623 | get_next_token()
|
624 |
|
625 | scan_tensor = ->
|
626 | n = 0
|
627 | if (token != '[')
|
628 | scan_error("[ expected")
|
629 |
|
630 | get_next_token()
|
631 |
|
632 |
|
633 | scan_stmt()
|
634 |
|
635 | n = 1
|
636 | while (token == ',')
|
637 | get_next_token()
|
638 | scan_stmt()
|
639 | n++
|
640 |
|
641 |
|
642 | build_tensor(n)
|
643 |
|
644 | if (token != ']')
|
645 | scan_error("] expected")
|
646 | get_next_token()
|
647 |
|
648 | scan_error = (errmsg) ->
|
649 | errorMessage = ""
|
650 |
|
651 |
|
652 |
|
653 | while (input_str != scan_str)
|
654 | if ((scanned[input_str] == '\n' || scanned[input_str] == '\r') && input_str + 1 == scan_str)
|
655 | break
|
656 | errorMessage += scanned[input_str++]
|
657 |
|
658 | errorMessage += " ? "
|
659 |
|
660 | while (scanned[input_str] && (scanned[input_str] != '\n' && scanned[input_str] != '\r'))
|
661 | errorMessage += scanned[input_str++]
|
662 |
|
663 | errorMessage += '\n'
|
664 |
|
665 | stop(errmsg)
|
666 |
|
667 |
|
668 |
|
669 |
|
670 |
|
671 |
|
672 |
|
673 |
|
674 |
|
675 | build_tensor = (n) ->
|
676 |
|
677 |
|
678 | i = 0
|
679 |
|
680 | save()
|
681 |
|
682 | p2 = alloc_tensor(n)
|
683 | p2.tensor.ndim = 1
|
684 | p2.tensor.dim[0] = n
|
685 | for i in [0...n]
|
686 | p2.tensor.elem[i] = stack[tos-n+i]
|
687 |
|
688 | check_tensor_dimensions p2
|
689 |
|
690 | moveTos tos - n
|
691 |
|
692 | push(p2)
|
693 |
|
694 | restore()
|
695 |
|
696 | get_next_token = ->
|
697 | newline_flag = 0
|
698 | while (1)
|
699 | get_token()
|
700 | if (token != T_NEWLINE)
|
701 | break
|
702 | newline_flag = 1
|
703 | if DEBUG then console.log "get_next_token token: " + token
|
704 |
|
705 |
|
706 |
|
707 | get_token = ->
|
708 |
|
709 | while (isspace(scanned[scan_str]))
|
710 | if (scanned[scan_str] == '\n' || scanned[scan_str] == '\r')
|
711 | token = T_NEWLINE
|
712 | scan_str++
|
713 | return
|
714 | scan_str++
|
715 |
|
716 | token_str = scan_str
|
717 |
|
718 |
|
719 |
|
720 | if (scan_str == scanned.length)
|
721 | token = ""
|
722 | return
|
723 |
|
724 |
|
725 |
|
726 | if (isdigit(scanned[scan_str]) || scanned[scan_str] == '.')
|
727 | while (isdigit(scanned[scan_str]))
|
728 | scan_str++
|
729 | if (scanned[scan_str] == '.')
|
730 | scan_str++
|
731 | while (isdigit(scanned[scan_str]))
|
732 | scan_str++
|
733 | if (scanned[scan_str] == 'e' && (scanned[scan_str+1] == '+' || scanned[scan_str+1] == '-' || isdigit(scanned[scan_str+1])))
|
734 | scan_str += 2
|
735 | while (isdigit(scanned[scan_str]))
|
736 | scan_str++
|
737 | token = T_DOUBLE
|
738 | else
|
739 | token = T_INTEGER
|
740 | update_token_buf(token_str, scan_str)
|
741 | return
|
742 |
|
743 |
|
744 |
|
745 | if (isalpha(scanned[scan_str]))
|
746 | while (isalnumorunderscore(scanned[scan_str]))
|
747 | scan_str++
|
748 | if (scanned[scan_str] == '(')
|
749 | token = T_FUNCTION
|
750 | else
|
751 | token = T_SYMBOL
|
752 | update_token_buf(token_str, scan_str)
|
753 | return
|
754 |
|
755 |
|
756 |
|
757 | if (scanned[scan_str] == '"')
|
758 | scan_str++
|
759 | while (scanned[scan_str] != '"')
|
760 |
|
761 | if (scan_str == scanned.length - 1)
|
762 | scan_str++
|
763 | scan_error("runaway string")
|
764 | scan_str--
|
765 | scan_str++
|
766 | scan_str++
|
767 | token = T_STRING
|
768 | update_token_buf(token_str + 1, scan_str - 1)
|
769 | return
|
770 |
|
771 |
|
772 |
|
773 | if (scanned[scan_str] == '#' || scanned[scan_str] == '-' && scanned[scan_str+1] == '-')
|
774 | while (scanned[scan_str] && scanned[scan_str] != '\n' && scanned[scan_str] != '\r')
|
775 | scan_str++
|
776 | if (scanned[scan_str])
|
777 | scan_str++
|
778 | token = T_NEWLINE
|
779 | return
|
780 |
|
781 |
|
782 | if (scanned[scan_str] == ':' && scanned[scan_str+1] == '=')
|
783 | scan_str += 2
|
784 | token = T_QUOTASSIGN
|
785 | return
|
786 |
|
787 |
|
788 | if (scanned[scan_str] == '=' && scanned[scan_str+1] == '=')
|
789 | scan_str += 2
|
790 | token = T_EQ
|
791 | return
|
792 |
|
793 |
|
794 |
|
795 |
|
796 |
|
797 |
|
798 | if (scanned[scan_str] == '!' && scanned[scan_str+1] == '=')
|
799 | scan_str += 2
|
800 | token = T_NEQ
|
801 | return
|
802 |
|
803 | if (scanned[scan_str] == '<' && scanned[scan_str+1] == '=')
|
804 | scan_str += 2
|
805 | token = T_LTEQ
|
806 | return
|
807 |
|
808 | if (scanned[scan_str] == '>' && scanned[scan_str+1] == '=')
|
809 | scan_str += 2
|
810 | token = T_GTEQ
|
811 | return
|
812 |
|
813 |
|
814 |
|
815 | token = scanned[scan_str++]
|
816 |
|
817 |
|
818 | update_token_buf = (a,b) ->
|
819 |
|
820 | token_buf = scanned.substring(a,b)
|
821 |
|
822 |
|
823 | $.scan = scan
|