GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — microbasic/src/token.cpp at master · bdevorem/microbasic Expand file tree/ Copy pathtoken.cppMore file actions 139 lines (122 loc) · 3.55 KB / Copy pathtoken.cppFile metadata and controls139 lines (122 loc) · 3.55 KB 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 #include "token.h" #include "Energia.h" #include "dumb.h" int atoi(char* s, int len) { int n = ((s[0] == '-')?1:0); int k = 0; int p = 1; for (int i = len - n - 1; i >= 0; i--) { k += (s[i]-'0')*p; p*=10; } return n?-k:k; } int isNumber(char* s, int len) { int n = ((s[0] == '-')?1:0); for (int i = n; i < len; i++) { char c = s[i]; if (c < '0' || c > '9') return 0; } return len>=1; } int strcmp(char* s1, int l1, char* s2, int l2) { if (l1 != l2) return 0; for (int i = 0; i < l1; i++) { if (s1[i] != s2[i]) return 0; } return 1; } void strcpy(char* s1, char* s2) { char c; while (c = *s1) { s1++; (*s2)=c; s2++; } (*s2)=0; } void _print(breezy_t e){ if (e.token == TOKEN_ERROR) Serial.println(ERR": parse failed, you suck"); else Serial.print(e.value); } void _println(breezy_t e){ if (e.token == TOKEN_ERROR) Serial.println(ERR": parse failed, you suck"); else Serial.println(e.value); } token_t scan_token(char* word, int len) { int state = 0; String buf; char symbol = word[0]; if ( strcmp(word, len, "CLEAR", 5) ) { return TOKEN_CLEAR; } else if ( strcmp(word, len, "PRINT", 5 ) ) { return TOKEN_PRINT; } else if ( strcmp(word, len, "IF", 2 ) ) { return TOKEN_IF; } else if ( strcmp(word, len, "THEN", 4 ) ) { return TOKEN_THEN; } else if ( strcmp(word, len, "GOTO", 4 ) ) { return TOKEN_GOTO; } else if ( strcmp(word, len, "INPUT", 5 ) ) { return TOKEN_INPUT; } else if ( strcmp(word, len, "LET", 3 ) ) { return TOKEN_LET; } else if ( strcmp(word, len, "GOSUB", 5 ) ) { return TOKEN_GOSUB; } else if ( strcmp(word, len, "RETURN", 6 ) ) { return TOKEN_RETURN; } else if ( strcmp(word, len, "LIST", 4 ) ) { return TOKEN_LIST; } else if ( strcmp(word, len, "RUN", 3 ) ) { return TOKEN_RUN; } else if ( strcmp(word, len, "END", 3 ) ) { return TOKEN_END; } else if ( strcmp(word, len, "(", 1 ) ) { return TOKEN_LPAREN; } else if ( strcmp(word, len, ")", 1 ) ) { return TOKEN_RPAREN; } else if ( strcmp(word, len, ",", 1 ) ) { return TOKEN_COMMA; } else if ( strcmp(word, len, "*", 1 ) ) { return TOKEN_MUL; } else if ( strcmp(word, len, "/", 1 ) ) { return TOKEN_DIV; } else if ( strcmp(word, len, "-", 1 ) ) { return TOKEN_SUB; } else if ( strcmp(word, len, "+", 1 ) ) { return TOKEN_ADD; } else if ( strcmp(word, len, "=", 1 ) ) { return TOKEN_EQ; } else if ( strcmp(word, len, "<", 1 ) ) { return TOKEN_LT; } else if ( strcmp(word, len, ">", 1 ) ) { return TOKEN_GT; } else if ( strcmp(word, len, "<>", 2 ) ) { return TOKEN_NEQ; } else if ( strcmp(word, len, "<=", 2 ) ) { return TOKEN_LE; } else if ( strcmp(word, len, ">=", 2 ) ) { return TOKEN_GE; } else if ( strcmp(word, len, "&", 1 ) ) { return TOKEN_AND; } else if ( strcmp(word, len, "|", 1 ) ) { return TOKEN_OR; } else if ( strcmp(word, len, "^", 1 ) ) { return TOKEN_XOR; } else if ( strcmp(word, len, "<<", 2 ) ) { return TOKEN_SLL; } else if ( strcmp(word, len, "<<", 2 ) ) { return TOKEN_SRL; } else if ( len > 1 && word[0] == '"' && word[len-1] == '"' ) { return TOKEN_STR; } else if ( len == 1 && word[0] >= 'A' && word[0] <= 'Z' ) { return TOKEN_ID; } else if ( isNumber(word, len) ){ return TOKEN_NUM; } else { return TOKEN_ERROR; } } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |