comparison lwasm/expr.c @ 194:0d916bcebb90

First pass at allowing symbols starting with digits but containing $
author lost
date Sun, 22 Mar 2009 17:50:42 +0000
parents 29ba546ceea0
children 2c1afbdb2de0
comparison
equal deleted inserted replaced
193:716879fc6790 194:0d916bcebb90
282 return 0; 282 return 0;
283 } 283 }
284 284
285 /* 285 /*
286 - a symbol will be a string of characters introduced by a letter, ".", 286 - a symbol will be a string of characters introduced by a letter, ".",
287 "_" but NOT a number 287 "_" but NOT a number OR it may start with a digit if it contains a $
288 - a decimal constant will consist of only digits, optionally prefixed 288 - a decimal constant will consist of only digits, optionally prefixed
289 with "&" 289 with "&"
290 - a binary constant will consist of only 0s and 1s either prefixed with % 290 - a binary constant will consist of only 0s and 1s either prefixed with %
291 or suffixed with "B" 291 or suffixed with "B"
292 - a hex constant will consist of 0-9A-F either prefixed with $ or 292 - a hex constant will consist of 0-9A-F either prefixed with $ or
421 lwasm_expr_term_free(t); 421 lwasm_expr_term_free(t);
422 return 0; 422 return 0;
423 } 423 }
424 424
425 // symbol or bare decimal or suffix identified constant here 425 // symbol or bare decimal or suffix identified constant here
426 // all numbers will start with a digit at this point 426
427 if (**p < '0' || **p > '9') 427 // find the end of a potential symbol
428 do
428 { 429 {
429 int l = 0; 430 int l = 0;
430 char *sb; 431 char *sb;
432 int havedol = 0;
431 433
432 // evaluate a symbol here 434 // evaluate a symbol here
433 static const char *symchars = "_.$@?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; 435 static const char *symchars = "_.$@?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
434 while ((*p)[l] && strchr(symchars, (*p)[l])) 436 while ((*p)[l] && strchr(symchars, (*p)[l]))
437 {
438 if ((*p)[l] == '$')
439 havedol = 1;
435 l++; 440 l++;
436 441 }
437 if (l == 0) 442 if (l == 0)
438 return -1; 443 return -1;
439 444
440 sb = lwasm_alloc(l + 1); 445 if (havedol || **p < '0' || **p > '9')
441 sb[l] = '\0'; 446 {
442 memcpy(sb, *p, l); 447 // have a symbol here
443 t = lwasm_expr_term_create_sym(sb); 448
444 lwasm_expr_stack_push(s, t); 449 sb = lwasm_alloc(l + 1);
445 lwasm_expr_term_free(t); 450 sb[l] = '\0';
446 (*p) += l; 451 memcpy(sb, *p, l);
447 debug_message(3, "Symbol: '%s'; (%s)", sb, *p); 452 t = lwasm_expr_term_create_sym(sb);
448 lwasm_free(sb); 453 lwasm_expr_stack_push(s, t);
449 return 0; 454 lwasm_expr_term_free(t);
450 } 455 (*p) += l;
451 456 debug_message(3, "Symbol: '%s'; (%s)", sb, *p);
457 lwasm_free(sb);
458 return 0;
459 }
460 } while (0);
461
452 if (!**p) 462 if (!**p)
453 return -1; 463 return -1;
454 464
455 // evaluate a suffix based constant 465 // evaluate a suffix based constant
456 { 466 {