static int yylook(void) { int tok = 0; while (1) { if ((tok = Scanner_token(scan)) == 0) return 0; if (tok == SWIG_TOKEN_ERROR) return 0; cparse_start_line = Scanner_start_line(scan); cparse_line = Scanner_line(scan); cparse_file = Scanner_file(scan); switch(tok) { case SWIG_TOKEN_ID: return ID; case SWIG_TOKEN_LPAREN: return LPAREN; case SWIG_TOKEN_RPAREN: return RPAREN; case SWIG_TOKEN_SEMI: return SEMI; case SWIG_TOKEN_COMMA: return COMMA; case SWIG_TOKEN_STAR: return STAR; case SWIG_TOKEN_RBRACE: num_brace--; if (num_brace < 0) { Swig_error(cparse_file, cparse_line, "Syntax error. Extraneous '}'\n"); num_brace = 0; } else { return RBRACE; } break; case SWIG_TOKEN_LBRACE: last_brace = num_brace; num_brace++; return LBRACE; case SWIG_TOKEN_EQUAL: return EQUAL; case SWIG_TOKEN_EQUALTO: return EQUALTO; case SWIG_TOKEN_PLUS: return PLUS; case SWIG_TOKEN_MINUS: return MINUS; case SWIG_TOKEN_SLASH: return SLASH; case SWIG_TOKEN_AND: return AND; case SWIG_TOKEN_LAND: return LAND; case SWIG_TOKEN_OR: return OR; case SWIG_TOKEN_LOR: return LOR; case SWIG_TOKEN_XOR: return XOR; case SWIG_TOKEN_NOT: return NOT; case SWIG_TOKEN_LNOT: return LNOT; case SWIG_TOKEN_NOTEQUAL: return NOTEQUALTO; case SWIG_TOKEN_LBRACKET: return LBRACKET; case SWIG_TOKEN_RBRACKET: return RBRACKET; case SWIG_TOKEN_QUESTION: return QUESTIONMARK; case SWIG_TOKEN_LESSTHAN: return LESSTHAN; case SWIG_TOKEN_LTEQUAL: return LESSTHANOREQUALTO; case SWIG_TOKEN_LSHIFT: return LSHIFT; case SWIG_TOKEN_GREATERTHAN: return GREATERTHAN; case SWIG_TOKEN_GTEQUAL: return GREATERTHANOREQUALTO; case SWIG_TOKEN_RSHIFT: return RSHIFT; case SWIG_TOKEN_PERIOD: return PERIOD; case SWIG_TOKEN_MODULO: return MODULO; case SWIG_TOKEN_COLON: return COLON; case SWIG_TOKEN_DCOLONSTAR: return DSTAR; case SWIG_TOKEN_DCOLON: { int nexttok = Scanner_token(scan); if (nexttok == SWIG_TOKEN_STAR) { return DSTAR; } else if (nexttok == SWIG_TOKEN_NOT) { return DCNOT; } else { Scanner_pushtoken(scan,nexttok,Scanner_text(scan)); if (!last_id) { scanner_next_token(DCOLON); return NONID; } else { return DCOLON; } } } break; /* Look for multi-character sequences */ case SWIG_TOKEN_RSTRING: yylval.type = NewString(Scanner_text(scan)); return TYPE_RAW; case SWIG_TOKEN_STRING: yylval.id = Swig_copy_string(Char(Scanner_text(scan))); return STRING; case SWIG_TOKEN_CHAR: yylval.str = NewString(Scanner_text(scan)); if (Len(yylval.str) == 0) { Swig_error(cparse_file, cparse_line, "Empty character constant\n"); Printf(stdout,"%d\n", Len(Scanner_text(scan))); } return CHARCONST; /* Numbers */ case SWIG_TOKEN_INT: return NUM_INT; case SWIG_TOKEN_UINT: return NUM_UNSIGNED; case SWIG_TOKEN_LONG: return NUM_LONG; case SWIG_TOKEN_ULONG: return NUM_ULONG; case SWIG_TOKEN_LONGLONG: return NUM_LONGLONG; case SWIG_TOKEN_ULONGLONG: return NUM_ULONGLONG; case SWIG_TOKEN_DOUBLE: case SWIG_TOKEN_FLOAT: return NUM_FLOAT; case SWIG_TOKEN_BOOL: return NUM_BOOL; case SWIG_TOKEN_POUND: Scanner_skip_line(scan); yylval.id = Swig_copy_string(Char(Scanner_text(scan))); return POUND; break; case SWIG_TOKEN_CODEBLOCK: yylval.str = NewString(Scanner_text(scan)); return HBLOCK; case SWIG_TOKEN_COMMENT: { String *cmt = Scanner_text(scan); char *loc = Char(cmt); if ((strncmp(loc,"/*@SWIG",7) == 0) && (loc[Len(cmt)-3] == '@')) { scanner_locator(cmt); } } break; case SWIG_TOKEN_ENDLINE: break; case SWIG_TOKEN_BACKSLASH: break; default: Swig_error(cparse_file, cparse_line, "Illegal token '%s'.\n", Scanner_text(scan)); return (ILLEGAL); } } }
int yylook(void) { int state; int c = 0; state = 0; yylen = 0; while(1) { /* printf("State = %d\n", state); */ switch(state) { case 0 : if((c = nextchar()) == 0) return (0); /* Process delimeters */ if (c == '\n') { state = 0; yylen = 0; /* last_id = 0;*/ } else if (isspace(c) || (c=='\\')) { state = 0; yylen = 0; /* last_id = 0; */ } else if ((isalpha(c)) || (c == '_')) state = 7; else if (c == '$') state = 75; /* Look for single character symbols */ else if (c == '(') return (LPAREN); else if (c == ')') return (RPAREN); else if (c == ';') return (SEMI); else if (c == ',') return (COMMA); else if (c == '*') return (STAR); else if (c == '}') { num_brace--; if (num_brace < 0) { Swig_error(cparse_file, cparse_line, "Syntax error. Extraneous '}'\n"); state = 0; num_brace = 0; } else { return (RBRACE); } } else if (c == '{') { last_brace = num_brace; num_brace++; return (LBRACE); } else if (c == '=') return (EQUAL); else if (c == '+') return (PLUS); else if (c == '-') return (MINUS); else if (c == '&') { state = 300; } else if (c == '|') { state = 301; } else if (c == '^') return (XOR); else if (c == '<') state = 60; else if (c == '>') state = 61; else if (c == '~') { return (NOT); } else if (c == '!') return (LNOT); else if (c == '\\') { state = 99; } else if (c == '[') return (LBRACKET); else if (c == ']') return (RBRACKET); /* Look for multi-character sequences */ else if (c == '/') state = 1; /* Comment (maybe) */ else if (c == '\"') state = 2; /* Possibly a string */ else if (c == '#') state = 3; /* CPP */ else if (c == '%') state = 4; /* Directive */ else if (c == '@') state = 4; /* Objective C keyword */ else if (c == ':') state = 5; /* maybe double colon */ else if (c == '0') state = 83; /* An octal or hex value */ else if (c == '\'') state = 9; /* A character constant */ else if (c == '.') state = 100; /* Maybe a number, maybe just a period */ else if (c == '`') { state = 200; /* Back-tick type */ yylen = 0; } else if (isdigit(c)) state = 8; /* A numerical value */ else state = 99; break; case 1: /* Comment block */ if ((c = nextchar()) == 0) return(0); if (c == '/') { comment_start = cparse_line; Clear(comment); state = 10; /* C++ style comment */ } else if (c == '*') { comment_start = cparse_line; Clear(comment); state = 12; /* C style comment */ } else { retract(1); return(SLASH); } break; case 300: /* & or && */ if ((c = nextchar()) == 0) return(AND); if (c == '&') return(LAND); else { retract(1); return(AND); } case 301: /* | or || */ if ((c = nextchar()) == 0) return(OR); if (c == '|') return(LOR); else { retract(1); return(OR); } case 10: /* C++ style comment */ if ((c = nextchar()) == 0) { Swig_error(cparse_file,-1, "Unterminated comment detected.\n"); return 0; } if (c == '\n') { Putc(c,comment); /* Add the comment to documentation */ /* yycomment(Char(comment),comment_start, column_start);*/ yylen = 0; state = 0; } else { state = 10; Putc(c,comment); yylen = 0; } break; case 12: /* C style comment block */ if ((c = nextchar()) == 0) { Swig_error(cparse_file,-1,"Unterminated comment detected.\n"); return 0; } if (c == '*') { state = 13; } else { Putc(c,comment); yylen = 0; state = 12; } break; case 13: /* Still in C style comment */ if ((c = nextchar()) == 0) { Swig_error(cparse_file,-1,"Unterminated comment detected.\n"); return 0; } if (c == '*') { Putc(c,comment); state = 13; } else if (c == '/') { /* Look for locator markers */ { char *loc = Char(comment); if (Len(comment)) { if ((*loc == '@') && (*(loc+Len(comment)-1) == '@')) { /* Locator */ scanner_locator(comment); } } } /* yycomment(Char(comment),comment_start,column_start); */ yylen = 0; state = 0; } else { Putc('*',comment); Putc(c,comment); yylen = 0; state = 12; } break; case 2: /* Processing a string */ if ((c = nextchar()) == 0) { Swig_error(cparse_file,-1, "Unterminated string detected.\n"); return 0; } if (c == '\"') { yytext[yylen-1] = 0; yylval.id = Swig_copy_string(yytext+1); return(STRING); } else if (c == '\\') { yylen--; get_escape(); break; } else state = 2; break; case 3: /* a CPP directive */ if (( c= nextchar()) == 0) return 0; if (c == '\n') { retract(1); yytext[yylen] = 0; yylval.id = yytext; return(POUND); } break; case 4: /* A wrapper generator directive (maybe) */ if (( c= nextchar()) == 0) return 0; if (c == '{') { state = 40; /* Include block */ Clear(header); cparse_start_line = cparse_line; } else if ((isalpha(c)) || (c == '_')) state = 7; else if (c == '}') { Swig_error(cparse_file,cparse_line, "Misplaced %%}.\n"); return 0; } else { retract(1); return(MODULO); } break; case 40: /* Process an include block */ if ((c = nextchar()) == 0) { Swig_error(cparse_file,-1, "Unterminated include block detected.\n"); return 0; } yylen = 0; if (c == '%') state = 41; else { Putc(c,header); yylen = 0; state = 40; } break; case 41: /* Still processing include block */ if ((c = nextchar()) == 0) { Swig_error(cparse_file,-1, "Unterminated include block detected.\n"); return 0; } if (c == '}') { yylval.str = NewString(header); return(HBLOCK); } else { Putc('%',header); Putc(c,header); yylen = 0; state = 40; } break; case 5: /* Maybe a double colon */ if (( c= nextchar()) == 0) return 0; if ( c == ':') { state = 51; } else { retract(1); return COLON; } break; case 51: /* Maybe a ::*, ::~, or :: */ if (( c = nextchar()) == 0) return 0; if (c == '*') { return DSTAR; } else if (c == '~') { return DCNOT; } else if (isspace(c)) { /* Keep scanning ahead. Might be :: * or :: ~ */ } else { retract(1); if (!last_id) { retract(2); return NONID; } else { return DCOLON; } } break; case 60: /* shift operators */ if ((c = nextchar()) == 0) return (0); if (c == '<') return LSHIFT; else { retract(1); return LESSTHAN; } break; case 61: if ((c = nextchar()) == 0) return (0); if (c == '>') return RSHIFT; else { retract(1); return GREATERTHAN; } break; case 7: /* Identifier */ if ((c = nextchar()) == 0) return(0); if (isalnum(c) || (c == '_') || (c == '.') || (c == '$')) { state = 7; } else { retract(1); return(ID); } break; case 75: /* Special identifier $*/ if ((c = nextchar()) == 0) return(0); if (isalnum(c) || (c == '_') || (c == '*') || (c == '&')) { state = 7; } else { retract(1); return(ID); } break; case 8: /* A numerical digit */ if ((c = nextchar()) == 0) return(0); if (c == '.') {state = 81;} else if ((c == 'e') || (c == 'E')) {state = 86;} else if ((c == 'f') || (c == 'F')) { return(NUM_FLOAT); } else if (isdigit(c)) { state = 8;} else if ((c == 'l') || (c == 'L')) { state = 87; } else if ((c == 'u') || (c == 'U')) { state = 88; } else { retract(1); return(NUM_INT); } break; case 81: /* A floating pointer number of some sort */ if ((c = nextchar()) == 0) return(0); if (isdigit(c)) state = 81; else if ((c == 'e') || (c == 'E')) state = 82; else if ((c == 'f') || (c == 'F') || (c == 'l') || (c == 'L')) { return(NUM_FLOAT); } else { retract(1); return(NUM_FLOAT); } break; case 82: if ((c = nextchar()) == 0) return(0); if ((isdigit(c)) || (c == '-') || (c == '+')) state = 86; else { retract(2); yytext[yylen-1] = 0; return(NUM_INT); } break; case 83: /* Might be a hexidecimal or octal number */ if ((c = nextchar()) == 0) return(0); if (isdigit(c)) state = 84; else if ((c == 'x') || (c == 'X')) state = 85; else if (c == '.') state = 81; else if ((c == 'l') || (c == 'L')) { state = 87; } else if ((c == 'u') || (c == 'U')) { state = 88; } else { retract(1); return(NUM_INT); } break; case 84: /* This is an octal number */ if ((c = nextchar()) == 0) return (0); if (isdigit(c)) state = 84; else if ((c == 'l') || (c == 'L')) { state = 87; } else if ((c == 'u') || (c == 'U')) { state = 88; } else { retract(1); return(NUM_INT); } break; case 85: /* This is an hex number */ if ((c = nextchar()) == 0) return (0); if ((isdigit(c)) || (c=='a') || (c=='b') || (c=='c') || (c=='d') || (c=='e') || (c=='f') || (c=='A') || (c=='B') || (c=='C') || (c=='D') || (c=='E') || (c=='F')) state = 85; else if ((c == 'l') || (c == 'L')) { state = 87; } else if ((c == 'u') || (c == 'U')) { state = 88; } else { retract(1); return(NUM_INT); } break; case 86: /* Rest of floating point number */ if ((c = nextchar()) == 0) return (0); if (isdigit(c)) state = 86; else if ((c == 'f') || (c == 'F') || (c == 'l') || (c == 'L')) { return(NUM_FLOAT); } else { retract(1); return(NUM_FLOAT); } /* Parse a character constant. ie. 'a' */ break; case 87 : /* A long integer of some sort */ if ((c = nextchar()) == 0) return (NUM_LONG); if ((c == 'u') || (c == 'U')) { return(NUM_ULONG); } else if ((c == 'l') || (c == 'L')) { state = 870; } else { retract(1); return(NUM_LONG); } break; case 870: if ((c = nextchar()) == 0) return (NUM_LONGLONG); if ((c == 'u') || (c == 'U')) { return (NUM_ULONGLONG); } else { retract(1); return(NUM_LONGLONG); } case 88: /* An unsigned integer of some sort */ if ((c = nextchar()) == 0) return (NUM_UNSIGNED); if ((c == 'l') || (c == 'L')) { state = 880; } else { retract(1); return(NUM_UNSIGNED); } break; case 880: if ((c = nextchar()) == 0) return (NUM_ULONG); if ((c == 'l') || (c == 'L')) return (NUM_ULONGLONG); else { retract(1); return(NUM_ULONG); } case 9: if ((c = nextchar()) == 0) return (0); if (c == '\\') { yylen--; get_escape(); } else if (c == '\'') { yytext[yylen-1] = 0; yylval.str = NewString(yytext+1); if (yylen == 2) { Swig_error(cparse_file, cparse_line, "Empty character constant\n"); } return(CHARCONST); } break; case 100: if ((c = nextchar()) == 0) return (0); if (isdigit(c)) state = 81; else { retract(1); return(PERIOD); } break; case 200: if ((c = nextchar()) == 0) return (0); if (c == '`') { yytext[yylen-1] = 0; yylval.type = NewString(yytext); return(TYPE_RAW); } break; default: Swig_error(cparse_file, cparse_line, "Illegal character '%c'=%d.\n",c,c); state = 0; return(ILLEGAL); } } }