void initPrinting(char *fname) { int i; currOUnit = createOUnitText("", NULL); setTokPos(&(currOUnit->pos), fname, 0, 1, 1, 0, 0, 0); _pushFileStack(currOUnit->pos.fileName); for (i = 0; i < NUM_OF_PRINT_TYPES; i++) { printData[i].stackPos = -1; } }
WicErrors getNextToken(pToken tok) { pTokTab tokTabPtr; WicErrors retVal = ERR_NONE; static long tokAfterDefine = 2; // used to flag '(' in #define x( as a // special parentheses int temp; assert(currTokF >= 0); currTokLen = 0; currTok[currTokLen] = 0; TOK_NUM_AFTER_NEW_LINE++; /* Used for #preprocessor directives */ tokAfterDefine++; /* Used for #preprocessor directives */ g_currLineNum = LINE_NUM; g_currColNum = COL_NUM; /* When getNextToken gets called, STATE may be one of: TS_START, TS_COMMENT. */ temp = skipBlank(); if (STATE == TS_START) { setTokPos( tok->pos, TOK_FILE_NAME, currTokF, LINE_NUM, COL_NUM, LINES_BEFORE, temp, orderLineNum ); while (NEXT_CHAR == '') { getNextChar(); tok->pos->spacesBefore = skipBlank(); } if (isalpha(NEXT_CHAR) || NEXT_CHAR == '_') { if (!scanId()) { char saveChar = NEXT_CHAR; currTokLen = 0; currTok[currTokLen] = 0; getNextChar(); if (saveChar == '"') { retVal = scanStr(tok->data); } else { retVal = scanChar(tok->data); } goto Return; } } else if (isdigit(NEXT_CHAR)) { retVal = scanNum(tok->data); goto Return; } else switch (NEXT_CHAR) { case '\'': getNextChar(); retVal = scanChar(tok->data); goto Return; break; case '"': if (currLineIsInclude) { getNextChar(); retVal = scanIncludeFileName(tok->data, '"'); goto Return; } else { getNextChar(); retVal = scanStr(tok->data); goto Return; break; } case '\n': pushGetNextChar(); currLineIsInclude = 0; break; case '!': pushGetNextChar(); if (NEXT_CHAR == '=') { pushGetNextChar(); } break; case '#': pushGetNextChar(); if (TOK_NUM_AFTER_NEW_LINE == 1) { skipBlank(); if (isalpha(NEXT_CHAR) || NEXT_CHAR == '_') { scanId(); } else { tok->data->code = Y_PRE_NULL; retVal = ERR_NONE; goto Return; } } else { if (NEXT_CHAR == '#') { pushGetNextChar(); } } break; case '%': pushGetNextChar(); if (NEXT_CHAR == '=') { pushGetNextChar(); } break; case '&': pushGetNextChar(); if (NEXT_CHAR == '&') { pushGetNextChar(); if (NEXT_CHAR == '=') { pushGetNextChar(); } } break; case '(': pushGetNextChar(); break; case ')': pushGetNextChar(); break; case '*': pushGetNextChar(); if (NEXT_CHAR == '=') { pushGetNextChar(); } break; case '+': pushGetNextChar(); if (NEXT_CHAR == '+') { pushGetNextChar(); } else if (NEXT_CHAR == '=') { pushGetNextChar(); } break; case ',': pushGetNextChar(); break; case '-': pushGetNextChar(); if (NEXT_CHAR == '-') { pushGetNextChar(); } else if (NEXT_CHAR == '=') { pushGetNextChar(); } else if (NEXT_CHAR == '>') { pushGetNextChar(); } break; case '.': pushGetNextChar(); if (NEXT_CHAR == '.') { pushGetNextChar(); if (NEXT_CHAR == '.') { pushGetNextChar(); } else { retVal = RERR_INV_CHAR; goto Return; } } else if (isdigit(NEXT_CHAR)) { if (pushFloatDotExp(tok->data, 1)) { retVal = convStr2Const(tok->data); goto Return; } else { retVal = RERR_INV_CHAR; goto Return; } } break; case '/': pushGetNextChar(); if (NEXT_CHAR == '=') { pushGetNextChar(); } else if (NEXT_CHAR == '*') { /* comment begin */ popChars(1); STATE = TS_COMMENT; getNextChar(); retVal = scanComment(tok->data); goto Return; } else if (NEXT_CHAR == '/') { popChars(1); STATE = TS_COMMENT; getNextChar(); retVal = scanCPlusPlusComment(tok->data); goto Return; } break; case ':': pushGetNextChar(); if (NEXT_CHAR == '>') { pushGetNextChar(); } break; case ';': pushGetNextChar(); break; case '<': if (currLineIsInclude) { getNextChar(); retVal = scanIncludeFileName(tok->data, '>'); goto Return; } else { pushGetNextChar(); if (NEXT_CHAR == '<') { pushGetNextChar(); if (NEXT_CHAR == '=') { pushGetNextChar(); } } else if (NEXT_CHAR == '=') { pushGetNextChar(); } } break; case '=': pushGetNextChar(); if (NEXT_CHAR == '=') { pushGetNextChar(); } break; case '>': pushGetNextChar(); if (NEXT_CHAR == '>') { pushGetNextChar(); if (NEXT_CHAR == '=') { pushGetNextChar(); } } else if (NEXT_CHAR == '=') { pushGetNextChar(); } break; case '?': pushGetNextChar(); break; case '[': pushGetNextChar(); break; case ']': pushGetNextChar(); break; case '^': pushGetNextChar(); if (NEXT_CHAR == '=') pushGetNextChar(); break; case '{': pushGetNextChar(); break; case '|': pushGetNextChar(); if (NEXT_CHAR == '=') { pushGetNextChar(); } else if (NEXT_CHAR == '|') { pushGetNextChar(); } break; case '}': pushGetNextChar(); break; case '~': pushGetNextChar(); break; case (char) EOF: tok->data->code = Y_EOF; retVal = ERR_NONE; goto Return; break; default: /* Eat up an ivalid character */ getNextChar(); retVal = RERR_INV_CHAR; goto Return; } tokTabPtr = tabLookup(currTok); if (tokTabPtr != NULL) { tok->data->code = tokTabPtr->code; if (tok->data->code == Y_PRE_INCLUDE) { currLineIsInclude = 1; } if (tok->data->code == Y_PRE_DEFINE) { tokAfterDefine = 0; } if (tok->data->code == Y_LEFT_PAREN && tokAfterDefine == 2) { // the case of #define x(... if (tok->pos->spacesBefore == 0) { tok->data->code = Y_PRE_SPECIAL_LEFT_PAREN; } } tok->data->repr.string = registerString(tokTabPtr->name, !FREE_STRING); } else { if (currTok[0] == '#') { retVal = RERR_INV_PREPROCESSOR; goto Return; } else { tok->data->code = Y_ID; tok->data->repr.string = registerString(wicStrdup(currTok), FREE_STRING); } } } else if (STATE == TS_COMMENT) { setTokPos(tok->pos, TOK_FILE_NAME, currTokF, LINE_NUM, COL_NUM, LINES_BEFORE, 0, orderLineNum); retVal = scanComment(tok->data); goto Return; } else { assert(0); } Return: if (tok->data->code != Y_PRE_NEWLINE) { tok->pos->linesBefore = tok->pos->lineNum - PREV_TOK_LINE_NUM; PREV_TOK_LINE_NUM = tok->pos->lineNum; } else { tok->pos->linesBefore = 0; } zapTokPos(g_currPos); g_currPos = dupTokPos(tok->pos, NULL); return retVal; }