Token* Scanner::NextToken() { while (ch == ' ' || ch == 10 || ch == 13 ) NextCh(); int recKind = noSym; int recEnd = pos; t = CreateToken(); t->pos = pos; t->col = col; t->line = line; t->charPos = charPos; int state = start.state(ch); tlen = 0; AddCh(); switch (state) { case -1: { t->kind = eofSym; break; } // NextCh already done case 0: { case_0: if (recKind != noSym) { tlen = recEnd - t->pos; SetScannerBehindT(); } t->kind = recKind; break; } // NextCh already done case 1: case_1: recEnd = pos; recKind = 1; if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_1;} else {t->kind = 1; break;} case 2: if (ch == L'a') {AddCh(); goto case_3;} else {goto case_0;} case 3: case_3: if (ch == L'l') {AddCh(); goto case_4;} else {goto case_0;} case 4: case_4: if (ch == L'c') {AddCh(); goto case_5;} else {goto case_0;} case 5: case_5: {t->kind = 2; break;} case 6: {t->kind = 3; break;} case 7: {t->kind = 4; break;} case 8: {t->kind = 5; break;} case 9: {t->kind = 6; break;} case 10: {t->kind = 7; break;} case 11: {t->kind = 8; break;} } AppendVal(t); return t; }
void Scanner::Init() { EOL = '\n'; eofSym = 0; maxT = 16; noSym = 16; int i; for (i = 65; i <= 90; ++i) start.set(i, 1); for (i = 97; i <= 122; ++i) start.set(i, 1); for (i = 48; i <= 57; ++i) start.set(i, 2); start.set(58, 19); start.set(59, 11); start.set(43, 13); start.set(45, 14); start.set(42, 15); start.set(94, 16); start.set(40, 17); start.set(41, 18); start.set(Buffer::EoF, -1); keywords.set(L"display", 3); keywords.set(L"halt", 8); keywords.set(L"mod", 12); tvalLength = 128; tval = new wchar_t[tvalLength]; // text of current token // HEAP_BLOCK_SIZE byte heap + pointer to next heap block heap = malloc(HEAP_BLOCK_SIZE + sizeof(void*)); firstHeap = heap; heapEnd = (void**) (((char*) heap) + HEAP_BLOCK_SIZE); *heapEnd = 0; heapTop = heap; if (sizeof(Token) > HEAP_BLOCK_SIZE) { wprintf(L"--- Too small HEAP_BLOCK_SIZE\n"); exit(1); } pos = -1; line = 1; col = 0; oldEols = 0; NextCh(); if (ch == 0xEF) { // check optional byte order mark for UTF-8 NextCh(); int ch1 = ch; NextCh(); int ch2 = ch; if (ch1 != 0xBB || ch2 != 0xBF) { wprintf(L"Illegal byte order mark at start of file"); exit(1); } Buffer *oldBuf = buffer; buffer = new UTF8Buffer(buffer); col = 0; delete oldBuf; oldBuf = NULL; NextCh(); } pt = tokens = CreateToken(); // first token is a dummy }
Token* Scanner::NextToken() { while (ch == ' ' || ch == 10 || ch == 13 ) NextCh(); int recKind = noSym; int recEnd = pos; t = CreateToken(); t->pos = pos; t->col = col; t->line = line; int state = start.state(ch); tlen = 0; AddCh(); switch (state) { case -1: { t->kind = eofSym; break; } // NextCh already done case 0: { case_0: if (recKind != noSym) { tlen = recEnd - t->pos; SetScannerBehindT(); } t->kind = recKind; break; } // NextCh already done case 1: case_1: recEnd = pos; recKind = 1; if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'Z') || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_1;} else {t->kind = 1; wchar_t *literal = coco_string_create(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;} case 2: case_2: recEnd = pos; recKind = 2; if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_2;} else {t->kind = 2; break;} case 3: if (ch == L'=') {AddCh(); goto case_4;} else {goto case_0;} case 4: case_4: {t->kind = 3; break;} case 5: {t->kind = 4; break;} case 6: {t->kind = 5; break;} case 7: {t->kind = 6; break;} case 8: {t->kind = 8; break;} case 9: {t->kind = 9; break;} } AppendVal(t); return t; }
void Scanner::Init() { EOL = '\n'; eofSym = 0; maxT = 9; noSym = 9; int i; for (i = 48; i <= 57; ++i) start.set(i, 1); start.set(99, 2); start.set(40, 6); start.set(41, 7); start.set(43, 8); start.set(45, 9); start.set(42, 10); start.set(47, 11); start.set(Buffer::EoF, -1); tvalLength = 128; tval = new wchar_t[tvalLength]; // text of current token // COCO_HEAP_BLOCK_SIZE byte heap + pointer to next heap block heap = malloc(COCO_HEAP_BLOCK_SIZE + sizeof(void*)); firstHeap = heap; heapEnd = (void**) (((char*) heap) + COCO_HEAP_BLOCK_SIZE); *heapEnd = 0; heapTop = heap; if (sizeof(Token) > COCO_HEAP_BLOCK_SIZE) { wprintf(L"--- Too small COCO_HEAP_BLOCK_SIZE\n"); exit(1); } pos = -1; line = 1; col = 0; charPos = -1; oldEols = 0; NextCh(); if (ch == 0xEF) { // check optional byte order mark for UTF-8 NextCh(); int ch1 = ch; NextCh(); int ch2 = ch; if (ch1 != 0xBB || ch2 != 0xBF) { wprintf(L"Illegal byte order mark at start of file"); exit(1); } Buffer *oldBuf = buffer; buffer = new UTF8Buffer(buffer); col = 0; charPos = -1; delete oldBuf; oldBuf = NULL; NextCh(); } pt = tokens = CreateToken(); // first token is a dummy }
int main( int argc, char *argv[] ) { int t; g_argc = argc; g_argv = argv; if( argc < 2 ) // check if filename is given { printf( "Useage: 120++ filename.cpp\n"); exit(-1); } yyin = fopen( argv[1], "r"); // open file if( yyin == NULL) // check if file opened { printf("Can't open file '%s' \n", argv[1]); exit(-1); } // initialize linked list set to NULL nodeptr p; Init(); p =(struct node*)malloc(sizeof(struct node)); struct token* tok; t_filename = argv[1]; while( (t = yylex()) > 0) { tok = CreateToken(t, yytext, t_filename, 1); if( t == SLIT){ SetSval(tok, t_sval); // free(t_sval); } Add( p, tok); // printf( "token '%d' text '%s'\n", t, yytext); } // traverse to end of linked list // print linked list Print(); return 0; }
TokenRef Scanner::NextToken() { while (ch == ' ' || (ch >= 9 && ch <= 10) || ch == 13 || ch == ' ' ) NextCh(); if ((ch == '/' && Comment0()) || (ch == '/' && Comment1())) return NextToken(); int recKind = noSym; size_t recEnd = pos; t = CreateToken(); t->pos = pos; t->col = col; t->line = line; t->charPos = charPos; int state = start.state(ch); tlen = 0; AddCh(); switch (state) { case -1: { t->kind = eofSym; break; } // NextCh already done case 0: { case_0: if (recKind != noSym) { tlen = recEnd - t->pos; SetScannerBehindT(); } t->kind = recKind; break; } // NextCh already done case 1: case_1: recEnd = pos; recKind = 1; if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || ch == '_' || (ch >= 'a' && ch <= 'z')) {AddCh(); goto case_1;} else {t->kind = 1; char *literal = coco_string_create(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;} case 2: case_2: if ((ch >= '0' && ch <= '9')) {AddCh(); goto case_3;} else {goto case_0;} case 3: case_3: recEnd = pos; recKind = 3; if ((ch >= '0' && ch <= '9')) {AddCh(); goto case_3;} else {t->kind = 3; break;} case 4: case_4: if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f')) {AddCh(); goto case_5;} else {goto case_0;} case 5: case_5: if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f')) {AddCh(); goto case_6;} else {goto case_0;} case 6: case_6: if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f')) {AddCh(); goto case_7;} else {goto case_0;} case 7: case_7: if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f')) {AddCh(); goto case_8;} else {goto case_0;} case 8: case_8: if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f')) {AddCh(); goto case_9;} else {goto case_0;} case 9: case_9: recEnd = pos; recKind = 4; if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f')) {AddCh(); goto case_10;} else {t->kind = 4; break;} case 10: case_10: if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f')) {AddCh(); goto case_11;} else {goto case_0;} case 11: case_11: {t->kind = 4; break;} case 12: if ((ch >= 'A' && ch <= 'Z') || ch == '_' || (ch >= 'a' && ch <= 'z')) {AddCh(); goto case_13;} else {goto case_0;} case 13: case_13: recEnd = pos; recKind = 5; if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || ch == '_' || (ch >= 'a' && ch <= 'z')) {AddCh(); goto case_13;} else {t->kind = 5; break;} case 14: case_14: if (ch <= '!' || (ch >= '#' && ch <= '[') || (ch >= ']' && ch <= 65535)) {AddCh(); goto case_14;} else if (ch == '"') {AddCh(); goto case_15;} else if (ch == 92) {AddCh(); goto case_17;} else {goto case_0;} case 15: case_15: {t->kind = 6; break;} case 16: case_16: recEnd = pos; recKind = 2; if ((ch >= '0' && ch <= '9')) {AddCh(); goto case_16;} else if (ch == '.') {AddCh(); goto case_2;} else {t->kind = 2; break;} case 17: case_17: if (ch <= '!' || (ch >= '#' && ch <= '[') || (ch >= ']' && ch <= 65535)) {AddCh(); goto case_14;} else if (ch == 92) {AddCh(); goto case_17;} else if (ch == '"') {AddCh(); goto case_18;} else {goto case_0;} case 18: case_18: recEnd = pos; recKind = 6; if (ch <= '!' || (ch >= '#' && ch <= '[') || (ch >= ']' && ch <= 65535)) {AddCh(); goto case_14;} else if (ch == '"') {AddCh(); goto case_15;} else if (ch == 92) {AddCh(); goto case_17;} else {t->kind = 6; break;} case 19: {t->kind = 11; break;} case 20: {t->kind = 12; break;} case 21: {t->kind = 15; break;} case 22: {t->kind = 16; break;} case 23: {t->kind = 20; break;} case 24: {t->kind = 31; break;} case 25: {t->kind = 32; break;} case 26: {t->kind = 36; break;} case 27: {t->kind = 43; break;} case 28: {t->kind = 45; break;} case 29: {t->kind = 47; break;} case 30: {t->kind = 90; break;} case 31: {t->kind = 91; break;} case 32: {t->kind = 93; break;} case 33: recEnd = pos; recKind = 49; if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f')) {AddCh(); goto case_4;} else {t->kind = 49; break;} } AppendVal(t); return t; }
CgaToken CgaLexer::GetToken() { // Eat white space while (IsWhiteSpace(c)) { MoveNext(); } // Handle identifiers if (IsAlpha(c)) { CGAString identifier; identifier += c; MoveNext(); while (IsAlphaNumeric(c) || c == '.') { identifier += c; MoveNext(); } if (identifier == "true") { return CreateToken(CgaTokenType::True, "true"); } else if (identifier == "false") { return CreateToken(CgaTokenType::False, "false"); } else if (identifier == "var") { return CreateToken(CgaTokenType::Var, "var"); } else { return CreateToken(CgaTokenType::Identifier, identifier); } } // Handle Numbers if (IsDigit(c) || c == '.') { CGAString snum; while (IsDigit(c)) { snum += c; MoveNext(); } if (c == '.') { snum += c; MoveNext(); while (IsDigit(c)) { snum += c; MoveNext(); } } float num = static_cast<float>(atof(snum.c_str())); if (c == 'r') { snum += c; MoveNext(); // Eat 'r' return CreateToken(CgaTokenType::ArgNumber, snum, num); } else { return CreateToken(CgaTokenType::Number, snum); } } // Handle string if (c == '\"') { MoveNext(); // Eat " CGAString value; while (c != '\"') { value += c; MoveNext(); if (stream.eof()) break; } MoveNext(); // Eat " return CreateToken(CgaTokenType::String, value); } // Handle Comments if (c == '#') { // Eat till end of line while (c != '\n' && !stream.eof()) { MoveNext(); } MoveNext(); // Eat \n } // Handle additive operators if (c == '+' || c == '-') { char lastChar = c; CGAString op; op += c; MoveNext(); // Handle arrow op '->' if (lastChar == '-' && c == '>') { op += c; MoveNext(); return CreateToken(CgaTokenType::Arrow, op); } return CreateToken(CgaTokenType::BinaryOp, op); } // Handle multiplicative operators if (c == '*' || c == '/') { CGAString op; op += c; MoveNext(); return CreateToken(CgaTokenType::BinaryOp, op); } // Handle conditional operators if (c == '<' || c == '>' || c == '!' || c == '=') { char lastChar = c; CGAString op; op += c; MoveNext(); if (c != '=') { // Is not an '=='. Emit an assign token ('=') return CreateToken(CgaTokenType::Assign, op); } if ( (lastChar == '<' && c == '=') || (lastChar == '>' && c == '=') || (lastChar == '!' && c == '=') || (lastChar == '=' && c == '=') ) { op += c; MoveNext(); } return CreateToken(CgaTokenType::BinaryOp, op); } // Handle End of file if (stream.eof()) { return CreateToken(CgaTokenType::Eof, 0); } CgaTokenType Type = CgaTokenType::Unknown; if (c == ';') Type = CgaTokenType::Semicolon; if (c == ',') Type = CgaTokenType::Comma; if (c == '(') Type = CgaTokenType::ParenOpen; if (c == ')') Type = CgaTokenType::ParenClose; if (c == '{') Type = CgaTokenType::CurlOpen; if (c == '}') Type = CgaTokenType::CurlClose; if (c == '|') Type = CgaTokenType::Pipe; if (c == ':') Type = CgaTokenType::Colon; if (c == '~') Type = CgaTokenType::Epsillon; CGAString value(1, c); MoveNext(); return CreateToken(Type, value); }
void Scanner::Init() { EOL = '\n'; eofSym = 0; maxT = 94; noSym = 94; int i; for (i = 65; i <= 90; ++i) start.set(i, 1); for (i = 95; i <= 95; ++i) start.set(i, 1); for (i = 97; i <= 122; ++i) start.set(i, 1); for (i = 48; i <= 57; ++i) start.set(i, 16); start.set(35, 33); start.set(64, 12); start.set(34, 14); start.set(123, 19); start.set(125, 20); start.set(61, 21); start.set(59, 22); start.set(44, 23); start.set(91, 24); start.set(93, 25); start.set(45, 26); start.set(58, 27); start.set(60, 28); start.set(46, 29); start.set(40, 30); start.set(41, 31); start.set(33, 32); start.set(Buffer::EoF, -1); keywords.set("OSS", 7); keywords.set("END", 8); keywords.set("FLAG", 9); keywords.set("IF", 10); keywords.set("ELIF", 13); keywords.set("ELSE", 14); keywords.set("ORDER", 17); keywords.set("WAYS", 18); keywords.set("GROUP", 19); keywords.set("SYMBOL", 21); keywords.set("POLYGON", 22); keywords.set("RECTANGLE", 23); keywords.set("x", 24); keywords.set("CIRCLE", 25); keywords.set("CONST", 26); keywords.set("COLOR", 27); keywords.set("MAG", 28); keywords.set("UINT", 29); keywords.set("STYLE", 30); keywords.set("FEATURE", 33); keywords.set("PATH", 34); keywords.set("TYPE", 35); keywords.set("ONEWAY", 37); keywords.set("BRIDGE", 38); keywords.set("TUNNEL", 39); keywords.set("SIZE", 40); keywords.set("m", 41); keywords.set("mm", 42); keywords.set("px", 44); keywords.set("NODE", 46); keywords.set("TEXT", 48); keywords.set("ICON", 50); keywords.set("WAY", 51); keywords.set("SHIELD", 52); keywords.set("AREA", 53); keywords.set("BORDERTEXT", 54); keywords.set("BORDERSYMBOL", 55); keywords.set("color", 56); keywords.set("dash", 57); keywords.set("gapColor", 58); keywords.set("displayWidth", 59); keywords.set("width", 60); keywords.set("displayOffset", 61); keywords.set("offset", 62); keywords.set("cap", 63); keywords.set("joinCap", 64); keywords.set("endCap", 65); keywords.set("priority", 66); keywords.set("zIndex", 67); keywords.set("pattern", 68); keywords.set("patternMinMag", 69); keywords.set("borderColor", 70); keywords.set("borderWidth", 71); keywords.set("borderDash", 72); keywords.set("label", 73); keywords.set("style", 74); keywords.set("size", 75); keywords.set("scaleMag", 76); keywords.set("autoSize", 77); keywords.set("position", 78); keywords.set("backgroundColor", 79); keywords.set("shieldSpace", 80); keywords.set("symbol", 81); keywords.set("symbolSpace", 82); keywords.set("name", 83); keywords.set("butt", 84); keywords.set("round", 85); keywords.set("square", 86); keywords.set("normal", 87); keywords.set("emphasize", 88); keywords.set("lighten", 89); keywords.set("darken", 92); tvalLength = 128; tval = new char[tvalLength]; // text of current token pos = -1; line = 1; col = 0; oldEols = 0; NextCh(); if (ch == 0xEF) { // check optional byte order mark for UTF-8 NextCh(); int ch1 = ch; NextCh(); int ch2 = ch; if (ch1 != 0xBB || ch2 != 0xBF) { std::cerr << "Illegal byte order mark at start of file" << std::endl; exit(1); } NextCh(); } pt = tokens = CreateToken(); // first token is a dummy }
void BeginScan(CJcScanner* scanner){ NextCh(scanner); scanner->pt = scanner->tokens = CreateToken(scanner); /* first token is a dummy */ }
Token* Scanner::NextToken() { while (ch == ' ' || (ch >= 9 && ch <= 10) || ch == 13 ) NextCh(); int recKind = noSym; int recEnd = pos; t = CreateToken(); t->pos = pos; t->col = col; t->line = line; t->charPos = charPos; int state = start.state(ch); tlen = 0; AddCh(); switch (state) { case -1: { t->kind = eofSym; break; } // NextCh already done case 0: { case_0: if (recKind != noSym) { tlen = recEnd - t->pos; SetScannerBehindT(); } t->kind = recKind; break; } // NextCh already done case 1: if ((ch >= L'A' && ch <= L'Z') || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_2;} else {goto case_0;} case 2: case_2: recEnd = pos; recKind = 1; if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'Z') || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_2;} else {t->kind = 1; break;} case 3: if ((ch >= L'A' && ch <= L'Z') || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_4;} else {goto case_0;} case 4: case_4: recEnd = pos; recKind = 2; if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'Z') || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_4;} else {t->kind = 2; break;} case 5: case_5: recEnd = pos; recKind = 3; if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'Z') || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_5;} else {t->kind = 3; break;} case 6: if ((ch >= L'A' && ch <= L'Z')) {AddCh(); goto case_7;} else {goto case_0;} case 7: case_7: recEnd = pos; recKind = 4; if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'Z') || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_7;} else {t->kind = 4; break;} case 8: case_8: if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_9;} else {goto case_0;} case 9: case_9: recEnd = pos; recKind = 6; if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_9;} else {t->kind = 6; break;} case 10: if (ch <= 8 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'!') || (ch >= L'#' && ch <= 65535)) {AddCh(); goto case_11;} else {goto case_0;} case 11: case_11: if (ch <= 8 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'!') || (ch >= L'#' && ch <= 65535)) {AddCh(); goto case_11;} else if (ch == L'"') {AddCh(); goto case_12;} else {goto case_0;} case 12: case_12: {t->kind = 7; break;} case 13: if (ch == L'r') {AddCh(); goto case_14;} else {goto case_0;} case 14: case_14: if (ch == L'u') {AddCh(); goto case_15;} else {goto case_0;} case 15: case_15: if (ch == L'e') {AddCh(); goto case_20;} else {goto case_0;} case 16: if (ch == L'a') {AddCh(); goto case_17;} else {goto case_0;} case 17: case_17: if (ch == L'l') {AddCh(); goto case_18;} else {goto case_0;} case 18: case_18: if (ch == L's') {AddCh(); goto case_19;} else {goto case_0;} case 19: case_19: if (ch == L'e') {AddCh(); goto case_20;} else {goto case_0;} case 20: case_20: {t->kind = 8; break;} case 21: if (ch == L'l') {AddCh(); goto case_22;} else {goto case_0;} case 22: case_22: if (ch == L'a') {AddCh(); goto case_23;} else {goto case_0;} case 23: case_23: if (ch == L's') {AddCh(); goto case_24;} else {goto case_0;} case 24: case_24: if (ch == L's') {AddCh(); goto case_25;} else {goto case_0;} case 25: case_25: {t->kind = 9; break;} case 26: case_26: if (ch == L'b') {AddCh(); goto case_27;} else {goto case_0;} case 27: case_27: if (ch == L'l') {AddCh(); goto case_28;} else {goto case_0;} case 28: case_28: if (ch == L'i') {AddCh(); goto case_29;} else {goto case_0;} case 29: case_29: if (ch == L'c') {AddCh(); goto case_30;} else {goto case_0;} case 30: case_30: {t->kind = 10; break;} case 31: case_31: if (ch == L'v') {AddCh(); goto case_32;} else {goto case_0;} case 32: case_32: if (ch == L'a') {AddCh(); goto case_33;} else {goto case_0;} case 33: case_33: if (ch == L't') {AddCh(); goto case_34;} else {goto case_0;} case 34: case_34: if (ch == L'e') {AddCh(); goto case_35;} else {goto case_0;} case 35: case_35: {t->kind = 11; break;} case 36: case_36: if (ch == L't') {AddCh(); goto case_37;} else {goto case_0;} case 37: case_37: if (ch == L'e') {AddCh(); goto case_38;} else {goto case_0;} case 38: case_38: if (ch == L'c') {AddCh(); goto case_39;} else {goto case_0;} case 39: case_39: if (ch == L't') {AddCh(); goto case_40;} else {goto case_0;} case 40: case_40: {t->kind = 12; break;} case 41: if (ch == L'e') {AddCh(); goto case_42;} else {goto case_0;} case 42: case_42: if (ch == L't') {AddCh(); goto case_43;} else {goto case_0;} case 43: case_43: if (ch == L'u') {AddCh(); goto case_44;} else {goto case_0;} case 44: case_44: if (ch == L'r') {AddCh(); goto case_45;} else {goto case_0;} case 45: case_45: if (ch == L'n') {AddCh(); goto case_46;} else {goto case_0;} case 46: case_46: {t->kind = 13; break;} case 47: if (ch == L't') {AddCh(); goto case_48;} else {goto case_0;} case 48: case_48: if (ch == L'r') {AddCh(); goto case_49;} else {goto case_0;} case 49: case_49: if (ch == L'i') {AddCh(); goto case_50;} else {goto case_0;} case 50: case_50: if (ch == L'n') {AddCh(); goto case_51;} else {goto case_0;} case 51: case_51: if (ch == L'g') {AddCh(); goto case_52;} else {goto case_0;} case 52: case_52: {t->kind = 14; break;} case 53: case_53: if (ch == L't') {AddCh(); goto case_54;} else {goto case_0;} case 54: case_54: {t->kind = 15; break;} case 55: if (ch == L'o') {AddCh(); goto case_56;} else {goto case_0;} case 56: case_56: if (ch == L'u') {AddCh(); goto case_57;} else {goto case_0;} case 57: case_57: if (ch == L'b') {AddCh(); goto case_58;} else {goto case_0;} case 58: case_58: if (ch == L'l') {AddCh(); goto case_59;} else {goto case_0;} case 59: case_59: if (ch == L'e') {AddCh(); goto case_60;} else {goto case_0;} case 60: case_60: {t->kind = 16; break;} case 61: if (ch == L'o') {AddCh(); goto case_62;} else {goto case_0;} case 62: case_62: if (ch == L'o') {AddCh(); goto case_63;} else {goto case_0;} case 63: case_63: if (ch == L'l') {AddCh(); goto case_64;} else {goto case_0;} case 64: case_64: {t->kind = 17; break;} case 65: if (ch == L'e') {AddCh(); goto case_66;} else {goto case_0;} case 66: case_66: if (ch == L'w') {AddCh(); goto case_67;} else {goto case_0;} case 67: case_67: {t->kind = 18; break;} case 68: if (ch == L'o') {AddCh(); goto case_69;} else {goto case_0;} case 69: case_69: if (ch == L'i') {AddCh(); goto case_70;} else {goto case_0;} case 70: case_70: if (ch == L'd') {AddCh(); goto case_71;} else {goto case_0;} case 71: case_71: {t->kind = 19; break;} case 72: case_72: {t->kind = 20; break;} case 73: case_73: if (ch == L'f') {AddCh(); goto case_74;} else {goto case_0;} case 74: case_74: {t->kind = 22; break;} case 75: if (ch == L'h') {AddCh(); goto case_76;} else {goto case_0;} case 76: case_76: if (ch == L'i') {AddCh(); goto case_77;} else {goto case_0;} case 77: case_77: if (ch == L'l') {AddCh(); goto case_78;} else {goto case_0;} case 78: case_78: if (ch == L'e') {AddCh(); goto case_79;} else {goto case_0;} case 79: case_79: {t->kind = 23; break;} case 80: case_80: {t->kind = 24; break;} case 81: if (ch == L'a') {AddCh(); goto case_82;} else {goto case_0;} case 82: case_82: if (ch == L'i') {AddCh(); goto case_83;} else {goto case_0;} case 83: case_83: if (ch == L'n') {AddCh(); goto case_84;} else {goto case_0;} case 84: case_84: {t->kind = 25; break;} case 85: case_85: {t->kind = 26; break;} case 86: case_86: {t->kind = 27; break;} case 87: case_87: {t->kind = 28; break;} case 88: case_88: {t->kind = 29; break;} case 89: case_89: {t->kind = 30; break;} case 90: case_90: {t->kind = 31; break;} case 91: case_91: {t->kind = 32; break;} case 92: case_92: {t->kind = 33; break;} case 93: case_93: if (ch <= L')' || (ch >= L'+' && ch <= 65535)) {AddCh(); goto case_93;} else if (ch == L'*') {AddCh(); goto case_100;} else {goto case_0;} case 94: case_94: {t->kind = 56; break;} case 95: case_95: recEnd = pos; recKind = 5; if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_95;} else if (ch == L'.') {AddCh(); goto case_8;} else {t->kind = 5; break;} case 96: if (ch == L'u') {AddCh(); goto case_26;} else if (ch == L'r') {AddCh(); goto case_101;} else {goto case_0;} case 97: if (ch == L'n') {AddCh(); goto case_53;} else if (ch == L'f') {AddCh(); goto case_72;} else {goto case_0;} case 98: if (ch == L'l') {AddCh(); goto case_102;} else {goto case_0;} case 99: recEnd = pos; recKind = 21; if (ch == L'?') {AddCh(); goto case_74;} else {t->kind = 21; break;} case 100: case_100: if (ch <= L')' || (ch >= L'+' && ch <= L'.') || (ch >= L'0' && ch <= 65535)) {AddCh(); goto case_93;} else if (ch == L'/') {AddCh(); goto case_94;} else if (ch == L'*') {AddCh(); goto case_100;} else {goto case_0;} case 101: case_101: if (ch == L'i') {AddCh(); goto case_31;} else if (ch == L'o') {AddCh(); goto case_36;} else {goto case_0;} case 102: case_102: if (ch == L's') {AddCh(); goto case_103;} else {goto case_0;} case 103: case_103: if (ch == L'e') {AddCh(); goto case_104;} else {goto case_0;} case 104: case_104: recEnd = pos; recKind = 21; if (ch == L'i') {AddCh(); goto case_73;} else {t->kind = 21; break;} case 105: {t->kind = 34; break;} case 106: {t->kind = 35; break;} case 107: {t->kind = 37; break;} case 108: {t->kind = 38; break;} case 109: {t->kind = 39; break;} case 110: {t->kind = 40; break;} case 111: {t->kind = 41; break;} case 112: {t->kind = 42; break;} case 113: {t->kind = 43; break;} case 114: {t->kind = 46; break;} case 115: {t->kind = 47; break;} case 116: {t->kind = 50; break;} case 117: {t->kind = 51; break;} case 118: {t->kind = 52; break;} case 119: {t->kind = 54; break;} case 120: recEnd = pos; recKind = 45; if (ch == L'>') {AddCh(); goto case_80;} else if (ch == L'-') {AddCh(); goto case_88;} else {t->kind = 45; break;} case 121: recEnd = pos; recKind = 49; if (ch == L'>') {AddCh(); goto case_85;} else if (ch == L'=') {AddCh(); goto case_89;} else {t->kind = 49; break;} case 122: recEnd = pos; recKind = 48; if (ch == L'<') {AddCh(); goto case_86;} else if (ch == L'=') {AddCh(); goto case_90;} else if (ch == L'>') {AddCh(); goto case_91;} else {t->kind = 48; break;} case 123: recEnd = pos; recKind = 44; if (ch == L'+') {AddCh(); goto case_87;} else {t->kind = 44; break;} case 124: recEnd = pos; recKind = 36; if (ch == L'=') {AddCh(); goto case_92;} else {t->kind = 36; break;} case 125: recEnd = pos; recKind = 53; if (ch == L'*') {AddCh(); goto case_93;} else {t->kind = 53; break;} } AppendVal(t); return t; }
void Scanner::Init() { EOL = '\n'; eofSym = 0; maxT = 55; noSym = 55; int i; for (i = 65; i <= 90; ++i) start.set(i, 5); for (i = 48; i <= 57; ++i) start.set(i, 95); start.set(95, 1); start.set(35, 3); start.set(36, 6); start.set(34, 10); start.set(116, 13); start.set(102, 16); start.set(99, 21); start.set(112, 96); start.set(114, 41); start.set(115, 47); start.set(105, 97); start.set(100, 55); start.set(98, 61); start.set(110, 65); start.set(118, 68); start.set(63, 72); start.set(101, 98); start.set(58, 99); start.set(119, 75); start.set(64, 79); start.set(45, 120); start.set(109, 81); start.set(62, 121); start.set(60, 122); start.set(43, 123); start.set(61, 124); start.set(47, 125); start.set(91, 105); start.set(93, 106); start.set(59, 107); start.set(40, 108); start.set(41, 109); start.set(123, 110); start.set(125, 111); start.set(44, 112); start.set(94, 113); start.set(38, 114); start.set(124, 115); start.set(126, 116); start.set(46, 117); start.set(42, 118); start.set(37, 119); start.set(Buffer::EoF, -1); tvalLength = 128; tval = new wchar_t[tvalLength]; // text of current token // COCO_HEAP_BLOCK_SIZE byte heap + pointer to next heap block heap = malloc(COCO_HEAP_BLOCK_SIZE + sizeof(void*)); firstHeap = heap; heapEnd = (void**) (((char*) heap) + COCO_HEAP_BLOCK_SIZE); *heapEnd = 0; heapTop = heap; if (sizeof(Token) > COCO_HEAP_BLOCK_SIZE) { wprintf(L"--- Too small COCO_HEAP_BLOCK_SIZE\n"); exit(1); } pos = -1; line = 1; col = 0; charPos = -1; oldEols = 0; NextCh(); if (ch == 0xEF) { // check optional byte order mark for UTF-8 NextCh(); int ch1 = ch; NextCh(); int ch2 = ch; if (ch1 != 0xBB || ch2 != 0xBF) { wprintf(L"Illegal byte order mark at start of file"); exit(1); } Buffer *oldBuf = buffer; buffer = new UTF8Buffer(buffer); col = 0; charPos = -1; delete oldBuf; oldBuf = NULL; NextCh(); } pt = tokens = CreateToken(); // first token is a dummy }
Token* Scanner::NextToken() { while (ch == ' ' || (ch >= 9 && ch <= 10) || ch == 13 ) NextCh(); int recKind = noSym; int recEnd = pos; t = CreateToken(); t->pos = pos; t->col = col; t->line = line; t->charPos = charPos; int state = start.state(ch); tlen = 0; AddCh(); switch (state) { case -1: { t->kind = eofSym; break; } // NextCh already done case 0: { case_0: if (recKind != noSym) { tlen = recEnd - t->pos; SetScannerBehindT(); } t->kind = recKind; break; } // NextCh already done case 1: case_1: if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_2;} else {goto case_0;} case 2: case_2: recEnd = pos; recKind = 2; if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_2;} else {t->kind = 2; break;} case 3: if ((ch >= L'A' && ch <= L'Z') || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_4;} else {goto case_0;} case 4: case_4: if ((ch >= L'A' && ch <= L'Z') || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_4;} else if (ch == L'"') {AddCh(); goto case_5;} else {goto case_0;} case 5: case_5: {t->kind = 3; break;} case 6: case_6: recEnd = pos; recKind = 4; if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_6;} else {t->kind = 4; wchar_t *literal = coco_string_create(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;} case 7: case_7: recEnd = pos; recKind = 1; if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_7;} else if (ch == L'.') {AddCh(); goto case_1;} else {t->kind = 1; break;} case 8: {t->kind = 6; break;} case 9: {t->kind = 7; break;} case 10: {t->kind = 9; break;} case 11: {t->kind = 10; break;} case 12: {t->kind = 11; break;} case 13: if (ch == L'.') {AddCh(); goto case_14;} else {goto case_0;} case 14: case_14: {t->kind = 12; break;} case 15: {t->kind = 13; break;} case 16: {t->kind = 17; break;} case 17: {t->kind = 18; break;} case 18: {t->kind = 22; break;} case 19: {t->kind = 23; break;} case 20: {t->kind = 31; break;} case 21: {t->kind = 33; break;} case 22: case_22: {t->kind = 53; break;} case 23: case_23: {t->kind = 54; break;} case 24: case_24: {t->kind = 55; break;} case 25: case_25: {t->kind = 56; break;} case 26: {t->kind = 61; break;} case 27: {t->kind = 62; break;} case 28: {t->kind = 63; break;} case 29: recEnd = pos; recKind = 26; if (ch == L'=') {AddCh(); goto case_22;} else {t->kind = 26; break;} case 30: recEnd = pos; recKind = 57; if (ch == L'>') {AddCh(); goto case_23;} else if (ch == L'=') {AddCh(); goto case_24;} else {t->kind = 57; break;} case 31: recEnd = pos; recKind = 58; if (ch == L'=') {AddCh(); goto case_25;} else {t->kind = 58; break;} } AppendVal(t); return t; }
void Scanner::Init() { EOL = '\n'; eofSym = 0; maxT = 109; noSym = 109; int i; for (i = 65; i <= 81; ++i) start.set(i, 1); for (i = 83; i <= 90; ++i) start.set(i, 1); for (i = 95; i <= 95; ++i) start.set(i, 1); for (i = 97; i <= 122; ++i) start.set(i, 1); start.set(48, 67); for (i = 49; i <= 57; ++i) start.set(i, 68); start.set(46, 69); start.set(39, 17); start.set(34, 20); start.set(44, 22); start.set(59, 23); start.set(58, 24); start.set(42, 25); start.set(40, 26); start.set(41, 27); start.set(91, 28); start.set(93, 29); start.set(123, 30); start.set(125, 31); start.set(35, 70); start.set(82, 80); start.set(61, 77); start.set(60, 78); start.set(62, 79); start.set(Buffer::EoF, -1); keywords.set(L"auto", 6); keywords.set(L"case", 7); keywords.set(L"cbuffer", 8); keywords.set(L"char", 9); keywords.set(L"const", 10); keywords.set(L"default", 11); keywords.set(L"double", 12); keywords.set(L"enum", 13); keywords.set(L"extern", 14); keywords.set(L"register", 15); keywords.set(L"short", 16); keywords.set(L"signed", 17); keywords.set(L"static", 18); keywords.set(L"struct", 19); keywords.set(L"typedef", 20); keywords.set(L"union", 21); keywords.set(L"unsigned", 22); keywords.set(L"void", 23); keywords.set(L"volatile", 24); keywords.set(L"HS", 36); keywords.set(L"DS", 37); keywords.set(L"TS", 38); keywords.set(L"VS", 39); keywords.set(L"GS", 40); keywords.set(L"PS", 41); keywords.set(L"RenderTarget", 42); keywords.set(L"SizeX", 43); keywords.set(L"ScaleX", 44); keywords.set(L"SizeY", 45); keywords.set(L"ScaleY", 46); keywords.set(L"Format", 47); keywords.set(L"Info", 48); keywords.set(L"MultiRenderTarget", 49); keywords.set(L"ClearColor", 50); keywords.set(L"SamplerState", 51); keywords.set(L"SamplerComparisonState", 52); keywords.set(L"Filter", 53); keywords.set(L"AddressU", 54); keywords.set(L"AddressV", 55); keywords.set(L"AddressW", 56); keywords.set(L"MipLODBias", 57); keywords.set(L"MaxAnisotropy", 58); keywords.set(L"ComparisonFunc", 59); keywords.set(L"BorderColor", 60); keywords.set(L"MinLOD", 61); keywords.set(L"MaxLOD", 62); keywords.set(L"DepthStencilState", 63); keywords.set(L"DepthEnable", 64); keywords.set(L"DepthWriteMask", 65); keywords.set(L"DepthFunc", 66); keywords.set(L"StencilEnable", 67); keywords.set(L"RasterizerState", 68); keywords.set(L"FillMode", 69); keywords.set(L"CullMode", 70); keywords.set(L"FrontCounterClockwise", 71); keywords.set(L"DepthBias", 72); keywords.set(L"DepthBiasClamp", 73); keywords.set(L"SlopeScaledDepthBias", 74); keywords.set(L"DepthClipEnable", 75); keywords.set(L"ScissorEnable", 76); keywords.set(L"MultisampleEnable", 77); keywords.set(L"AntialiasedLineEnable", 78); keywords.set(L"BlendState", 79); keywords.set(L"BlendEnable", 80); keywords.set(L"AlphaToCoverageEnable", 81); keywords.set(L"SrcBlend", 82); keywords.set(L"DestBlend", 83); keywords.set(L"BlendOp", 84); keywords.set(L"SrcBlendAlpha", 85); keywords.set(L"DestBlendAlpha", 86); keywords.set(L"BlendOpAlpha", 87); keywords.set(L"RenderTargetWriteMask", 88); keywords.set(L"StateBlock", 89); keywords.set(L"StencilRef", 90); keywords.set(L"BlendFactor", 91); keywords.set(L"SampleMask", 92); keywords.set(L"Shader", 94); keywords.set(L"Code", 95); keywords.set(L"VertexShader", 97); keywords.set(L"PixelShader", 98); keywords.set(L"Inputs", 101); keywords.set(L"Texture2D", 102); keywords.set(L"Vertex", 103); keywords.set(L"SemanticName", 104); keywords.set(L"SemanticIndex", 105); keywords.set(L"InputSlot", 106); keywords.set(L"Shared", 107); keywords.set(L"Variables", 108); tvalLength = 128; tval = new wchar_t[tvalLength]; // text of current token // HEAP_BLOCK_SIZE byte heap + pointer to next heap block heap = mxAlloc(HEAP_BLOCK_SIZE + sizeof(void*)); firstHeap = heap; heapEnd = (void**) (((char*) heap) + HEAP_BLOCK_SIZE); *heapEnd = 0; heapTop = heap; if (sizeof(Token) > HEAP_BLOCK_SIZE) { wprintf(L"--- Too small HEAP_BLOCK_SIZE\n"); MX_DEBUG_BREAK; exit(1); } pos = -1; line = 1; col = 0; charPos = -1; oldEols = 0; NextCh(); if (ch == 0xEF) { // check optional byte order mark for UTF-8 NextCh(); int ch1 = ch; NextCh(); int ch2 = ch; if (ch1 != 0xBB || ch2 != 0xBF) { wprintf(L"Illegal byte order mark at start of file"); MX_DEBUG_BREAK; exit(1); } Buffer *oldBuf = buffer; buffer = new UTF8Buffer(buffer); col = 0; charPos = -1; delete oldBuf; oldBuf = NULL; NextCh(); } pt = tokens = CreateToken(); // first token is a dummy }
void Scanner::Init() { EOL = '\n'; eofSym = 0; maxT = 38; noSym = 38; int i; for (i = 97; i <= 98; ++i) start.set(i, 1); for (i = 100; i <= 117; ++i) start.set(i, 1); for (i = 119; i <= 122; ++i) start.set(i, 1); for (i = 48; i <= 57; ++i) start.set(i, 5); start.set(39, 2); start.set(60, 8); start.set(62, 9); start.set(33, 6); start.set(61, 17); start.set(59, 10); start.set(40, 11); start.set(44, 12); start.set(41, 13); start.set(99, 18); start.set(118, 19); start.set(42, 16); start.set(Buffer::EoF, -1); keywords.set(L"create", 6); keywords.set(L"table", 7); keywords.set(L"null", 11); keywords.set(L"not", 12); keywords.set(L"default", 13); keywords.set(L"index", 14); keywords.set(L"int", 15); keywords.set(L"float", 16); keywords.set(L"long", 17); keywords.set(L"date", 18); keywords.set(L"time", 19); keywords.set(L"drop", 22); keywords.set(L"select", 23); keywords.set(L"distinct", 24); keywords.set(L"all", 25); keywords.set(L"from", 27); keywords.set(L"where", 28); keywords.set(L"update", 29); keywords.set(L"set", 30); keywords.set(L"insert", 32); keywords.set(L"into", 33); keywords.set(L"values", 34); keywords.set(L"delete", 35); keywords.set(L"and", 36); keywords.set(L"or", 37); tvalLength = 128; tval = new wchar_t[tvalLength]; // text of current token // HEAP_BLOCK_SIZE byte heap + pointer to next heap block heap = malloc(HEAP_BLOCK_SIZE + sizeof(void*)); firstHeap = heap; heapEnd = (void**) (((char*) heap) + HEAP_BLOCK_SIZE); *heapEnd = 0; heapTop = heap; if (sizeof(Token) > HEAP_BLOCK_SIZE) { wprintf(L"--- Too small HEAP_BLOCK_SIZE\n"); exit(1); } pos = -1; line = 1; col = 0; oldEols = 0; NextCh(); if (ch == 0xEF) { // check optional byte order mark for UTF-8 NextCh(); int ch1 = ch; NextCh(); int ch2 = ch; if (ch1 != 0xBB || ch2 != 0xBF) { wprintf(L"Illegal byte order mark at start of file"); exit(1); } Buffer *oldBuf = buffer; buffer = new UTF8Buffer(buffer); col = 0; delete oldBuf; oldBuf = NULL; NextCh(); } pt = tokens = CreateToken(); // first token is a dummy }
void Scanner::Init() { EOL = '\n'; eofSym = 0; maxT = 61; noSym = 61; int i; for (i = 97; i <= 122; ++i) start.set(i, 1); for (i = 48; i <= 57; ++i) start.set(i, 61); start.set(34, 4); start.set(39, 6); start.set(10, 9); start.set(46, 62); start.set(65, 60); start.set(67, 64); start.set(123, 70); start.set(125, 71); start.set(86, 106); start.set(70, 73); start.set(80, 82); start.set(44, 90); start.set(40, 91); start.set(41, 92); start.set(45, 94); start.set(60, 107); start.set(62, 108); start.set(33, 98); start.set(61, 100); start.set(89, 101); start.set(79, 102); start.set(43, 103); start.set(42, 104); start.set(47, 105); start.set(Buffer::EoF, -1); keywords.set(L"motor", 20); keywords.set(L"servo", 21); keywords.set(L"pantalla", 22); keywords.set(L"led", 23); keywords.set(L"boton", 24); keywords.set(L"sensor", 25); keywords.set(L"pin", 27); keywords.set(L"espacios", 28); keywords.set(L"entero", 29); keywords.set(L"decimal", 30); keywords.set(L"frase", 31); keywords.set(L"enteroA", 32); keywords.set(L"decimalA", 33); keywords.set(L"condicion", 38); keywords.set(L"ciclo", 39); keywords.set(L"llamar", 40); keywords.set(L"asignar", 41); keywords.set(L"esperar", 42); keywords.set(L"si", 43); keywords.set(L"sino", 44); keywords.set(L"mientras", 45); keywords.set(L"haz", 46); keywords.set(L"veces", 47); keywords.set(L"posicion", 48); tvalLength = 128; tval = new wchar_t[tvalLength]; // text of current token // COCO_HEAP_BLOCK_SIZE byte heap + pointer to next heap block heap = malloc(COCO_HEAP_BLOCK_SIZE + sizeof(void*)); firstHeap = heap; heapEnd = (void**) (((char*) heap) + COCO_HEAP_BLOCK_SIZE); *heapEnd = 0; heapTop = heap; if (sizeof(Token) > COCO_HEAP_BLOCK_SIZE) { wprintf(L"--- Too small COCO_HEAP_BLOCK_SIZE\n"); exit(1); } pos = -1; line = 1; col = 0; charPos = -1; oldEols = 0; NextCh(); if (ch == 0xEF) { // check optional byte order mark for UTF-8 NextCh(); int ch1 = ch; NextCh(); int ch2 = ch; if (ch1 != 0xBB || ch2 != 0xBF) { wprintf(L"Illegal byte order mark at start of file"); exit(1); } Buffer *oldBuf = buffer; buffer = new UTF8Buffer(buffer); col = 0; charPos = -1; delete oldBuf; oldBuf = NULL; NextCh(); } pt = tokens = CreateToken(); // first token is a dummy }
void Scanner::Init() { EOL = '\n'; eofSym = 0; maxT = 41; noSym = 41; int i; for (i = 65; i <= 90; ++i) start.set(i, 1); for (i = 95; i <= 95; ++i) start.set(i, 1); for (i = 97; i <= 122; ++i) start.set(i, 1); for (i = 48; i <= 57; ++i) start.set(i, 2); start.set(34, 12); start.set(39, 5); start.set(36, 13); start.set(61, 16); start.set(46, 31); start.set(43, 17); start.set(45, 18); start.set(60, 32); start.set(62, 20); start.set(124, 23); start.set(40, 33); start.set(41, 24); start.set(91, 25); start.set(93, 26); start.set(123, 27); start.set(125, 28); start.set(Buffer::EoF, -1); keywords.set(L"COMPILER", 6); keywords.set(L"IGNORECASE", 7); keywords.set(L"CHARACTERS", 8); keywords.set(L"TOKENS", 9); keywords.set(L"PRAGMAS", 10); keywords.set(L"COMMENTS", 11); keywords.set(L"FROM", 12); keywords.set(L"TO", 13); keywords.set(L"NESTED", 14); keywords.set(L"IGNORE", 15); keywords.set(L"PRODUCTIONS", 16); keywords.set(L"END", 19); keywords.set(L"ANY", 23); keywords.set(L"WEAK", 29); keywords.set(L"SYNC", 36); keywords.set(L"IF", 37); keywords.set(L"CONTEXT", 38); tvalLength = 128; tval = new wchar_t[tvalLength]; // text of current token // COCO_HEAP_BLOCK_SIZE byte heap + pointer to next heap block heap = malloc(COCO_HEAP_BLOCK_SIZE + sizeof(void*)); firstHeap = heap; heapEnd = (void**) (((char*) heap) + COCO_HEAP_BLOCK_SIZE); *heapEnd = 0; heapTop = heap; if (sizeof(Token) > COCO_HEAP_BLOCK_SIZE) { wprintf(L"--- Too small COCO_HEAP_BLOCK_SIZE\n"); exit(1); } pos = -1; line = 1; col = 0; charPos = -1; oldEols = 0; NextCh(); if (ch == 0xEF) { // check optional byte order mark for UTF-8 NextCh(); int ch1 = ch; NextCh(); int ch2 = ch; if (ch1 != 0xBB || ch2 != 0xBF) { wprintf(L"Illegal byte order mark at start of file"); exit(1); } Buffer *oldBuf = buffer; buffer = new UTF8Buffer(buffer); col = 0; charPos = -1; delete oldBuf; oldBuf = NULL; NextCh(); } pt = tokens = CreateToken(); // first token is a dummy }
static CJcToken* NextToken(CJcScanner* scanner){ jc_int state; while (scanner->ch == ' ' || scanner->ch >= 9 && scanner->ch <= 10 || scanner->ch == 13 ) NextCh(scanner); scanner->t = CreateToken(scanner); scanner->t->fcol = GetCol(scanner->buffer); scanner->t->fline = GetLine(scanner->buffer); scanner->t->fname = GetFileName(scanner->buffer); scanner->t->pos = scanner->pos; scanner->t->col = scanner->col; scanner->t->line = scanner->line; state = GetStartState(&scanner->start, scanner->ch); scanner->tlen = 0; AddCh(scanner); switch (state){ case -1: scanner->t->kind = scanner->eofSym; break; case 0: scanner->t->kind = scanner->noSym; break; case 1: case_1: if (scanner->ch >= '0' && scanner->ch <= '9' || scanner->ch >= 'A' && scanner->ch <= 'Z' || scanner->ch == '_' || scanner->ch >= 'a' && scanner->ch <= 'z') {AddCh(scanner); goto case_1;} else {scanner->t->kind = 1; {char *literal = jcc_string_create(scanner->tval, 0, scanner->tlen); scanner->t->kind = GetKeyword(&scanner->keywords, literal, scanner->t->kind); free(literal); break;}} case 2: if (scanner->ch <= 9 || scanner->ch >= 11 && scanner->ch <= 12 || scanner->ch >= 14 && scanner->ch <= '&' || scanner->ch >= '(' && scanner->ch <= '[' || scanner->ch >= ']' && scanner->ch <= 65535) {AddCh(scanner); goto case_4;} else if (scanner->ch == 92) {AddCh(scanner); goto case_3;} else {scanner->t->kind = scanner->noSym; break;} case 3: case_3: if (scanner->ch == '"' || scanner->ch == 39 || scanner->ch == '?' || scanner->ch == 92 || scanner->ch >= 'a' && scanner->ch <= 'b' || scanner->ch == 'f' || scanner->ch == 'n' || scanner->ch == 'r' || scanner->ch == 't' || scanner->ch == 'v') {AddCh(scanner); goto case_4;} else if (scanner->ch >= '0' && scanner->ch <= '7') {AddCh(scanner); goto case_5;} else if (scanner->ch == 'X' || scanner->ch == 'x') {AddCh(scanner); goto case_6;} else {scanner->t->kind = scanner->noSym; break;} case 4: case_4: if (scanner->ch == 39) {AddCh(scanner); goto case_8;} else {scanner->t->kind = scanner->noSym; break;} case 5: case_5: if (scanner->ch >= '0' && scanner->ch <= '7') {AddCh(scanner); goto case_87;} else if (scanner->ch == 39) {AddCh(scanner); goto case_8;} else {scanner->t->kind = scanner->noSym; break;} case 6: case_6: if (scanner->ch >= '0' && scanner->ch <= '9' || scanner->ch >= 'A' && scanner->ch <= 'F' || scanner->ch >= 'a' && scanner->ch <= 'f') {AddCh(scanner); goto case_7;} else {scanner->t->kind = scanner->noSym; break;} case 7: case_7: if (scanner->ch >= '0' && scanner->ch <= '9' || scanner->ch >= 'A' && scanner->ch <= 'F' || scanner->ch >= 'a' && scanner->ch <= 'f') {AddCh(scanner); goto case_4;} else if (scanner->ch == 39) {AddCh(scanner); goto case_8;} else {scanner->t->kind = scanner->noSym; break;} case 8: case_8: {scanner->t->kind = 2; break;} case 9: case_9: if (scanner->ch <= 9 || scanner->ch >= 11 && scanner->ch <= 12 || scanner->ch >= 14 && scanner->ch <= '!' || scanner->ch >= '#' && scanner->ch <= '[' || scanner->ch >= ']' && scanner->ch <= 65535) {AddCh(scanner); goto case_9;} else if (scanner->ch == '"') {AddCh(scanner); goto case_14;} else if (scanner->ch == 92) {AddCh(scanner); goto case_10;} else {scanner->t->kind = scanner->noSym; break;} case 10: case_10: if (scanner->ch == '"' || scanner->ch == 39 || scanner->ch == '?' || scanner->ch == 92 || scanner->ch >= 'a' && scanner->ch <= 'b' || scanner->ch == 'f' || scanner->ch == 'n' || scanner->ch == 'r' || scanner->ch == 't' || scanner->ch == 'v') {AddCh(scanner); goto case_9;} else if (scanner->ch >= '0' && scanner->ch <= '7') {AddCh(scanner); goto case_11;} else if (scanner->ch == 'X' || scanner->ch == 'x') {AddCh(scanner); goto case_12;} else {scanner->t->kind = scanner->noSym; break;} case 11: case_11: if (scanner->ch <= 9 || scanner->ch >= 11 && scanner->ch <= 12 || scanner->ch >= 14 && scanner->ch <= '!' || scanner->ch >= '#' && scanner->ch <= '/' || scanner->ch >= '8' && scanner->ch <= '[' || scanner->ch >= ']' && scanner->ch <= 65535) {AddCh(scanner); goto case_9;} else if (scanner->ch >= '0' && scanner->ch <= '7') {AddCh(scanner); goto case_88;} else if (scanner->ch == '"') {AddCh(scanner); goto case_14;} else if (scanner->ch == 92) {AddCh(scanner); goto case_10;} else {scanner->t->kind = scanner->noSym; break;} case 12: case_12: if (scanner->ch >= '0' && scanner->ch <= '9' || scanner->ch >= 'A' && scanner->ch <= 'F' || scanner->ch >= 'a' && scanner->ch <= 'f') {AddCh(scanner); goto case_13;} else {scanner->t->kind = scanner->noSym; break;} case 13: case_13: if (scanner->ch <= 9 || scanner->ch >= 11 && scanner->ch <= 12 || scanner->ch >= 14 && scanner->ch <= '!' || scanner->ch >= '#' && scanner->ch <= '[' || scanner->ch >= ']' && scanner->ch <= 65535) {AddCh(scanner); goto case_9;} else if (scanner->ch == '"') {AddCh(scanner); goto case_14;} else if (scanner->ch == 92) {AddCh(scanner); goto case_10;} else {scanner->t->kind = scanner->noSym; break;} case 14: case_14: {scanner->t->kind = 3; break;} case 15: case_15: if (scanner->ch == '8' || scanner->ch == 'L' || scanner->ch == 'l') {AddCh(scanner); goto case_25;} else if (scanner->ch == '1') {AddCh(scanner); goto case_16;} else if (scanner->ch == '3') {AddCh(scanner); goto case_17;} else if (scanner->ch == '6') {AddCh(scanner); goto case_18;} else {scanner->t->kind = 4; break;} case 16: case_16: if (scanner->ch == '6') {AddCh(scanner); goto case_25;} else {scanner->t->kind = scanner->noSym; break;} case 17: case_17: if (scanner->ch == '2') {AddCh(scanner); goto case_25;} else {scanner->t->kind = scanner->noSym; break;} case 18: case_18: if (scanner->ch == '4') {AddCh(scanner); goto case_25;} else {scanner->t->kind = scanner->noSym; break;} case 19: case_19: if (scanner->ch == '8') {AddCh(scanner); goto case_25;} else if (scanner->ch == '1') {AddCh(scanner); goto case_20;} else if (scanner->ch == '3') {AddCh(scanner); goto case_21;} else if (scanner->ch == '6') {AddCh(scanner); goto case_22;} else {scanner->t->kind = scanner->noSym; break;} case 20: case_20: if (scanner->ch == '6') {AddCh(scanner); goto case_25;} else {scanner->t->kind = scanner->noSym; break;} case 21: case_21: if (scanner->ch == '2') {AddCh(scanner); goto case_25;} else {scanner->t->kind = scanner->noSym; break;} case 22: case_22: if (scanner->ch == '4') {AddCh(scanner); goto case_25;} else {scanner->t->kind = scanner->noSym; break;} case 23: case_23: if (scanner->ch >= '0' && scanner->ch <= '9' || scanner->ch >= 'A' && scanner->ch <= 'F' || scanner->ch >= 'a' && scanner->ch <= 'f') {AddCh(scanner); goto case_24;} else {scanner->t->kind = scanner->noSym; break;} case 24: case_24: if (scanner->ch >= '0' && scanner->ch <= '9' || scanner->ch >= 'A' && scanner->ch <= 'F' || scanner->ch >= 'a' && scanner->ch <= 'f') {AddCh(scanner); goto case_24;} else if (scanner->ch == 'U' || scanner->ch == 'u') {AddCh(scanner); goto case_15;} else if (scanner->ch == 'I' || scanner->ch == 'i') {AddCh(scanner); goto case_19;} else {scanner->t->kind = 4; break;} case 25: case_25: {scanner->t->kind = 4; break;} case 26: case_26: if (scanner->ch >= '0' && scanner->ch <= '9') {AddCh(scanner); goto case_26;} else if (scanner->ch == 'F' || scanner->ch == 'f') {AddCh(scanner); goto case_39;} else if (scanner->ch == 'E' || scanner->ch == 'e') {AddCh(scanner); goto case_27;} else {scanner->t->kind = 5; break;} case 27: case_27: if (scanner->ch >= '0' && scanner->ch <= '9') {AddCh(scanner); goto case_29;} else if (scanner->ch == '+' || scanner->ch == '-') {AddCh(scanner); goto case_28;} else {scanner->t->kind = scanner->noSym; break;} case 28: case_28: if (scanner->ch >= '0' && scanner->ch <= '9') {AddCh(scanner); goto case_29;} else {scanner->t->kind = scanner->noSym; break;} case 29: case_29: if (scanner->ch >= '0' && scanner->ch <= '9') {AddCh(scanner); goto case_29;} else if (scanner->ch == 'F' || scanner->ch == 'f') {AddCh(scanner); goto case_39;} else {scanner->t->kind = 5; break;} case 30: case_30: if (scanner->ch >= '0' && scanner->ch <= '9') {AddCh(scanner); goto case_30;} else if (scanner->ch == '.') {AddCh(scanner); goto case_31;} else if (scanner->ch == 'E' || scanner->ch == 'e') {AddCh(scanner); goto case_36;} else {scanner->t->kind = scanner->noSym; break;} case 31: case_31: if (scanner->ch >= '0' && scanner->ch <= '9') {AddCh(scanner); goto case_35;} else if (scanner->ch == 'F' || scanner->ch == 'f') {AddCh(scanner); goto case_39;} else if (scanner->ch == 'E' || scanner->ch == 'e') {AddCh(scanner); goto case_32;} else {scanner->t->kind = 5; break;} case 32: case_32: if (scanner->ch >= '0' && scanner->ch <= '9') {AddCh(scanner); goto case_34;} else if (scanner->ch == '+' || scanner->ch == '-') {AddCh(scanner); goto case_33;} else {scanner->t->kind = scanner->noSym; break;} case 33: case_33: if (scanner->ch >= '0' && scanner->ch <= '9') {AddCh(scanner); goto case_34;} else {scanner->t->kind = scanner->noSym; break;} case 34: case_34: if (scanner->ch >= '0' && scanner->ch <= '9') {AddCh(scanner); goto case_34;} else if (scanner->ch == 'F' || scanner->ch == 'f') {AddCh(scanner); goto case_39;} else {scanner->t->kind = 5; break;} case 35: case_35: if (scanner->ch >= '0' && scanner->ch <= '9') {AddCh(scanner); goto case_35;} else if (scanner->ch == 'F' || scanner->ch == 'f') {AddCh(scanner); goto case_39;} else if (scanner->ch == 'E' || scanner->ch == 'e') {AddCh(scanner); goto case_32;} else {scanner->t->kind = 5; break;} case 36: case_36: if (scanner->ch >= '0' && scanner->ch <= '9') {AddCh(scanner); goto case_38;} else if (scanner->ch == '+' || scanner->ch == '-') {AddCh(scanner); goto case_37;} else {scanner->t->kind = scanner->noSym; break;} case 37: case_37: if (scanner->ch >= '0' && scanner->ch <= '9') {AddCh(scanner); goto case_38;} else {scanner->t->kind = scanner->noSym; break;} case 38: case_38: if (scanner->ch >= '0' && scanner->ch <= '9') {AddCh(scanner); goto case_38;} else if (scanner->ch == 'F' || scanner->ch == 'f') {AddCh(scanner); goto case_39;} else {scanner->t->kind = 5; break;} case 39: case_39: {scanner->t->kind = 5; break;} case 40: case_40: if (scanner->ch == '.') {AddCh(scanner); goto case_41;} else {scanner->t->kind = scanner->noSym; break;} case 41: case_41: {scanner->t->kind = 40; break;} case 42: case_42: {scanner->t->kind = 41; break;} case 43: case_43: {scanner->t->kind = 42; break;} case 44: case_44: {scanner->t->kind = 43; break;} case 45: case_45: {scanner->t->kind = 44; break;} case 46: case_46: {scanner->t->kind = 45; break;} case 47: case_47: {scanner->t->kind = 46; break;} case 48: case_48: {scanner->t->kind = 47; break;} case 49: case_49: {scanner->t->kind = 48; break;} case 50: case_50: {scanner->t->kind = 49; break;} case 51: case_51: {scanner->t->kind = 50; break;} case 52: case_52: {scanner->t->kind = 51; break;} case 53: case_53: {scanner->t->kind = 52; break;} case 54: case_54: {scanner->t->kind = 53; break;} case 55: case_55: {scanner->t->kind = 54; break;} case 56: case_56: {scanner->t->kind = 57; break;} case 57: case_57: {scanner->t->kind = 58; break;} case 58: case_58: {scanner->t->kind = 59; break;} case 59: case_59: {scanner->t->kind = 60; break;} case 60: case_60: {scanner->t->kind = 61; break;} case 61: {scanner->t->kind = 62; break;} case 62: {scanner->t->kind = 68; break;} case 63: {scanner->t->kind = 69; break;} case 64: case_64: {scanner->t->kind = 73; break;} case 65: case_65: {scanner->t->kind = 74; break;} case 66: case_66: {scanner->t->kind = 75; break;} case 67: case_67: {scanner->t->kind = 76; break;} case 68: {scanner->t->kind = 79; break;} case 69: {scanner->t->kind = 82; break;} case 70: {scanner->t->kind = 84; break;} case 71: case_71: if (scanner->ch >= '0' && scanner->ch <= '9') {AddCh(scanner); goto case_71;} else if (scanner->ch == 'U' || scanner->ch == 'u') {AddCh(scanner); goto case_15;} else if (scanner->ch == 'I' || scanner->ch == 'i') {AddCh(scanner); goto case_19;} else if (scanner->ch == '.') {AddCh(scanner); goto case_31;} else if (scanner->ch == 'E' || scanner->ch == 'e') {AddCh(scanner); goto case_36;} else {scanner->t->kind = 4; break;} case 72: case_72: if (scanner->ch >= '0' && scanner->ch <= '7') {AddCh(scanner); goto case_72;} else if (scanner->ch >= '8' && scanner->ch <= '9') {AddCh(scanner); goto case_30;} else if (scanner->ch == 'X' || scanner->ch == 'x') {AddCh(scanner); goto case_23;} else if (scanner->ch == 'U' || scanner->ch == 'u') {AddCh(scanner); goto case_15;} else if (scanner->ch == 'I' || scanner->ch == 'i') {AddCh(scanner); goto case_19;} else if (scanner->ch == '.') {AddCh(scanner); goto case_31;} else if (scanner->ch == 'E' || scanner->ch == 'e') {AddCh(scanner); goto case_36;} else {scanner->t->kind = 4; break;} case 73: if (scanner->ch >= '0' && scanner->ch <= '9') {AddCh(scanner); goto case_26;} else if (scanner->ch == '.') {AddCh(scanner); goto case_40;} else {scanner->t->kind = 83; break;} case 74: if (scanner->ch == '>') {AddCh(scanner); goto case_89;} else if (scanner->ch == '=') {AddCh(scanner); goto case_53;} else {scanner->t->kind = 81; break;} case 75: if (scanner->ch == '<') {AddCh(scanner); goto case_90;} else if (scanner->ch == '=') {AddCh(scanner); goto case_54;} else if (scanner->ch == '%') {AddCh(scanner); goto case_64;} else if (scanner->ch == ':') {AddCh(scanner); goto case_66;} else {scanner->t->kind = 80; break;} case 76: if (scanner->ch == '=') {AddCh(scanner); goto case_44;} else {scanner->t->kind = 63; break;} case 77: if (scanner->ch == '=') {AddCh(scanner); goto case_45;} else if (scanner->ch == '>') {AddCh(scanner); goto case_65;} else {scanner->t->kind = 64; break;} case 78: if (scanner->ch == '=') {AddCh(scanner); goto case_46;} else {scanner->t->kind = 65; break;} case 79: if (scanner->ch == '=') {AddCh(scanner); goto case_47;} else if (scanner->ch == '&') {AddCh(scanner); goto case_56;} else {scanner->t->kind = 66; break;} case 80: if (scanner->ch == '=') {AddCh(scanner); goto case_48;} else {scanner->t->kind = 67; break;} case 81: if (scanner->ch == '=') {AddCh(scanner); goto case_49;} else if (scanner->ch == '>') {AddCh(scanner); goto case_58;} else if (scanner->ch == '-') {AddCh(scanner); goto case_60;} else {scanner->t->kind = 70; break;} case 82: if (scanner->ch == '=') {AddCh(scanner); goto case_50;} else if (scanner->ch == '+') {AddCh(scanner); goto case_59;} else {scanner->t->kind = 71; break;} case 83: if (scanner->ch == '=') {AddCh(scanner); goto case_51;} else if (scanner->ch == '|') {AddCh(scanner); goto case_57;} else {scanner->t->kind = 77; break;} case 84: if (scanner->ch == '=') {AddCh(scanner); goto case_52;} else {scanner->t->kind = 85; break;} case 85: if (scanner->ch == '=') {AddCh(scanner); goto case_55;} else {scanner->t->kind = 72; break;} case 86: if (scanner->ch == '>') {AddCh(scanner); goto case_67;} else {scanner->t->kind = 78; break;} case 87: case_87: if (scanner->ch >= '0' && scanner->ch <= '7') {AddCh(scanner); goto case_4;} else if (scanner->ch == 39) {AddCh(scanner); goto case_8;} else {scanner->t->kind = scanner->noSym; break;} case 88: case_88: if (scanner->ch <= 9 || scanner->ch >= 11 && scanner->ch <= 12 || scanner->ch >= 14 && scanner->ch <= '!' || scanner->ch >= '#' && scanner->ch <= '[' || scanner->ch >= ']' && scanner->ch <= 65535) {AddCh(scanner); goto case_9;} else if (scanner->ch == '"') {AddCh(scanner); goto case_14;} else if (scanner->ch == 92) {AddCh(scanner); goto case_10;} else {scanner->t->kind = scanner->noSym; break;} case 89: case_89: if (scanner->ch == '=') {AddCh(scanner); goto case_42;} else {scanner->t->kind = 56; break;} case 90: case_90: if (scanner->ch == '=') {AddCh(scanner); goto case_43;} else {scanner->t->kind = 55; break;} } AppendVal(scanner, scanner->t); return scanner->t; }
Token* Scanner::NextToken() { while (ch == ' ' || false ) NextCh(); int recKind = noSym; int recEnd = pos; t = CreateToken(); t->pos = pos; t->col = col; t->line = line; t->charPos = charPos; int state = start.state(ch); tlen = 0; AddCh(); switch (state) { case -1: { t->kind = eofSym; break; } // NextCh already done case 0: { case_0: if (recKind != noSym) { tlen = recEnd - t->pos; SetScannerBehindT(); } t->kind = recKind; break; } // NextCh already done case 1: if (ch == L'1') {AddCh(); goto case_2;} else {goto case_0;} case 2: case_2: if (ch == L'2') {AddCh(); goto case_3;} else {goto case_0;} case 3: case_3: if (ch == L'3') {AddCh(); goto case_4;} else {goto case_0;} case 4: case_4: if (ch == L'4') {AddCh(); goto case_5;} else {goto case_0;} case 5: case_5: if (ch == L'5') {AddCh(); goto case_6;} else {goto case_0;} case 6: case_6: if (ch == L'6') {AddCh(); goto case_7;} else {goto case_0;} case 7: case_7: if (ch == L'7') {AddCh(); goto case_8;} else {goto case_0;} case 8: case_8: if (ch == L'8') {AddCh(); goto case_9;} else {goto case_0;} case 9: case_9: if (ch == L'9') {AddCh(); goto case_10;} else {goto case_0;} case 10: case_10: {t->kind = 1; break;} case 11: case_11: {t->kind = 2; break;} case 12: {t->kind = 3; break;} case 13: {t->kind = 4; break;} case 14: case_14: if (ch == L'u') {AddCh(); goto case_15;} else {goto case_0;} case 15: case_15: if (ch == L'e') {AddCh(); goto case_19;} else {goto case_0;} case 16: case_16: if (ch == L'l') {AddCh(); goto case_17;} else {goto case_0;} case 17: case_17: if (ch == L's') {AddCh(); goto case_18;} else {goto case_0;} case 18: case_18: if (ch == L'e') {AddCh(); goto case_19;} else {goto case_0;} case 19: case_19: {t->kind = 5; break;} case 20: recEnd = pos; recKind = 2; if (ch == L'=') {AddCh(); goto case_11;} else {t->kind = 2; break;} case 21: recEnd = pos; recKind = 2; if (ch == L'=') {AddCh(); goto case_11;} else {t->kind = 2; break;} case 22: case_22: if (ch == L'd') {AddCh(); goto case_23;} else {goto case_0;} case 23: case_23: if (ch == L'u') {AddCh(); goto case_24;} else {goto case_0;} case 24: case_24: if (ch == L'l') {AddCh(); goto case_25;} else {goto case_0;} case 25: case_25: if (ch == L'e') {AddCh(); goto case_26;} else {goto case_0;} case 26: case_26: {t->kind = 6; break;} case 27: case_27: {t->kind = 7; break;} case 28: if (ch == L'a') {AddCh(); goto case_29;} else {goto case_0;} case 29: case_29: if (ch == L'r') {AddCh(); goto case_30;} else {goto case_0;} case 30: case_30: {t->kind = 8; break;} case 31: case_31: if (ch == L'g') {AddCh(); goto case_32;} else {goto case_0;} case 32: case_32: if (ch == L'i') {AddCh(); goto case_33;} else {goto case_0;} case 33: case_33: if (ch == L'n') {AddCh(); goto case_34;} else {goto case_0;} case 34: case_34: {t->kind = 9; break;} case 35: case_35: if (ch == L'd') {AddCh(); goto case_36;} else {goto case_0;} case 36: case_36: {t->kind = 10; break;} case 37: case_37: if (ch == L'p') {AddCh(); goto case_38;} else {goto case_0;} case 38: case_38: if (ch == L'o') {AddCh(); goto case_39;} else {goto case_0;} case 39: case_39: if (ch == L'r') {AddCh(); goto case_40;} else {goto case_0;} case 40: case_40: if (ch == L't') {AddCh(); goto case_41;} else {goto case_0;} case 41: case_41: {t->kind = 12; break;} case 42: {t->kind = 13; break;} case 43: case_43: if (ch == L's') {AddCh(); goto case_44;} else {goto case_0;} case 44: case_44: if (ch == L't') {AddCh(); goto case_45;} else {goto case_0;} case 45: case_45: if (ch == L'd') {AddCh(); goto case_46;} else {goto case_0;} case 46: case_46: if (ch == L'l') {AddCh(); goto case_47;} else {goto case_0;} case 47: case_47: if (ch == L'o') {AddCh(); goto case_48;} else {goto case_0;} case 48: case_48: if (ch == L'g') {AddCh(); goto case_49;} else {goto case_0;} case 49: case_49: {t->kind = 14; break;} case 50: if (ch == L'm') {AddCh(); goto case_51;} else {goto case_0;} case 51: case_51: if (ch == L'a') {AddCh(); goto case_52;} else {goto case_0;} case 52: case_52: if (ch == L't') {AddCh(); goto case_53;} else {goto case_0;} case 53: case_53: if (ch == L'h') {AddCh(); goto case_54;} else {goto case_0;} case 54: case_54: {t->kind = 15; break;} case 55: if (ch == L'r') {AddCh(); goto case_56;} else {goto case_0;} case 56: case_56: if (ch == L'r') {AddCh(); goto case_57;} else {goto case_0;} case 57: case_57: if (ch == L'a') {AddCh(); goto case_58;} else {goto case_0;} case 58: case_58: if (ch == L'y') {AddCh(); goto case_59;} else {goto case_0;} case 59: case_59: {t->kind = 17; break;} case 60: case_60: {t->kind = 18; break;} case 61: case_61: if (ch == L'g') {AddCh(); goto case_62;} else {goto case_0;} case 62: case_62: if (ch == L'e') {AddCh(); goto case_63;} else {goto case_0;} case 63: case_63: if (ch == L'r') {AddCh(); goto case_64;} else {goto case_0;} case 64: case_64: {t->kind = 19; break;} case 65: case_65: if (ch == L'l') {AddCh(); goto case_66;} else {goto case_0;} case 66: case_66: {t->kind = 20; break;} case 67: case_67: if (ch == L'a') {AddCh(); goto case_68;} else {goto case_0;} case 68: case_68: if (ch == L'n') {AddCh(); goto case_69;} else {goto case_0;} case 69: case_69: {t->kind = 21; break;} case 70: case_70: {t->kind = 22; break;} case 71: case_71: if (ch == L'e') {AddCh(); goto case_72;} else {goto case_0;} case 72: case_72: if (ch == L'n') {AddCh(); goto case_73;} else {goto case_0;} case 73: case_73: {t->kind = 23; break;} case 74: {t->kind = 24; break;} case 75: case_75: if (ch == L'l') {AddCh(); goto case_76;} else {goto case_0;} case 76: case_76: if (ch == L'o') {AddCh(); goto case_77;} else {goto case_0;} case 77: case_77: if (ch == L'g') {AddCh(); goto case_78;} else {goto case_0;} case 78: case_78: if (ch == L'.') {AddCh(); goto case_79;} else {goto case_0;} case 79: case_79: {t->kind = 26; break;} case 80: if (ch == L'n') {AddCh(); goto case_81;} else {goto case_0;} case 81: case_81: {t->kind = 27; break;} case 82: case_82: if (ch == L'i') {AddCh(); goto case_83;} else {goto case_0;} case 83: case_83: if (ch == L'n') {AddCh(); goto case_84;} else {goto case_0;} case 84: case_84: if (ch == L'g') {AddCh(); goto case_85;} else {goto case_0;} case 85: case_85: {t->kind = 30; break;} case 86: case_86: {t->kind = 31; break;} case 87: {t->kind = 32; break;} case 88: {t->kind = 33; break;} case 89: if (ch == L'h') {AddCh(); goto case_90;} else {goto case_0;} case 90: case_90: if (ch == L'i') {AddCh(); goto case_91;} else {goto case_0;} case 91: case_91: if (ch == L'l') {AddCh(); goto case_92;} else {goto case_0;} case 92: case_92: if (ch == L'e') {AddCh(); goto case_93;} else {goto case_0;} case 93: case_93: if (ch == L'(') {AddCh(); goto case_94;} else {goto case_0;} case 94: case_94: {t->kind = 34; break;} case 95: case_95: if (ch == L'o') {AddCh(); goto case_96;} else {goto case_0;} case 96: case_96: {t->kind = 35; break;} case 97: case_97: if (ch == L'e') {AddCh(); goto case_98;} else {goto case_0;} case 98: case_98: if (ch == L'a') {AddCh(); goto case_99;} else {goto case_0;} case 99: case_99: if (ch == L't') {AddCh(); goto case_100;} else {goto case_0;} case 100: case_100: {t->kind = 36; break;} case 101: if (ch == L'n') {AddCh(); goto case_102;} else {goto case_0;} case 102: case_102: if (ch == L't') {AddCh(); goto case_103;} else {goto case_0;} case 103: case_103: if (ch == L'i') {AddCh(); goto case_104;} else {goto case_0;} case 104: case_104: if (ch == L'l') {AddCh(); goto case_105;} else {goto case_0;} case 105: case_105: if (ch == L'(') {AddCh(); goto case_106;} else {goto case_0;} case 106: case_106: {t->kind = 37; break;} case 107: case_107: if (ch == L'r') {AddCh(); goto case_108;} else {goto case_0;} case 108: case_108: {t->kind = 38; break;} case 109: case_109: {t->kind = 39; break;} case 110: if (ch == L'o') {AddCh(); goto case_111;} else {goto case_0;} case 111: case_111: {t->kind = 40; break;} case 112: case_112: {t->kind = 41; break;} case 113: case_113: if (ch == L'e') {AddCh(); goto case_114;} else {goto case_0;} case 114: case_114: if (ch == L'n') {AddCh(); goto case_115;} else {goto case_0;} case 115: case_115: {t->kind = 42; break;} case 116: case_116: if (ch == L's') {AddCh(); goto case_117;} else {goto case_0;} case 117: case_117: if (ch == L'e') {AddCh(); goto case_118;} else {goto case_0;} case 118: case_118: {t->kind = 43; break;} case 119: if (ch == L'r') {AddCh(); goto case_14;} else if (ch == L'o') {AddCh(); goto case_109;} else if (ch == L'h') {AddCh(); goto case_113;} else {goto case_0;} case 120: if (ch == L'a') {AddCh(); goto case_16;} else if (ch == L'o') {AddCh(); goto case_107;} else {goto case_0;} case 121: if (ch == L'o') {AddCh(); goto case_22;} else if (ch == L'a') {AddCh(); goto case_130;} else {goto case_0;} case 122: if (ch == L'e') {AddCh(); goto case_31;} else if (ch == L'o') {AddCh(); goto case_131;} else {goto case_0;} case 123: if (ch == L'n') {AddCh(); goto case_35;} else if (ch == L'l') {AddCh(); goto case_116;} else {goto case_0;} case 124: if (ch == L'm') {AddCh(); goto case_37;} else if (ch == L'n') {AddCh(); goto case_132;} else if (ch == L'f') {AddCh(); goto case_112;} else {goto case_0;} case 125: recEnd = pos; recKind = 16; if (ch == L'=') {AddCh(); goto case_86;} else {t->kind = 16; break;} case 126: if (ch == L'f') {AddCh(); goto case_60;} else if (ch == L'p') {AddCh(); goto case_71;} else {goto case_0;} case 127: if (ch == L'e') {AddCh(); goto case_133;} else {goto case_0;} case 128: recEnd = pos; recKind = 25; if (ch == L'd') {AddCh(); goto case_95;} else {t->kind = 25; break;} case 129: if (ch == L't') {AddCh(); goto case_134;} else {goto case_0;} case 130: case_130: if (ch == L'i') {AddCh(); goto case_135;} else {goto case_0;} case 131: case_131: if (ch == L'o') {AddCh(); goto case_136;} else {goto case_0;} case 132: case_132: if (ch == L',') {AddCh(); goto case_43;} else if (ch == L't') {AddCh(); goto case_137;} else if (ch == L'.') {AddCh(); goto case_70;} else {goto case_0;} case 133: case_133: if (ch == L'a') {AddCh(); goto case_65;} else if (ch == L'p') {AddCh(); goto case_97;} else {goto case_0;} case 134: case_134: if (ch == L'd') {AddCh(); goto case_75;} else if (ch == L'r') {AddCh(); goto case_82;} else {goto case_0;} case 135: case_135: if (ch == L'n') {AddCh(); goto case_138;} else {goto case_0;} case 136: case_136: if (ch == L'l') {AddCh(); goto case_139;} else {goto case_0;} case 137: case_137: recEnd = pos; recKind = 28; if (ch == L'e') {AddCh(); goto case_61;} else {t->kind = 28; break;} case 138: case_138: recEnd = pos; recKind = 11; if (ch == L';') {AddCh(); goto case_27;} else {t->kind = 11; break;} case 139: case_139: recEnd = pos; recKind = 29; if (ch == L'e') {AddCh(); goto case_67;} else {t->kind = 29; break;} } AppendVal(t); return t; }
void Scanner::Init() { EOL = '\n'; eofSym = 0; maxT = 44; noSym = 44; start.set(48, 1); int i; for (i = 35; i <= 35; ++i) start.set(i, 11); for (i = 38; i <= 38; ++i) start.set(i, 11); for (i = 61; i <= 61; ++i) start.set(i, 11); for (i = 124; i <= 124; ++i) start.set(i, 11); start.set(60, 20); start.set(62, 21); for (i = 42; i <= 42; ++i) start.set(i, 12); for (i = 47; i <= 47; ++i) start.set(i, 12); for (i = 43; i <= 43; ++i) start.set(i, 13); for (i = 45; i <= 45; ++i) start.set(i, 13); start.set(116, 119); start.set(102, 120); start.set(109, 121); start.set(118, 28); start.set(98, 122); start.set(101, 123); start.set(105, 124); start.set(59, 42); start.set(44, 50); start.set(58, 125); start.set(97, 55); start.set(111, 126); start.set(114, 127); start.set(40, 74); start.set(41, 128); start.set(115, 129); start.set(108, 80); start.set(126, 87); start.set(46, 88); start.set(119, 89); start.set(117, 101); start.set(100, 110); start.set(Buffer::EoF, -1); tvalLength = 128; tval = new wchar_t[tvalLength]; // text of current token // COCO_HEAP_BLOCK_SIZE byte heap + pointer to next heap block heap = malloc(COCO_HEAP_BLOCK_SIZE + sizeof(void*)); firstHeap = heap; heapEnd = (void**) (((char*) heap) + COCO_HEAP_BLOCK_SIZE); *heapEnd = 0; heapTop = heap; if (sizeof(Token) > COCO_HEAP_BLOCK_SIZE) { wprintf(L"--- Too small COCO_HEAP_BLOCK_SIZE\n"); exit(1); } pos = -1; line = 1; col = 0; charPos = -1; oldEols = 0; NextCh(); if (ch == 0xEF) { // check optional byte order mark for UTF-8 NextCh(); int ch1 = ch; NextCh(); int ch2 = ch; if (ch1 != 0xBB || ch2 != 0xBF) { wprintf(L"Illegal byte order mark at start of file"); exit(1); } Buffer *oldBuf = buffer; buffer = new UTF8Buffer(buffer); col = 0; charPos = -1; delete oldBuf; oldBuf = NULL; NextCh(); } pt = tokens = CreateToken(); // first token is a dummy }
Token* Scanner::NextToken() { while (ch == ' ' || (ch >= 9 && ch <= 10) || ch == 13 ) NextCh(); if ((ch == L'(' && Comment0())) return NextToken(); int recKind = noSym; int recEnd = pos; t = CreateToken(); t->pos = pos; t->col = col; t->line = line; t->charPos = charPos; int state = start.state(ch); tlen = 0; AddCh(); switch (state) { case -1: { t->kind = eofSym; break; } // NextCh already done case 0: { case_0: if (recKind != noSym) { tlen = recEnd - t->pos; SetScannerBehindT(); } t->kind = recKind; break; } // NextCh already done case 1: case_1: recEnd = pos; recKind = 1; if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_1;} else {t->kind = 1; wchar_t *literal = coco_string_create(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;} case 2: case_2: {t->kind = 2; break;} case 3: case_3: {t->kind = 3; break;} case 4: case_4: {t->kind = 4; break;} case 5: case_5: recEnd = pos; recKind = 5; if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_5;} else if ((ch >= L'D' && ch <= L'E')) {AddCh(); goto case_6;} else {t->kind = 5; break;} case 6: case_6: if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_8;} else if (ch == L'+' || ch == L'-') {AddCh(); goto case_7;} else {goto case_0;} case 7: case_7: if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_8;} else {goto case_0;} case 8: case_8: recEnd = pos; recKind = 5; if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_8;} else {t->kind = 5; break;} case 9: case_9: {t->kind = 6; break;} case 10: case_10: recEnd = pos; recKind = 4; if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_10;} else if ((ch >= L'A' && ch <= L'F')) {AddCh(); goto case_13;} else if (ch == L'H') {AddCh(); goto case_4;} else if (ch == L'.') {AddCh(); goto case_5;} else if (ch == L'X') {AddCh(); goto case_9;} else {t->kind = 4; break;} case 11: case_11: if (ch == 10 || ch == 13) {AddCh(); goto case_2;} else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'!') || (ch >= L'#' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_11;} else if (ch == 92) {AddCh(); goto case_14;} else if (ch == L'"') {AddCh(); goto case_3;} else {goto case_0;} case 12: case_12: if (ch == 10 || ch == 13) {AddCh(); goto case_2;} else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'&') || (ch >= L'(' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_12;} else if (ch == 92) {AddCh(); goto case_15;} else if (ch == 39) {AddCh(); goto case_3;} else {goto case_0;} case 13: case_13: if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'F')) {AddCh(); goto case_13;} else if (ch == L'H') {AddCh(); goto case_4;} else if (ch == L'X') {AddCh(); goto case_9;} else {goto case_0;} case 14: case_14: if ((ch >= 1 && ch <= 9) || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'!') || (ch >= L'#' && ch <= L'[') || (ch >= L']' && ch <= L't') || (ch >= L'v' && ch <= L'~')) {AddCh(); goto case_11;} else if (ch == L'u') {AddCh(); goto case_16;} else {goto case_0;} case 15: case_15: if ((ch >= 1 && ch <= 9) || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'!') || (ch >= L'#' && ch <= L'[') || (ch >= L']' && ch <= L't') || (ch >= L'v' && ch <= L'~')) {AddCh(); goto case_12;} else if (ch == L'u') {AddCh(); goto case_17;} else {goto case_0;} case 16: case_16: if (ch == 10 || ch == 13) {AddCh(); goto case_2;} else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'!') || (ch >= L'#' && ch <= L'/') || (ch >= L':' && ch <= L'@') || (ch >= L'G' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_11;} else if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'F')) {AddCh(); goto case_18;} else if (ch == 92) {AddCh(); goto case_14;} else if (ch == L'"') {AddCh(); goto case_3;} else {goto case_0;} case 17: case_17: if (ch == 10 || ch == 13) {AddCh(); goto case_2;} else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'&') || (ch >= L'(' && ch <= L'/') || (ch >= L':' && ch <= L'@') || (ch >= L'G' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_12;} else if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'F')) {AddCh(); goto case_19;} else if (ch == 92) {AddCh(); goto case_15;} else if (ch == 39) {AddCh(); goto case_3;} else {goto case_0;} case 18: case_18: if (ch == 10 || ch == 13) {AddCh(); goto case_2;} else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'!') || (ch >= L'#' && ch <= L'/') || (ch >= L':' && ch <= L'@') || (ch >= L'G' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_11;} else if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'F')) {AddCh(); goto case_20;} else if (ch == 92) {AddCh(); goto case_14;} else if (ch == L'"') {AddCh(); goto case_3;} else {goto case_0;} case 19: case_19: if (ch == 10 || ch == 13) {AddCh(); goto case_2;} else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'&') || (ch >= L'(' && ch <= L'/') || (ch >= L':' && ch <= L'@') || (ch >= L'G' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_12;} else if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'F')) {AddCh(); goto case_21;} else if (ch == 92) {AddCh(); goto case_15;} else if (ch == 39) {AddCh(); goto case_3;} else {goto case_0;} case 20: case_20: if (ch == 10 || ch == 13) {AddCh(); goto case_2;} else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'!') || (ch >= L'#' && ch <= L'/') || (ch >= L':' && ch <= L'@') || (ch >= L'G' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_11;} else if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'F')) {AddCh(); goto case_22;} else if (ch == 92) {AddCh(); goto case_14;} else if (ch == L'"') {AddCh(); goto case_3;} else {goto case_0;} case 21: case_21: if (ch == 10 || ch == 13) {AddCh(); goto case_2;} else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'&') || (ch >= L'(' && ch <= L'/') || (ch >= L':' && ch <= L'@') || (ch >= L'G' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_12;} else if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'F')) {AddCh(); goto case_23;} else if (ch == 92) {AddCh(); goto case_15;} else if (ch == 39) {AddCh(); goto case_3;} else {goto case_0;} case 22: case_22: if (ch == 10 || ch == 13) {AddCh(); goto case_2;} else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'!') || (ch >= L'#' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_11;} else if (ch == 92) {AddCh(); goto case_14;} else if (ch == L'"') {AddCh(); goto case_3;} else {goto case_0;} case 23: case_23: if (ch == 10 || ch == 13) {AddCh(); goto case_2;} else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'&') || (ch >= L'(' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_12;} else if (ch == 92) {AddCh(); goto case_15;} else if (ch == 39) {AddCh(); goto case_3;} else {goto case_0;} case 24: {t->kind = 7; break;} case 25: {t->kind = 8; break;} case 26: case_26: {t->kind = 10; break;} case 27: case_27: {t->kind = 12; break;} case 28: {t->kind = 15; break;} case 29: {t->kind = 16; break;} case 30: {t->kind = 18; break;} case 31: {t->kind = 19; break;} case 32: {t->kind = 22; break;} case 33: case_33: {t->kind = 23; break;} case 34: {t->kind = 24; break;} case 35: {t->kind = 26; break;} case 36: {t->kind = 34; break;} case 37: {t->kind = 35; break;} case 38: {t->kind = 36; break;} case 39: case_39: {t->kind = 42; break;} case 40: {t->kind = 44; break;} case 41: {t->kind = 46; break;} case 42: {t->kind = 47; break;} case 43: {t->kind = 48; break;} case 44: {t->kind = 49; break;} case 45: {t->kind = 52; break;} case 46: recEnd = pos; recKind = 9; if (ch == L'=') {AddCh(); goto case_26;} else {t->kind = 9; break;} case 47: recEnd = pos; recKind = 11; if (ch == L'=') {AddCh(); goto case_27;} else {t->kind = 11; break;} case 48: recEnd = pos; recKind = 31; if (ch == L'=') {AddCh(); goto case_33;} else {t->kind = 31; break;} case 49: recEnd = pos; recKind = 45; if (ch == L'.') {AddCh(); goto case_39;} else {t->kind = 45; break;} } AppendVal(t); return t; }
void Scanner::Init() { EOL = '\n'; eofSym = 0; maxT = 67; noSym = 67; int i; for (i = 65; i <= 90; ++i) start.set(i, 1); for (i = 95; i <= 95; ++i) start.set(i, 1); for (i = 97; i <= 122; ++i) start.set(i, 1); for (i = 48; i <= 57; ++i) start.set(i, 10); start.set(34, 11); start.set(39, 12); start.set(61, 24); start.set(35, 25); start.set(60, 46); start.set(62, 47); start.set(43, 28); start.set(45, 29); start.set(42, 30); start.set(47, 31); start.set(38, 32); start.set(58, 48); start.set(44, 34); start.set(59, 35); start.set(94, 36); start.set(40, 37); start.set(41, 38); start.set(46, 49); start.set(126, 40); start.set(91, 41); start.set(93, 42); start.set(123, 43); start.set(125, 44); start.set(124, 45); start.set(Buffer::EoF, -1); keywords.set(L"IN", 13); keywords.set(L"IS", 14); keywords.set(L"OR", 17); keywords.set(L"DIV", 20); keywords.set(L"MOD", 21); keywords.set(L"IMPORT", 25); keywords.set(L"CONST", 27); keywords.set(L"TYPE", 28); keywords.set(L"VAR", 29); keywords.set(L"PROCEDURE", 30); keywords.set(L"BEGIN", 32); keywords.set(L"END", 33); keywords.set(L"OF", 37); keywords.set(L"ARRAY", 38); keywords.set(L"RECORD", 39); keywords.set(L"POINTER", 40); keywords.set(L"TO", 41); keywords.set(L"NIL", 43); keywords.set(L"ELSIF", 50); keywords.set(L"THEN", 51); keywords.set(L"DO", 53); keywords.set(L"IF", 54); keywords.set(L"ELSE", 55); keywords.set(L"CASE", 56); keywords.set(L"WHILE", 57); keywords.set(L"REPEAT", 58); keywords.set(L"UNTIL", 59); keywords.set(L"FOR", 60); keywords.set(L"BY", 61); keywords.set(L"LOOP", 62); keywords.set(L"WITH", 63); keywords.set(L"EXIT", 64); keywords.set(L"RETURN", 65); keywords.set(L"MODULE", 66); tvalLength = 128; tval = new wchar_t[tvalLength]; // text of current token // COCO_HEAP_BLOCK_SIZE byte heap + pointer to next heap block heap = malloc(COCO_HEAP_BLOCK_SIZE + sizeof(void*)); firstHeap = heap; heapEnd = (void**) (((char*) heap) + COCO_HEAP_BLOCK_SIZE); *heapEnd = 0; heapTop = heap; if (sizeof(Token) > COCO_HEAP_BLOCK_SIZE) { wprintf(L"--- Too small COCO_HEAP_BLOCK_SIZE\n"); exit(1); } pos = -1; line = 1; col = 0; charPos = -1; oldEols = 0; NextCh(); if (ch == 0xEF) { // check optional byte order mark for UTF-8 NextCh(); int ch1 = ch; NextCh(); int ch2 = ch; if (ch1 != 0xBB || ch2 != 0xBF) { wprintf(L"Illegal byte order mark at start of file"); exit(1); } Buffer *oldBuf = buffer; buffer = new UTF8Buffer(buffer); col = 0; charPos = -1; delete oldBuf; oldBuf = NULL; NextCh(); } pt = tokens = CreateToken(); // first token is a dummy }
Token* Scanner::NextToken() { while (ch == ' ' || ch == 13 ) NextCh(); if ((ch == L'/' && Comment0())) return NextToken(); int recKind = noSym; int recEnd = pos; t = CreateToken(); t->pos = pos; t->col = col; t->line = line; t->charPos = charPos; int state = start.state(ch); tlen = 0; AddCh(); switch (state) { case -1: { t->kind = eofSym; break; } // NextCh already done case 0: { case_0: if (recKind != noSym) { tlen = recEnd - t->pos; SetScannerBehindT(); } t->kind = recKind; break; } // NextCh already done case 1: case_1: recEnd = pos; recKind = 1; if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'Z') || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_1;} else {t->kind = 1; wchar_t *literal = coco_string_create(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;} case 2: case_2: if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_3;} else {goto case_0;} case 3: case_3: recEnd = pos; recKind = 3; if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_3;} else {t->kind = 3; break;} case 4: case_4: if (ch == L' ' || (ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'Z') || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_4;} else if (ch == L'"') {AddCh(); goto case_5;} else {goto case_0;} case 5: case_5: {t->kind = 4; break;} case 6: if ((ch >= L'A' && ch <= L'Z') || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_7;} else {goto case_0;} case 7: case_7: if (ch == 39) {AddCh(); goto case_8;} else {goto case_0;} case 8: case_8: {t->kind = 5; break;} case 9: {t->kind = 6; break;} case 10: case_10: if (ch == L'e') {AddCh(); goto case_11;} else {goto case_0;} case 11: case_11: if (ch == L'l') {AddCh(); goto case_12;} else {goto case_0;} case 12: case_12: if (ch == L'o') {AddCh(); goto case_13;} else {goto case_0;} case 13: case_13: if (ch == L'c') {AddCh(); goto case_14;} else {goto case_0;} case 14: case_14: if (ch == L'i') {AddCh(); goto case_15;} else {goto case_0;} case 15: case_15: if (ch == L'd') {AddCh(); goto case_16;} else {goto case_0;} case 16: case_16: if (ch == L'a') {AddCh(); goto case_17;} else {goto case_0;} case 17: case_17: if (ch == L'd') {AddCh(); goto case_26;} else {goto case_0;} case 18: case_18: if (ch == L'i') {AddCh(); goto case_19;} else {goto case_0;} case 19: case_19: if (ch == L'r') {AddCh(); goto case_20;} else {goto case_0;} case 20: case_20: if (ch == L'e') {AddCh(); goto case_21;} else {goto case_0;} case 21: case_21: if (ch == L'c') {AddCh(); goto case_22;} else {goto case_0;} case 22: case_22: if (ch == L'c') {AddCh(); goto case_23;} else {goto case_0;} case 23: case_23: if (ch == L'i') {AddCh(); goto case_24;} else {goto case_0;} case 24: case_24: if (ch == L'o') {AddCh(); goto case_25;} else {goto case_0;} case 25: case_25: if (ch == L'n') {AddCh(); goto case_26;} else {goto case_0;} case 26: case_26: {t->kind = 7; break;} case 27: case_27: if (ch == L'e') {AddCh(); goto case_28;} else {goto case_0;} case 28: case_28: if (ch == L'c') {AddCh(); goto case_29;} else {goto case_0;} case 29: case_29: if (ch == L't') {AddCh(); goto case_30;} else {goto case_0;} case 30: case_30: if (ch == L'u') {AddCh(); goto case_31;} else {goto case_0;} case 31: case_31: if (ch == L'r') {AddCh(); goto case_32;} else {goto case_0;} case 32: case_32: if (ch == L'a') {AddCh(); goto case_33;} else {goto case_0;} case 33: case_33: {t->kind = 8; break;} case 34: case_34: if (ch == L'c') {AddCh(); goto case_35;} else {goto case_0;} case 35: case_35: if (ch == L'e') {AddCh(); goto case_36;} else {goto case_0;} case 36: case_36: if (ch == L'n') {AddCh(); goto case_37;} else {goto case_0;} case 37: case_37: if (ch == L'd') {AddCh(); goto case_38;} else {goto case_0;} case 38: case_38: if (ch == L'i') {AddCh(); goto case_39;} else {goto case_0;} case 39: case_39: if (ch == L'd') {AddCh(); goto case_40;} else {goto case_0;} case 40: case_40: if (ch == L'o') {AddCh(); goto case_41;} else {goto case_0;} case 41: case_41: {t->kind = 9; break;} case 42: case_42: if (ch == L'm') {AddCh(); goto case_43;} else {goto case_0;} case 43: case_43: if (ch == L'p') {AddCh(); goto case_44;} else {goto case_0;} case 44: case_44: if (ch == L'r') {AddCh(); goto case_45;} else {goto case_0;} case 45: case_45: if (ch == L'i') {AddCh(); goto case_46;} else {goto case_0;} case 46: case_46: if (ch == L'm') {AddCh(); goto case_47;} else {goto case_0;} case 47: case_47: if (ch == L'e') {AddCh(); goto case_48;} else {goto case_0;} case 48: case_48: {t->kind = 10; break;} case 49: case_49: if (ch == L'n') {AddCh(); goto case_50;} else {goto case_0;} case 50: case_50: if (ch == L'g') {AddCh(); goto case_51;} else {goto case_0;} case 51: case_51: if (ch == L'u') {AddCh(); goto case_52;} else {goto case_0;} case 52: case_52: if (ch == L'l') {AddCh(); goto case_53;} else {goto case_0;} case 53: case_53: if (ch == L'o') {AddCh(); goto case_54;} else {goto case_0;} case 54: case_54: {t->kind = 11; break;} case 55: case_55: if (ch == L't') {AddCh(); goto case_56;} else {goto case_0;} case 56: case_56: if (ch == L'a') {AddCh(); goto case_57;} else {goto case_0;} case 57: case_57: if (ch == L'd') {AddCh(); goto case_58;} else {goto case_0;} case 58: case_58: if (ch == L'o') {AddCh(); goto case_59;} else {goto case_0;} case 59: case_59: {t->kind = 12; break;} case 60: case_60: recEnd = pos; recKind = 13; if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_60;} else {t->kind = 13; break;} case 61: case_61: recEnd = pos; recKind = 2; if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_61;} else if (ch == L'.') {AddCh(); goto case_2;} else {t->kind = 2; break;} case 62: if (ch == L'v') {AddCh(); goto case_10;} else if (ch == L'd') {AddCh(); goto case_18;} else if (ch == L'l') {AddCh(); goto case_27;} else if (ch == L'e') {AddCh(); goto case_63;} else if (ch == L'i') {AddCh(); goto case_42;} else if (ch == L'a') {AddCh(); goto case_49;} else {goto case_0;} case 63: case_63: if (ch == L'n') {AddCh(); goto case_34;} else if (ch == L's') {AddCh(); goto case_55;} else {goto case_0;} case 64: if (ch == L'O') {AddCh(); goto case_65;} else {goto case_0;} case 65: case_65: if (ch == L'N') {AddCh(); goto case_66;} else {goto case_0;} case 66: case_66: if (ch == L'F') {AddCh(); goto case_67;} else {goto case_0;} case 67: case_67: if (ch == L'I') {AddCh(); goto case_68;} else {goto case_0;} case 68: case_68: if (ch == L'G') {AddCh(); goto case_69;} else {goto case_0;} case 69: case_69: {t->kind = 14; break;} case 70: {t->kind = 15; break;} case 71: {t->kind = 16; break;} case 72: case_72: {t->kind = 17; break;} case 73: if (ch == L'U') {AddCh(); goto case_74;} else {goto case_0;} case 74: case_74: if (ch == L'N') {AddCh(); goto case_75;} else {goto case_0;} case 75: case_75: if (ch == L'C') {AddCh(); goto case_76;} else {goto case_0;} case 76: case_76: if (ch == L'I') {AddCh(); goto case_77;} else {goto case_0;} case 77: case_77: if (ch == L'O') {AddCh(); goto case_78;} else {goto case_0;} case 78: case_78: if (ch == L'N') {AddCh(); goto case_79;} else {goto case_0;} case 79: case_79: if (ch == L'E') {AddCh(); goto case_80;} else {goto case_0;} case 80: case_80: if (ch == L'S') {AddCh(); goto case_81;} else {goto case_0;} case 81: case_81: {t->kind = 18; break;} case 82: if (ch == L'R') {AddCh(); goto case_83;} else {goto case_0;} case 83: case_83: if (ch == L'O') {AddCh(); goto case_84;} else {goto case_0;} case 84: case_84: if (ch == L'G') {AddCh(); goto case_85;} else {goto case_0;} case 85: case_85: if (ch == L'R') {AddCh(); goto case_86;} else {goto case_0;} case 86: case_86: if (ch == L'A') {AddCh(); goto case_87;} else {goto case_0;} case 87: case_87: if (ch == L'M') {AddCh(); goto case_88;} else {goto case_0;} case 88: case_88: if (ch == L'A') {AddCh(); goto case_89;} else {goto case_0;} case 89: case_89: {t->kind = 19; break;} case 90: {t->kind = 26; break;} case 91: {t->kind = 34; break;} case 92: {t->kind = 35; break;} case 93: case_93: {t->kind = 36; break;} case 94: {t->kind = 37; break;} case 95: case_95: {t->kind = 49; break;} case 96: case_96: {t->kind = 52; break;} case 97: case_97: {t->kind = 53; break;} case 98: if (ch == L'=') {AddCh(); goto case_99;} else {goto case_0;} case 99: case_99: {t->kind = 54; break;} case 100: {t->kind = 55; break;} case 101: {t->kind = 56; break;} case 102: {t->kind = 57; break;} case 103: {t->kind = 58; break;} case 104: {t->kind = 59; break;} case 105: {t->kind = 60; break;} case 106: if (ch == L'A') {AddCh(); goto case_109;} else {goto case_0;} case 107: recEnd = pos; recKind = 51; if (ch == L'-') {AddCh(); goto case_95;} else if (ch == L'=') {AddCh(); goto case_96;} else {t->kind = 51; break;} case 108: recEnd = pos; recKind = 50; if (ch == L'=') {AddCh(); goto case_97;} else {t->kind = 50; break;} case 109: case_109: if (ch == L'R') {AddCh(); goto case_110;} else {goto case_0;} case 110: case_110: if (ch == L'G') {AddCh(); goto case_72;} else if (ch == L'F') {AddCh(); goto case_93;} else {goto case_0;} } AppendVal(t); return t; }
Token* Scanner::NextToken() { while (ch == ' ' || ch == 10 || ch == 13 ) NextCh(); int recKind = noSym; int recEnd = pos; t = CreateToken(); t->pos = pos; t->col = col; t->line = line; int state = start.state(ch); tlen = 0; AddCh(); switch (state) { case -1: { t->kind = eofSym; break; } // NextCh already done case 0: { case_0: if (recKind != noSym) { tlen = recEnd - t->pos; SetScannerBehindT(); } t->kind = recKind; break; } // NextCh already done case 1: case_1: if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'Z') || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_1;} else {t->kind = 1; wchar_t *literal = coco_string_create(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;} case 2: case_2: if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_2;} else {t->kind = 2; break;} case 3: case_3: if (ch == L'e') {AddCh(); goto case_4;} else {t->kind = noSym; break;} case 4: case_4: if (ch == L'x') {AddCh(); goto case_5;} else {t->kind = noSym; break;} case 5: case_5: if (ch == L';') {AddCh(); goto case_6;} else {t->kind = noSym; break;} case 6: case_6: {t->kind = 4; break;} case 7: case_7: if (ch == L'c') {AddCh(); goto case_8;} else {t->kind = noSym; break;} case 8: case_8: if (ch == L't') {AddCh(); goto case_9;} else {t->kind = noSym; break;} case 9: case_9: if (ch == L';') {AddCh(); goto case_10;} else {t->kind = noSym; break;} case 10: case_10: {t->kind = 5; break;} case 11: {t->kind = 6; break;} case 12: case_12: {t->kind = 7; break;} case 13: {t->kind = 9; break;} case 14: {t->kind = 10; break;} case 15: {t->kind = 11; break;} case 16: {t->kind = 13; break;} case 17: {t->kind = 14; break;} case 18: {t->kind = 15; break;} case 19: if (ch == L'h') {AddCh(); goto case_3;} else if (ch == L'o') {AddCh(); goto case_7;} else if (ch == L'=') {AddCh(); goto case_12;} else {t->kind = noSym; break;} } AppendVal(t); return t; }
Token* Scanner::NextToken() { while (ch == ' ' || (ch >= 9 && ch <= 10) || ch == 13 ) NextCh(); if ((ch == L'/' && Comment0()) || (ch == L'/' && Comment1())) return NextToken(); int recKind = noSym; int recEnd = pos; t = CreateToken(); t->pos = pos; t->col = col; t->line = line; t->charPos = charPos; int state = start.state(ch); tlen = 0; AddCh(); switch (state) { case -1: { t->kind = eofSym; break; } // NextCh already done case 0: { case_0: if (recKind != noSym) { tlen = recEnd - t->pos; SetScannerBehindT(); } t->kind = recKind; break; } // NextCh already done case 1: case_1: recEnd = pos; recKind = 1; if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_1;} else {t->kind = 1; wchar_t *literal = coco_string_create(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;} case 2: case_2: recEnd = pos; recKind = 2; if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_2;} else {t->kind = 2; break;} case 3: case_3: {t->kind = 3; break;} case 4: case_4: {t->kind = 4; break;} case 5: if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'&') || (ch >= L'(' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_6;} else if (ch == 92) {AddCh(); goto case_7;} else {goto case_0;} case 6: case_6: if (ch == 39) {AddCh(); goto case_9;} else {goto case_0;} case 7: case_7: if ((ch >= L' ' && ch <= L'~')) {AddCh(); goto case_8;} else {goto case_0;} case 8: case_8: if ((ch >= L'0' && ch <= L'9') || (ch >= L'a' && ch <= L'f')) {AddCh(); goto case_8;} else if (ch == 39) {AddCh(); goto case_9;} else {goto case_0;} case 9: case_9: {t->kind = 5; break;} case 10: case_10: recEnd = pos; recKind = 42; if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_10;} else {t->kind = 42; break;} case 11: case_11: recEnd = pos; recKind = 43; if ((ch >= L'-' && ch <= L'.') || (ch >= L'0' && ch <= L':') || (ch >= L'A' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_11;} else {t->kind = 43; break;} case 12: case_12: if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'!') || (ch >= L'#' && ch <= L'[') || (ch >= L']' && ch <= 65535)) {AddCh(); goto case_12;} else if (ch == 10 || ch == 13) {AddCh(); goto case_4;} else if (ch == L'"') {AddCh(); goto case_3;} else if (ch == 92) {AddCh(); goto case_14;} else {goto case_0;} case 13: recEnd = pos; recKind = 42; if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_10;} else if ((ch >= L'A' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_15;} else {t->kind = 42; break;} case 14: case_14: if ((ch >= L' ' && ch <= L'~')) {AddCh(); goto case_12;} else {goto case_0;} case 15: case_15: recEnd = pos; recKind = 42; if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_10;} else if ((ch >= L'A' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_15;} else if (ch == L'=') {AddCh(); goto case_11;} else {t->kind = 42; break;} case 16: {t->kind = 17; break;} case 17: {t->kind = 20; break;} case 18: {t->kind = 21; break;} case 19: case_19: {t->kind = 22; break;} case 20: {t->kind = 25; break;} case 21: case_21: {t->kind = 26; break;} case 22: case_22: {t->kind = 27; break;} case 23: {t->kind = 28; break;} case 24: {t->kind = 31; break;} case 25: {t->kind = 32; break;} case 26: {t->kind = 33; break;} case 27: {t->kind = 34; break;} case 28: {t->kind = 35; break;} case 29: case_29: {t->kind = 39; break;} case 30: case_30: {t->kind = 40; break;} case 31: recEnd = pos; recKind = 18; if (ch == L'.') {AddCh(); goto case_19;} else if (ch == L'>') {AddCh(); goto case_22;} else if (ch == L')') {AddCh(); goto case_30;} else {t->kind = 18; break;} case 32: recEnd = pos; recKind = 24; if (ch == L'.') {AddCh(); goto case_21;} else {t->kind = 24; break;} case 33: recEnd = pos; recKind = 30; if (ch == L'.') {AddCh(); goto case_29;} else {t->kind = 30; break;} } AppendVal(t); return t; }
void Scanner::Init() { EOL = '\n'; eofSym = 0; maxT = 54; noSym = 54; int i; for (i = 65; i <= 90; ++i) start.set(i, 1); for (i = 97; i <= 122; ++i) start.set(i, 1); for (i = 48; i <= 57; ++i) start.set(i, 29); start.set(39, 2); start.set(34, 5); start.set(46, 30); start.set(38, 9); start.set(124, 11); start.set(60, 31); start.set(62, 32); start.set(33, 33); start.set(61, 34); start.set(43, 17); start.set(45, 18); start.set(42, 19); start.set(47, 20); start.set(59, 21); start.set(44, 22); start.set(123, 23); start.set(125, 24); start.set(40, 25); start.set(41, 26); start.set(91, 27); start.set(93, 28); start.set(Buffer::EoF, -1); keywords.set(L"int", 6); keywords.set(L"char", 7); keywords.set(L"string", 8); keywords.set(L"if", 9); keywords.set(L"while", 10); keywords.set(L"bool", 11); keywords.set(L"double", 12); keywords.set(L"extends", 13); keywords.set(L"this", 14); keywords.set(L"else", 15); keywords.set(L"false", 16); keywords.set(L"true", 17); keywords.set(L"class", 18); keywords.set(L"for", 19); keywords.set(L"do", 20); keywords.set(L"void", 21); keywords.set(L"return", 22); keywords.set(L"new", 23); keywords.set(L"null", 24); keywords.set(L"super", 25); keywords.set(L"write", 26); keywords.set(L"main", 27); keywords.set(L"ftw", 28); keywords.set(L"read", 29); keywords.set(L"function", 53); tvalLength = 128; tval = new wchar_t[tvalLength]; // text of current token // COCO_HEAP_BLOCK_SIZE byte heap + pointer to next heap block heap = malloc(COCO_HEAP_BLOCK_SIZE + sizeof(void*)); firstHeap = heap; heapEnd = (void**) (((char*) heap) + COCO_HEAP_BLOCK_SIZE); *heapEnd = 0; heapTop = heap; if (sizeof(Token) > COCO_HEAP_BLOCK_SIZE) { wprintf(L"--- Too small COCO_HEAP_BLOCK_SIZE\n"); exit(1); } pos = -1; line = 1; col = 0; charPos = -1; oldEols = 0; NextCh(); if (ch == 0xEF) { // check optional byte order mark for UTF-8 NextCh(); int ch1 = ch; NextCh(); int ch2 = ch; if (ch1 != 0xBB || ch2 != 0xBF) { wprintf(L"Illegal byte order mark at start of file"); exit(1); } Buffer *oldBuf = buffer; buffer = new UTF8Buffer(buffer); col = 0; charPos = -1; delete oldBuf; oldBuf = NULL; NextCh(); } pt = tokens = CreateToken(); // first token is a dummy }
Token* Scanner::NextToken() { while (ch == ' ' || (ch >= 9 && ch <= 10) || ch == 13 ) NextCh(); if ((ch == L'/' && Comment0()) || (ch == L'/' && Comment1()) || (ch == L'/' && Comment2())) return NextToken(); int recKind = noSym; int recEnd = pos; t = CreateToken(); t->pos = pos; t->col = col; t->line = line; t->charPos = charPos; int state = start.state(ch); tlen = 0; AddCh(); switch (state) { case -1: { t->kind = eofSym; // NextCh already done break; } case 0: { case_0: if (recKind != noSym) { tlen = recEnd - t->pos; SetScannerBehindT(); } t->kind = recKind; break; } // NextCh already done case 1: case_1: recEnd = pos; recKind = 1; if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) { AddCh(); goto case_1; } else { t->kind = 1; wchar_t *literal = coco_string_create(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break; } case 2: case_2: recEnd = pos; recKind = 2; if ((ch >= L'0' && ch <= L'9')) { AddCh(); goto case_2; } else if (ch == L'F' || ch == L'L' || ch == L'f' || ch == L'l') { AddCh(); goto case_13; } else if (ch == L'E' || ch == L'e') { AddCh(); goto case_3; } else { t->kind = 2; break; } case 3: case_3: if ((ch >= L'0' && ch <= L'9')) { AddCh(); goto case_5; } else if (ch == L'+' || ch == L'-') { AddCh(); goto case_4; } else { goto case_0; } case 4: case_4: if ((ch >= L'0' && ch <= L'9')) { AddCh(); goto case_5; } else { goto case_0; } case 5: case_5: recEnd = pos; recKind = 2; if ((ch >= L'0' && ch <= L'9')) { AddCh(); goto case_5; } else if (ch == L'F' || ch == L'L' || ch == L'f' || ch == L'l') { AddCh(); goto case_13; } else { t->kind = 2; break; } case 6: case_6: recEnd = pos; recKind = 2; if ((ch >= L'0' && ch <= L'9')) { AddCh(); goto case_6; } else if (ch == L'F' || ch == L'L' || ch == L'f' || ch == L'l') { AddCh(); goto case_13; } else if (ch == L'E' || ch == L'e') { AddCh(); goto case_7; } else { t->kind = 2; break; } case 7: case_7: if ((ch >= L'0' && ch <= L'9')) { AddCh(); goto case_9; } else if (ch == L'+' || ch == L'-') { AddCh(); goto case_8; } else { goto case_0; } case 8: case_8: if ((ch >= L'0' && ch <= L'9')) { AddCh(); goto case_9; } else { goto case_0; } case 9: case_9: recEnd = pos; recKind = 2; if ((ch >= L'0' && ch <= L'9')) { AddCh(); goto case_9; } else if (ch == L'F' || ch == L'L' || ch == L'f' || ch == L'l') { AddCh(); goto case_13; } else { t->kind = 2; break; } case 10: case_10: if ((ch >= L'0' && ch <= L'9')) { AddCh(); goto case_12; } else if (ch == L'+' || ch == L'-') { AddCh(); goto case_11; } else { goto case_0; } case 11: case_11: if ((ch >= L'0' && ch <= L'9')) { AddCh(); goto case_12; } else { goto case_0; } case 12: case_12: recEnd = pos; recKind = 2; if ((ch >= L'0' && ch <= L'9')) { AddCh(); goto case_12; } else if (ch == L'F' || ch == L'L' || ch == L'f' || ch == L'l') { AddCh(); goto case_13; } else { t->kind = 2; break; } case 13: case_13: { t->kind = 2; break; } case 14: case_14: recEnd = pos; recKind = 3; if (ch == L'L' || ch == L'U' || ch == L'l' || ch == L'u') { AddCh(); goto case_14; } else { t->kind = 3; break; } case 15: case_15: if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'F') || (ch >= L'a' && ch <= L'f')) { AddCh(); goto case_16; } else { goto case_0; } case 16: case_16: recEnd = pos; recKind = 3; if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'F') || (ch >= L'a' && ch <= L'f')) { AddCh(); goto case_16; } else if (ch == L'L' || ch == L'U' || ch == L'l' || ch == L'u') { AddCh(); goto case_14; } else { t->kind = 3; break; } case 17: if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'&') || (ch >= L'(' && ch <= 65535)) { AddCh(); goto case_18; } else { goto case_0; } case 18: case_18: if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'&') || (ch >= L'(' && ch <= 65535)) { AddCh(); goto case_18; } else if (ch == 39) { AddCh(); goto case_19; } else { goto case_0; } case 19: case_19: { t->kind = 4; break; } case 20: case_20: if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= L'!') || (ch >= L'#' && ch <= 65535)) { AddCh(); goto case_20; } else if (ch == L'"') { AddCh(); goto case_21; } else { goto case_0; } case 21: case_21: { t->kind = 5; break; } case 22: { t->kind = 25; break; } case 23: { t->kind = 26; break; } case 24: { t->kind = 27; break; } case 25: { t->kind = 28; break; } case 26: { t->kind = 29; break; } case 27: { t->kind = 30; break; } case 28: { t->kind = 31; break; } case 29: { t->kind = 32; break; } case 30: { t->kind = 33; break; } case 31: { t->kind = 34; break; } case 32: case_32: if (ch == L'.') { AddCh(); goto case_33; } else { goto case_0; } case 33: case_33: { t->kind = 35; break; } case 34: case_34: if (ch == L'e') { AddCh(); goto case_35; } else { goto case_0; } case 35: case_35: if (ch == L'f') { AddCh(); goto case_36; } else { goto case_0; } case 36: case_36: if (ch == L'i') { AddCh(); goto case_37; } else { goto case_0; } case 37: case_37: if (ch == L'n') { AddCh(); goto case_38; } else { goto case_0; } case 38: case_38: if (ch == L'e') { AddCh(); goto case_39; } else { goto case_0; } case 39: case_39: if (ch == 10 || ch == 13) { AddCh(); goto case_40; } else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= 65535)) { AddCh(); goto case_39; } else { goto case_0; } case 40: case_40: { t->kind = 110; break; } case 41: case_41: if (ch == L'n') { AddCh(); goto case_42; } else { goto case_0; } case 42: case_42: if (ch == L'd') { AddCh(); goto case_43; } else { goto case_0; } case 43: case_43: if (ch == L'e') { AddCh(); goto case_44; } else { goto case_0; } case 44: case_44: if (ch == L'f') { AddCh(); goto case_45; } else { goto case_0; } case 45: case_45: if (ch == 10 || ch == 13) { AddCh(); goto case_46; } else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= 65535)) { AddCh(); goto case_45; } else { goto case_0; } case 46: case_46: { t->kind = 111; break; } case 47: case_47: if (ch == 10 || ch == 13) { AddCh(); goto case_48; } else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= 65535)) { AddCh(); goto case_47; } else { goto case_0; } case 48: case_48: { t->kind = 112; break; } case 49: case_49: if (ch == L'f') { AddCh(); goto case_50; } else { goto case_0; } case 50: case_50: if (ch == 10 || ch == 13) { AddCh(); goto case_51; } else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= 65535)) { AddCh(); goto case_50; } else { goto case_0; } case 51: case_51: { t->kind = 113; break; } case 52: case_52: if (ch == L'e') { AddCh(); goto case_53; } else { goto case_0; } case 53: case_53: if (ch == 10 || ch == 13) { AddCh(); goto case_54; } else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= 65535)) { AddCh(); goto case_53; } else { goto case_0; } case 54: case_54: { t->kind = 114; break; } case 55: case_55: if (ch == L'd') { AddCh(); goto case_56; } else { goto case_0; } case 56: case_56: if (ch == L'i') { AddCh(); goto case_57; } else { goto case_0; } case 57: case_57: if (ch == L'f') { AddCh(); goto case_58; } else { goto case_0; } case 58: case_58: if (ch == 10 || ch == 13) { AddCh(); goto case_59; } else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= 65535)) { AddCh(); goto case_58; } else { goto case_0; } case 59: case_59: { t->kind = 115; break; } case 60: case_60: if (ch == L'c') { AddCh(); goto case_61; } else { goto case_0; } case 61: case_61: if (ch == L'l') { AddCh(); goto case_62; } else { goto case_0; } case 62: case_62: if (ch == L'u') { AddCh(); goto case_63; } else { goto case_0; } case 63: case_63: if (ch == L'd') { AddCh(); goto case_64; } else { goto case_0; } case 64: case_64: if (ch == L'e') { AddCh(); goto case_65; } else { goto case_0; } case 65: case_65: if (ch == 10 || ch == 13) { AddCh(); goto case_66; } else if (ch <= 9 || (ch >= 11 && ch <= 12) || (ch >= 14 && ch <= 65535)) { AddCh(); goto case_65; } else { goto case_0; } case 66: case_66: { t->kind = 116; break; } case 67: recEnd = pos; recKind = 3; if ((ch >= L'8' && ch <= L'9')) { AddCh(); goto case_71; } else if ((ch >= L'0' && ch <= L'7')) { AddCh(); goto case_72; } else if (ch == L'.') { AddCh(); goto case_6; } else if (ch == L'E' || ch == L'e') { AddCh(); goto case_10; } else if (ch == L'L' || ch == L'U' || ch == L'l' || ch == L'u') { AddCh(); goto case_14; } else if (ch == L'X' || ch == L'x') { AddCh(); goto case_15; } else { t->kind = 3; break; } case 68: case_68: recEnd = pos; recKind = 3; if ((ch >= L'0' && ch <= L'9')) { AddCh(); goto case_68; } else if (ch == L'.') { AddCh(); goto case_6; } else if (ch == L'E' || ch == L'e') { AddCh(); goto case_10; } else if (ch == L'L' || ch == L'U' || ch == L'l' || ch == L'u') { AddCh(); goto case_14; } else { t->kind = 3; break; } case 69: if ((ch >= L'0' && ch <= L'9')) { AddCh(); goto case_2; } else if (ch == L'.') { AddCh(); goto case_32; } else { goto case_0; } case 70: case_70: if (ch == 9 || (ch >= 11 && ch <= 12) || ch == L' ') { AddCh(); goto case_70; } else if (ch == L'd') { AddCh(); goto case_34; } else if (ch == L'u') { AddCh(); goto case_41; } else if (ch == L'i') { AddCh(); goto case_73; } else if (ch == L'e') { AddCh(); goto case_74; } else { goto case_0; } case 71: case_71: if ((ch >= L'0' && ch <= L'9')) { AddCh(); goto case_71; } else if (ch == L'.') { AddCh(); goto case_6; } else if (ch == L'E' || ch == L'e') { AddCh(); goto case_10; } else { goto case_0; } case 72: case_72: recEnd = pos; recKind = 3; if ((ch >= L'8' && ch <= L'9')) { AddCh(); goto case_71; } else if ((ch >= L'0' && ch <= L'7')) { AddCh(); goto case_72; } else if (ch == L'.') { AddCh(); goto case_6; } else if (ch == L'E' || ch == L'e') { AddCh(); goto case_10; } else if (ch == L'L' || ch == L'U' || ch == L'l' || ch == L'u') { AddCh(); goto case_14; } else { t->kind = 3; break; } case 73: case_73: if (ch == L'f') { AddCh(); goto case_47; } else if (ch == L'n') { AddCh(); goto case_60; } else { goto case_0; } case 74: case_74: if (ch == L'l') { AddCh(); goto case_75; } else if (ch == L'n') { AddCh(); goto case_55; } else { goto case_0; } case 75: case_75: if (ch == L'i') { AddCh(); goto case_49; } else if (ch == L's') { AddCh(); goto case_52; } else { goto case_0; } case 76: case_76: { t->kind = 93; break; } case 77: { t->kind = 96; break; } case 78: { t->kind = 99; break; } case 79: { t->kind = 100; break; } case 80: recEnd = pos; recKind = 1; if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'F') || (ch >= L'H' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) { AddCh(); goto case_1; } else if (ch == L'G') { AddCh(); goto case_81; } else { t->kind = 1; wchar_t *literal = coco_string_create(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break; } case 81: case_81: recEnd = pos; recKind = 1; if ((ch >= L'0' && ch <= L'9') || ch == L'A' || (ch >= L'C' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) { AddCh(); goto case_1; } else if (ch == L'B') { AddCh(); goto case_82; } else { t->kind = 1; wchar_t *literal = coco_string_create(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break; } case 82: case_82: recEnd = pos; recKind = 1; if ((ch >= L'0' && ch <= L'9') || (ch >= L'B' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) { AddCh(); goto case_1; } else if (ch == L'A') { AddCh(); goto case_83; } else { t->kind = 1; wchar_t *literal = coco_string_create(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break; } case 83: case_83: recEnd = pos; recKind = 1; if ((ch >= L'0' && ch <= L'9') || (ch >= L'A' && ch <= L'Z') || ch == L'_' || (ch >= L'a' && ch <= L'z')) { AddCh(); goto case_1; } else if (ch == L'(') { AddCh(); goto case_76; } else { t->kind = 1; wchar_t *literal = coco_string_create(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break; } } AppendVal(t); return t; }
void Scanner::Init() { EOL = '\n'; eofSym = 0; maxT = 64; noSym = 64; int i; for (i = 48; i <= 57; ++i) start.set(i, 7); for (i = 65; i <= 90; ++i) start.set(i, 6); for (i = 97; i <= 122; ++i) start.set(i, 6); start.set(34, 3); start.set(123, 8); start.set(125, 9); start.set(44, 10); start.set(59, 11); start.set(91, 12); start.set(46, 13); start.set(93, 15); start.set(40, 16); start.set(41, 17); start.set(45, 18); start.set(43, 19); start.set(61, 29); start.set(124, 20); start.set(58, 21); start.set(60, 30); start.set(62, 31); start.set(42, 26); start.set(47, 27); start.set(37, 28); start.set(Buffer::EoF, -1); keywords.set(L"program", 5); keywords.set(L"global", 8); keywords.set(L"int", 14); keywords.set(L"float", 15); keywords.set(L"main", 16); keywords.set(L"module", 19); keywords.set(L"void", 20); keywords.set(L"return", 21); keywords.set(L"if", 24); keywords.set(L"else", 25); keywords.set(L"while", 27); keywords.set(L"do", 28); keywords.set(L"read", 29); keywords.set(L"print", 30); keywords.set(L"draw", 32); keywords.set(L"end", 34); keywords.set(L"point", 35); keywords.set(L"line", 36); keywords.set(L"triangle", 37); keywords.set(L"square", 38); keywords.set(L"circle", 39); keywords.set(L"star", 40); keywords.set(L"pentagon", 41); keywords.set(L"hexagon", 42); keywords.set(L"rhomboid", 43); keywords.set(L"x_position", 44); keywords.set(L"y_position", 45); keywords.set(L"rotate", 46); keywords.set(L"sizeX", 47); keywords.set(L"sizeY", 48); keywords.set(L"size", 49); keywords.set(L"thick", 50); keywords.set(L"colorThick", 51); keywords.set(L"colorFigure", 52); keywords.set(L"and", 59); keywords.set(L"or", 60); tvalLength = 128; tval = new wchar_t[tvalLength]; // text of current token // COCO_HEAP_BLOCK_SIZE byte heap + pointer to next heap block heap = malloc(COCO_HEAP_BLOCK_SIZE + sizeof(void*)); firstHeap = heap; heapEnd = (void**) (((char*) heap) + COCO_HEAP_BLOCK_SIZE); *heapEnd = 0; heapTop = heap; if (sizeof(Token) > COCO_HEAP_BLOCK_SIZE) { wprintf(L"--- Too small COCO_HEAP_BLOCK_SIZE\n"); exit(1); } pos = -1; line = 1; col = 0; charPos = -1; oldEols = 0; NextCh(); if (ch == 0xEF) { // check optional byte order mark for UTF-8 NextCh(); int ch1 = ch; NextCh(); int ch2 = ch; if (ch1 != 0xBB || ch2 != 0xBF) { wprintf(L"Illegal byte order mark at start of file"); exit(1); } Buffer *oldBuf = buffer; buffer = new UTF8Buffer(buffer); col = 0; charPos = -1; delete oldBuf; oldBuf = NULL; NextCh(); } pt = tokens = CreateToken(); // first token is a dummy }
Token* Scanner::NextToken() { while (ch == ' ' || false ) NextCh(); t = CreateToken(); t->pos = pos; t->col = col; t->line = line; int state = start.state(ch); tlen = 0; AddCh(); switch (state) { case -1: { t->kind = eofSym; break; } // NextCh already done case 0: { t->kind = noSym; break; } // NextCh already done case 1: case_1: if ((ch >= L'0' && ch <= L'9') || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_1;} else {t->kind = 1; wchar_t *literal = coco_string_create_lower(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;} case 2: if (ch <= L'&' || (ch >= L'(' && ch <= 65535)) {AddCh(); goto case_3;} else {t->kind = noSym; break;} case 3: case_3: if (ch <= L'&' || (ch >= L'(' && ch <= 65535)) {AddCh(); goto case_3;} else if (ch == 39) {AddCh(); goto case_4;} else {t->kind = noSym; break;} case 4: case_4: {t->kind = 2; break;} case 5: case_5: if ((ch >= L'0' && ch <= L'9')) {AddCh(); goto case_5;} else {t->kind = 3; break;} case 6: if (ch == L'=') {AddCh(); goto case_7;} else {t->kind = noSym; break;} case 7: case_7: {t->kind = 4; break;} case 8: if (ch == L'=') {AddCh(); goto case_7;} else {t->kind = 4; break;} case 9: if (ch == L'=') {AddCh(); goto case_7;} else {t->kind = 4; break;} case 10: {t->kind = 5; break;} case 11: {t->kind = 8; break;} case 12: {t->kind = 9; break;} case 13: {t->kind = 10; break;} case 14: case_14: {t->kind = 20; break;} case 15: case_15: {t->kind = 21; break;} case 16: {t->kind = 26; break;} case 17: if (ch == L'=') {AddCh(); goto case_7;} else {t->kind = 31; break;} case 18: if ((ch >= L'0' && ch <= L'9') || (ch >= L'a' && ch <= L'g') || (ch >= L'i' && ch <= L'z')) {AddCh(); goto case_1;} else if (ch == L'h') {AddCh(); goto case_20;} else {t->kind = 1; wchar_t *literal = coco_string_create_lower(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;} case 19: if ((ch >= L'0' && ch <= L'9') || (ch >= L'b' && ch <= L'z')) {AddCh(); goto case_1;} else if (ch == L'a') {AddCh(); goto case_21;} else {t->kind = 1; wchar_t *literal = coco_string_create_lower(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;} case 20: case_20: if ((ch >= L'0' && ch <= L'9') || (ch >= L'b' && ch <= L'z')) {AddCh(); goto case_1;} else if (ch == L'a') {AddCh(); goto case_22;} else {t->kind = 1; wchar_t *literal = coco_string_create_lower(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;} case 21: case_21: if ((ch >= L'0' && ch <= L'9') || (ch >= L'a' && ch <= L'q') || (ch >= L's' && ch <= L'z')) {AddCh(); goto case_1;} else if (ch == L'r') {AddCh(); goto case_23;} else {t->kind = 1; wchar_t *literal = coco_string_create_lower(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;} case 22: case_22: if ((ch >= L'0' && ch <= L'9') || (ch >= L'a' && ch <= L'q') || (ch >= L's' && ch <= L'z')) {AddCh(); goto case_1;} else if (ch == L'r') {AddCh(); goto case_24;} else {t->kind = 1; wchar_t *literal = coco_string_create_lower(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;} case 23: case_23: if ((ch >= L'0' && ch <= L'9') || (ch >= L'a' && ch <= L'b') || (ch >= L'd' && ch <= L'z')) {AddCh(); goto case_1;} else if (ch == L'c') {AddCh(); goto case_25;} else {t->kind = 1; wchar_t *literal = coco_string_create_lower(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;} case 24: case_24: if ((ch >= L'0' && ch <= L'9') || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_1;} else if (ch == L'(') {AddCh(); goto case_14;} else {t->kind = 1; wchar_t *literal = coco_string_create_lower(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;} case 25: case_25: if ((ch >= L'0' && ch <= L'9') || (ch >= L'a' && ch <= L'g') || (ch >= L'i' && ch <= L'z')) {AddCh(); goto case_1;} else if (ch == L'h') {AddCh(); goto case_26;} else {t->kind = 1; wchar_t *literal = coco_string_create_lower(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;} case 26: case_26: if ((ch >= L'0' && ch <= L'9') || (ch >= L'b' && ch <= L'z')) {AddCh(); goto case_1;} else if (ch == L'a') {AddCh(); goto case_27;} else {t->kind = 1; wchar_t *literal = coco_string_create_lower(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;} case 27: case_27: if ((ch >= L'0' && ch <= L'9') || (ch >= L'a' && ch <= L'q') || (ch >= L's' && ch <= L'z')) {AddCh(); goto case_1;} else if (ch == L'r') {AddCh(); goto case_28;} else {t->kind = 1; wchar_t *literal = coco_string_create_lower(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;} case 28: case_28: if ((ch >= L'0' && ch <= L'9') || (ch >= L'a' && ch <= L'z')) {AddCh(); goto case_1;} else if (ch == L'(') {AddCh(); goto case_15;} else {t->kind = 1; wchar_t *literal = coco_string_create_lower(tval, 0, tlen); t->kind = keywords.get(literal, t->kind); coco_string_delete(literal); break;} } AppendVal(t); return t; }
void Scanner::Init() { EOL = '\n'; eofSym = 0; maxT = 47; noSym = 47; start.set(97, 1); start.set(49, 27); start.set(116, 36); start.set(102, 39); start.set(35, 44); start.set(62, 154); start.set(117, 53); start.set(110, 58); start.set(115, 155); start.set(105, 156); start.set(99, 157); start.set(109, 83); start.set(125, 90); start.set(59, 91); start.set(100, 92); start.set(98, 98); start.set(48, 105); start.set(91, 106); start.set(93, 107); start.set(43, 109); start.set(45, 158); start.set(42, 110); start.set(47, 111); start.set(37, 112); start.set(40, 113); start.set(41, 159); start.set(108, 115); start.set(101, 123); start.set(123, 129); start.set(124, 130); start.set(38, 132); start.set(33, 160); start.set(61, 161); start.set(60, 162); start.set(119, 138); start.set(Buffer::EoF, -1); tvalLength = 128; tval = new wchar_t[tvalLength]; // text of current token // COCO_HEAP_BLOCK_SIZE byte heap + pointer to next heap block heap = malloc(COCO_HEAP_BLOCK_SIZE + sizeof(void*)); firstHeap = heap; heapEnd = (void**) (((char*) heap) + COCO_HEAP_BLOCK_SIZE); *heapEnd = 0; heapTop = heap; if (sizeof(Token) > COCO_HEAP_BLOCK_SIZE) { wprintf(L"--- Too small COCO_HEAP_BLOCK_SIZE\n"); exit(1); } pos = -1; line = 1; col = 0; charPos = -1; oldEols = 0; NextCh(); if (ch == 0xEF) { // check optional byte order mark for UTF-8 NextCh(); int ch1 = ch; NextCh(); int ch2 = ch; if (ch1 != 0xBB || ch2 != 0xBF) { wprintf(L"Illegal byte order mark at start of file"); exit(1); } Buffer *oldBuf = buffer; buffer = new UTF8Buffer(buffer); col = 0; charPos = -1; delete oldBuf; oldBuf = NULL; NextCh(); } pt = tokens = CreateToken(); // first token is a dummy }