/* test processchar() */ int main(void) { fprintf(stderr, "Transforming 'c' into 'string'\n"); if (processchar(STDIN_FILENO, STDOUT_FILENO, 'c', "string") == -1) fprintf(stderr, "processchar failed\n"); fprintf(stderr, "processchar success\n"); return 0; }
/*This function processes the exiting data stream Inputs: None Outputs: Integer - 0 is success -1 is failure */ int vdscreen::processdata(void) { int c; //we have received some bytes, process them c=getnextchar(); while (c!=-1) { processchar(c); c=getnextchar(); } return 0; }
int yylex() { int r, c, c2, d; int radix; char extPath[MAXPATHLEN]; // for error reporting yylen = 0; // finite state machine to parse input stream into tokens if (lexCmdLine == 1) { lexCmdLine = 2; r = INTERPRET; goto leave; } start: c = input(); if (c == 0) { r = 0; goto leave; } else if (c==' ' || c=='\t' || c=='\n' || c=='\r' || c=='\v' || c=='\f') { yylen = 0; goto start; } else if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_') goto ident; else if (c == '/') { c = input(); if (c == '/') goto comment1; else if (c == '*') goto comment2; else { unput(c); goto binop; } } else if (c >= '0' && c <= '9') goto digits_1; else if (c == OPENPAREN || c == OPENSQUAR || c == OPENCURLY) { pushls(&brackets, (int)c); if (c == OPENCURLY) { pushls(&closedFuncCharNo, linestarts[lineno] + charno - 1); } r = c; goto leave; } else if (c == CLOSSQUAR) { if (!emptyls(&brackets)) { if ((d = popls(&brackets)) != OPENSQUAR) { fatal(); post("opening bracket was a '%c', but found a '%c'\n",d,c); goto error2; } } else { fatal(); post("unmatched '%c'\n",c); goto error2; } r = c; goto leave; } else if (c == CLOSPAREN) { if (!emptyls(&brackets)) { if ((d = popls(&brackets)) != OPENPAREN) { fatal(); post("opening bracket was a '%c', but found a '%c'\n",d,c); goto error2; } } else { fatal(); post("unmatched '%c'\n",c); goto error2; } r = c; goto leave; } else if (c == CLOSCURLY) { if (!emptyls(&brackets)) { if ((d = popls(&brackets)) != OPENCURLY) { fatal(); post("opening bracket was a '%c', but found a '%c'\n",d,c); goto error2; } lastClosedFuncCharNo = popls(&closedFuncCharNo); } else { fatal(); post("unmatched '%c'\n",c); goto error2; } r = c; goto leave; } else if (c == '^') { r = c; goto leave; } else if (c == '~') { r = c; goto leave; } else if (c == ';') { r = c; goto leave; } else if (c == ':') { r = c; goto leave; } else if (c == '`') { r = c; goto leave; } else if (c == '\\') goto symbol1; else if (c == '\'') goto symbol3; else if (c == '"') goto string1; else if (c == '.') { if ((c = input()) == '.') { if ((c = input()) == '.') { r = ELLIPSIS; goto leave; } else { r = DOTDOT; unput(c); goto leave; } } else { unput(c); r = '.'; goto leave; } } else if (c == '#') { if ((c = input()) == OPENCURLY) { pushls(&brackets, OPENCURLY); pushls(&closedFuncCharNo, linestarts[lineno] + charno - 2); r = BEGINCLOSEDFUNC; } else { unput(c); r = '#'; } goto leave; } else if (c == '$') { c = input(); if (c == '\\') { c = input(); switch (c) { case 'n' : c = '\n'; break; case 'r' : c = '\r'; break; case 't' : c = '\t'; break; case 'f' : c = '\f'; break; case 'v' : c = '\v'; break; } } r = processchar(c); goto leave; } else if (c == ',') { r = c; goto leave; } else if (c == '=') { c = input(); if (strchr(binopchars, c)) goto binop; else { unput(c); r = '='; goto leave; } } else if (strchr(binopchars, c)) goto binop; else if(!(isprint(c) || isspace(c) || c == 0)) { yylen = 0; goto start; } else goto error1; ident: c = input(); if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_' || (c >= '0' && c <= '9')) goto ident; else if (c == ':') { yytext[yylen] = 0; r = processkeywordbinop(yytext) ; goto leave; } else { unput(c); yytext[yylen] = 0; r = processident(yytext) ; goto leave; } symbol1: c = input(); if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_') goto symbol2; else if (c >= '0' && c <= '9') goto symbol4; else { unput(c); yytext[yylen] = 0; r = processsymbol(yytext) ; goto leave; } symbol2: c = input(); if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_' || (c >= '0' && c <= '9')) goto symbol2; else { unput(c); yytext[yylen] = 0; r = processsymbol(yytext) ; goto leave; } symbol4: c = input(); if (c >= '0' && c <= '9') goto symbol4; else { unput(c); yytext[yylen] = 0; r = processsymbol(yytext) ; goto leave; } binop: c = input(); if (c == 0) goto binop2; if (strchr(binopchars, c)) goto binop; else { binop2: unput(c); yytext[yylen] = 0; r = processbinop(yytext) ; goto leave; } radix_digits_1: c = input(); if (c >= '0' && c <= '0' + sc_min(10,radix) - 1) goto radix_digits_1; if (c >= 'a' && c <= 'a' + sc_min(36,radix) - 11) goto radix_digits_1; if (c >= 'A' && c <= 'A' + sc_min(36,radix) - 11) goto radix_digits_1; if (c == '.') { goto radix_digits_2; } unput(c); yytext[yylen] = 0; r = processintradix(yytext, yylen, radix); goto leave; radix_digits_2: c = input(); if (c >= '0' && c <= '0' + sc_min(10,radix) - 1) goto radix_digits_2; if (c >= 'A' && c <= 'A' + sc_min(36,radix) - 11) goto radix_digits_2; // do not allow lower case after decimal point. unput(c); yytext[yylen] = 0; r = processfloatradix(yytext, yylen, radix); goto leave; hexdigits: c = input(); if (c >= '0' && c <= '9') goto hexdigits; if (c >= 'a' && c <= 'f') goto hexdigits; if (c >= 'A' && c <= 'F') goto hexdigits; unput(c); yytext[yylen] = 0; r = processhex(yytext); goto leave; digits_1: /* number started with digits */ c = input(); if (c >= '0' && c <= '9') goto digits_1; else if (c == 'r') { radix = sc_strtoi(yytext, yylen-1, 10); yylen = 0; goto radix_digits_1; } else if (c == 'e' || c == 'E') goto expon_1; else if (c == '.') { c2 = input(); if (c2 >= '0' && c2 <= '9') goto digits_2; else { unput(c2); unput(c); yytext[yylen] = 0; r = processint(yytext); goto leave; } } else if (c == 'b' || c == 's') { d = input(); if (d >= '0' && d <= '9') goto accidental1; if (d == c) goto accidental2; goto accidental3; accidental1: d = input(); if (d >= '0' && d <= '9') goto accidental1; unput(d); yytext[yylen] = 0; r = processaccidental1(yytext); goto leave; accidental2: d = input(); if (d == c) goto accidental2; accidental3: unput(d); yytext[yylen] = 0; r = processaccidental2(yytext); goto leave; } else if (c == 'x') { yylen = 0; goto hexdigits; } else { unput(c); yytext[yylen] = 0; r = processint(yytext); goto leave; } digits_2: c = input(); if (c >= '0' && c <= '9') goto digits_2; else if (c == 'e' || c == 'E') goto expon_1; // else if (c == 'π' || c == '∏') { // --yylen; // yytext[yylen] = 0; // r = processfloat(yytext, 1); // goto leave; // } else { unput(c); yytext[yylen] = 0; r = processfloat(yytext, 0); goto leave; } expon_1: /* e has been seen, need digits */ c = input(); if (c >= '0' && c <= '9') goto expon_3; else if (c == '+' || c == '-') goto expon_2; else goto error1; expon_2: /* + or - seen but still need digits */ c = input(); if (c >= '0' && c <= '9') goto expon_3; else goto error1; expon_3: c = input(); if (c >= '0' && c <= '9') goto expon_3; // else if (c == 'π' || c == '∏') { // --yylen; // yytext[yylen] = 0; // r = processfloat(yytext, 1); // goto leave; // } else { unput(c); yytext[yylen] = 0; r = processfloat(yytext, 0); goto leave; } symbol3 : { int startline, endchar; startline = lineno; endchar = '\''; /*do { c = input(); } while (c != endchar && c != 0);*/ for (;yylen<MAXYYLEN;) { c = input(); if (c == '\n' || c == '\r') { asRelativePath(curfilename,extPath); post("Symbol open at end of line on line %d in file '%s'\n", startline+errLineOffset, extPath); yylen = 0; r = 0; goto leave; } if (c == '\\') { yylen--; c = input(); } else if (c == endchar) break; if (c == 0) break; } if (c == 0) { asRelativePath(curfilename,extPath); post("Open ended symbol ... started on line %d in file '%s'\n", startline+errLineOffset, extPath); yylen = 0; r = 0; goto leave; } yytext[yylen] = 0; yytext[yylen-1] = 0; r = processsymbol(yytext); goto leave; } string1 : { int startline, endchar; startline = lineno; endchar = '"'; for (;yylen<MAXYYLEN;) { c = input(); if (c == '\\') { yylen--; c = input(); switch (c) { case 'n' : yytext[yylen-1] = '\n'; break; case 'r' : yytext[yylen-1] = '\r'; break; case 't' : yytext[yylen-1] = '\t'; break; case 'f' : yytext[yylen-1] = '\f'; break; case 'v' : yytext[yylen-1] = '\v'; break; } } else if (c == '\r') c = '\n'; else if (c == endchar) break; if (c == 0) break; } if (c == 0) { asRelativePath(curfilename,extPath); post("Open ended string ... started on line %d in file '%s'\n", startline+errLineOffset, extPath); yylen = 0; r = 0; goto leave; } yylen--; do { c = input0(); } while (c && isspace(c)); if (c == '"') goto string1; else if (c) unput0(c); yytext[yylen] = 0; r = processstring(yytext); goto leave; } comment1: /* comment -- to end of line */ do { c = input0(); } while (c != '\n' && c != '\r' && c != 0); yylen = 0; if (c == 0) { r = 0; goto leave; } else goto start; comment2 : { int startline, clevel, prevc; startline = lineno; prevc = 0; clevel = 1; do { c = input0(); if (c == '/' && prevc == '*') { if (--clevel <= 0) break; } else if (c == '*' && prevc == '/') clevel++; prevc = c; } while (c != 0); yylen = 0; if (c == 0) { asRelativePath(curfilename,extPath); post("Open ended comment ... started on line %d in file '%s'\n", startline+errLineOffset, extPath); r = 0; goto leave; } goto start; } error1: yytext[yylen] = 0; asRelativePath(curfilename, extPath); post("illegal input string '%s' \n at '%s' line %d char %d\n", yytext, extPath, lineno+errLineOffset, charno); post("code %d\n", c); //postfl(" '%c' '%s'\n", c, binopchars); //postfl("%d\n", strchr(binopchars, c)); error2: asRelativePath(curfilename, extPath); post(" in file '%s' line %d char %d\n", extPath, lineno+errLineOffset, charno); r = BADTOKEN; goto leave; leave: yytext[yylen] = 0; #if DEBUGLEX if (gDebugLexer) postfl("yylex: %d '%s'\n",r,yytext); #endif //if (lexCmdLine>0) postfl("yylex: %d '%s'\n",r,yytext); return r; }