void ResNickMan::AddReservedNick(const char * sNick, const bool &bFromScript/* = false*/) { uint32_t ulHash = HashNick(sNick, strlen(sNick)); if(CheckReserved(sNick, ulHash) == false) { ReservedNick * pNewNick = new ReservedNick(sNick, ulHash); if(pNewNick == NULL) { AppendDebugLog("%s - [MEM] Cannot allocate pNewNick in ResNickMan::AddReservedNick\n", 0); return; } else if(pNewNick->sNick == NULL) { delete pNewNick; AppendDebugLog("%s - [MEM] Cannot allocate pNewNick->sNick in ResNickMan::AddReservedNick\n", 0); return; } if(ReservedNicks == NULL) { ReservedNicks = pNewNick; } else { ReservedNicks->prev = pNewNick; pNewNick->next = ReservedNicks; ReservedNicks = pNewNick; } pNewNick->bFromScript = bFromScript; } }
MicroScanner::Token MicroScanner::GetToken() { Token token; std::string tokenBuffer; std::ifstream::char_type inChar; std::ifstream::char_type c; std::ifstream& is = m_inputFileStream; while (is.get(inChar)) { TokenClass tokenClass; switch(inChar) { case '-': is.get(c); if (c == '-') { /* skip one line comments (which start with --) */ do is.get(inChar); while (inChar != '\n'); break; } else { tokenClass = MINUSOP; tokenBuffer += inChar; } return std::make_pair(tokenClass, tokenBuffer); case '(': tokenClass = LPAREN; tokenBuffer += inChar; return std::make_pair(tokenClass, tokenBuffer); case ')': tokenClass = RPAREN; tokenBuffer += inChar; return std::make_pair(tokenClass, tokenBuffer); case ';': tokenClass = SEMICOLON; tokenBuffer += inChar; return std::make_pair(tokenClass, tokenBuffer); case ',': tokenClass = COMMA; tokenBuffer += inChar; return std::make_pair(tokenClass, tokenBuffer); case '+': tokenClass = PLUSOP; tokenBuffer += inChar; return std::make_pair(tokenClass, tokenBuffer); case ':': tokenBuffer += inChar; /* looking for ":=" */ is.get(c); if (c == '=') { tokenBuffer += c; return std::make_pair(ASSIGNOP, tokenBuffer); } else { is.unget(); /* lexical_error */ } break; default: if (std::isspace(inChar)) continue; else if (std::isalpha(inChar)) { /* * ID ::= LETTER | ID LETTER * | ID DIGIT * | ID UNDERSCORE */ tokenBuffer += inChar; for (is.get(c); std::isalnum(c) || c == '_'; is.get(c)) tokenBuffer += c; is.unget(); CheckReserved(tokenBuffer, token); return token; } else if (std::isdigit(inChar)) { /* * INTLITERAL ::= DIGIT | * INTLITERAL DIGIT */ tokenBuffer += inChar; for (is.get(c); std::isdigit(c); is.get(c)) tokenBuffer += c; is.unget(); token = std::make_pair(INTLITERAL, tokenBuffer); return token; } else { /* lexical_error */ } break; } } return std::make_pair(SCANEOF, ""); }
extern int StyleLex( Bool fSymbol) { int c , len; int token; char *s; Bool fFloat; dbgmsg(">StyleLex"); retry: while ( isspace( c = GetChar(StyleFile) ) ) { if ( c == '\n' ) { c = ' '; StylecLine ++; } } if ( c == '#' ) { while ( ( c = GetChar(StyleFile) ) != '\n' ); StylecLine ++; goto retry; } if ( c == '"' ) { s = StyleComSymbol; len = 0; while ( ( c = GetChar(StyleFile) ) != '"' ) { if ( c == '\\' ) { c = GetChar(StyleFile); } *s = c; if ( len < SIZE_SYMBOL ) { s ++; len ++; } } *s = 0; token = T_SCONST; } else if ( isalpha(c) ) { s = StyleComSymbol; len = 0; do { *s = c; if ( len < SIZE_SYMBOL ) { s ++; len ++; } c = GetChar(StyleFile); } while ( ( isalpha(c) ) || ( isdigit(c) ) || ( c == '.' ) || ( c == '_' ) ); *s = 0; UnGetChar(StyleFile,c); if ( fSymbol ) { token = T_SYMBOL; } else { token = CheckReserved(StyleComSymbol); } } else if ( isdigit(c) ) { s = StyleComSymbol; len = 0; fFloat = FALSE; do { *s = c; if ( c == '.' ) { if ( fFloat ) { printf(". duplicate\n"); } fFloat = TRUE; } if ( len < SIZE_SYMBOL ) { s ++; len ++; } c = GetChar(StyleFile); } while ( ( isdigit(c) ) || ( c == '.' ) ); *s = 0; UnGetChar(StyleFile,c); if ( fFloat ) { StyleComInt = (int)(atof(StyleComSymbol) * 65535.0); } else { StyleComInt = atoi(StyleComSymbol); } token = T_ICONST; } else { switch (c) { case EOF: token = T_EOF; break; default: token = c; break; } } dbgmsg("<StyleLex"); return (token); }
/*------------------------------------------------------------* * FIND NEXT TAG * * This function will find the next tag in the current file. * It may now also find a list of tags to create. If the * signal or variable tag has a list of symbols to be defined * then this will return that list, that will need to be * transversed for it to be found. *------------------------------------------------------------*/ int find_next_tag(int infile,char* token,int *token_size,int *hasbody,int* operator,int *line,int* is_a_list) { int notused; int bytes_read,curr_pos,count; int found = 0; *hasbody = 0; *is_a_list = 0; do { switch(read_buffer[position]) { /* white space removal */ case 0x0a: *line = *line + 1; position++; break; case 0x0d: /* handle the DOS non-sense */ position++; *line = *line + 1; if (read_buffer[position] == 0x0a) position++; else if (read_buffer[position] == 0xff) { fillBuffer(infile); if(read_buffer[position] == 0x0a) position++; else if (read_buffer[position] == 0xff) found = -1; } break; case 0x20: case 0x09: position++; break; case '\"': DiscardString(infile); /* check for comments */ case '-': DiscardComment(infile); break; /* check only for the first letters of the reserved words */ case 'E': case 'A': case 'C': case 'S': case 'P': case 'F': case 'T': case 'V': case 'B': case 'e': case 'a': case 'c': case 's': case 'p': case 'f': case 't': case 'v': case 'b': found = CheckReserved(infile,0); if (found == -1) { skipToWhite(infile); found = 0; } else if (found == BEGIN && in_architecture) { first_begin = 1; levelcount++; pack_level++; funcProc_level++; found = 0; } else if (found == END) { /* we have an end -- need to handle this */ position++; if ((found = CheckReserved(infile,1)) == -1) { skipToWhite(infile); } if (in_package) { if (found != CASE && found != IF) { pack_level--; if (pack_level <= 0) in_package = 0; } } if (in_funcProc) { if (found != CASE && found != IF) { funcProc_level--; if (funcProc_level <= 0) in_funcProc = 0; } } if (in_architecture) { if (found != CASE && found != IF) { levelcount--; if (found == ARCHITECTURE) { /* end architecture */ in_architecture = 0; } else if (first_begin && levelcount <= 0) { /* we have run out of levels */ in_architecture = 0; } } } found = 0; } break; /* using 0xff as the end of buffer marker */ case 0xff: if (my_eof) found = -1; else fillBuffer(infile); break; /* if it does not start with a reserved, then skip to next white */ default: skipToWhite(infile); } } while(!found); /* we have a reserved word, and we also know which one we have found * so lets get create the search string that we need */ if (found != -1) { switch(found) { case END: /* we want to lose the next token after the end */ GetToken(token,infile,¬used,0,NULL); token[0] = '\0'; *token_size = 0; break; case FUNCTION: /* <function> <token> <stuff> [is] --- problem definition and imp are no different! (well no 'is')*/ case PROCEDURE: /* <procedure> <token> <stuff> [is] --- problem definition and imp are no different! (well no 'is')*/ *token_size = GetToken(token,infile,operator,0,NULL); if (found_is(infile,line)) { /* function or procedure body --- start the funcProc grouping stuff */ in_funcProc = 1; funcProc_level = 0; memcpy(funcProc_token,token,*token_size); funcProc_token_size = *token_size; } break; case PACKAGE: /* <package> [<body>] <token> [is] */ *token_size = GetToken(token,infile,operator,0,NULL); if (tolower(token[0]) == 'b' && tolower(token[1]) == 'o' && tolower(token[2]) == 'd' && tolower(token[3]) == 'y' && token[4] == '\0') { *hasbody = 1; *token_size = GetToken(token,infile,operator,0,NULL); }else{ /* start the package group stuff */ in_package = 1; memcpy(pack_token,token,*token_size); pack_token_size = *token_size; pack_level = 0; } break; /* search string: "/\c<reserved>\s\+<name>/" */ case ARCHITECTURE: /* <architecture> <token> [of] <entity_name> <is> -- non-unique need the entity as well */ first_begin = 0; in_architecture = 1; levelcount = 0; *token_size = GetToken(token,infile,operator,0,NULL); memcpy(arch_token,token,*token_size); arch_token_size = *token_size; break; case SIGNAL: /* <signal> <token> [,<token>] ':' <other stuff> */ case VARIABLE: /* <variable> <token> [,<token>] ':' <stuff> */ *token_size = GetToken(token,infile,operator,1,is_a_list); break; case TYPE: /* <type> <token> 'is' <stuff> */ case COMPONENT: /* <component> <token> [is] */ case CONSTANT: /* <constant> <token> ':' <stuff> */ case SUBTYPE: /* <subtype> <token> 'is' <stuff> */ case ENTITY: /* <entity> <token> [of]*/ *token_size = GetToken(token,infile,operator,0,NULL); break; } } return found; }