// One of TinyXML's more performance demanding functions. Try to keep the memory overhead down. The // "assign" optimization removes over 10% of the execution time. // const char* TiXmlBase::ReadName( const char* p, TIXML_STRING * name, TiXmlEncoding encoding ) { // Oddly, not supported on some comilers, //name->clear(); // So use this: *name = ""; assert( p ); // Names start with letters or underscores. // Of course, in unicode, tinyxml has no idea what a letter *is*. The // algorithm is generous. // // After that, they can be letters, underscores, numbers, // hyphens, or colons. (Colons are valid ony for namespaces, // but tinyxml can't tell namespaces from names.) if ( p && *p && ( IsAlpha( (unsigned char) *p, encoding ) || *p == '_' ) ) { const char* start = p; while( p && *p && ( IsAlphaNum( (unsigned char ) *p, encoding ) || *p == '_' || *p == '-' || *p == '.' || *p == ':' ) ) { //(*name) += *p; // expensive ++p; } if ( p-start > 0 ) { name->assign( start, p-start ); } return p; } return 0; }
int CharFilterAlpha(int c) { return IsAlpha(c) ? c : 0; }
MDBXMLNode* MDBXMLNode::Identify( const char* p, MDBXMLEncoding encoding ) { MDBXMLNode* returnNode = 0; p = SkipWhiteSpace( p, encoding ); if( !p || !*p || *p != '<' ) { return 0; } MDBXMLDocument* doc = GetDocument(); p = SkipWhiteSpace( p, encoding ); if ( !p || !*p ) { return 0; } // What is this thing? // - Elements start with a letter or underscore, but xml is reserved. // - Comments: <!-- // - Decleration: <?xml // - Everthing else is unknown to tinyxml. // const char* xmlHeader = { "<?xml" }; const char* commentHeader = { "<!--" }; const char* dtdHeader = { "<!" }; const char* cdataHeader = { "<![CDATA[" }; if ( StringEqual( p, xmlHeader, true, encoding ) ) { #ifdef DEBUG_PARSER MDBXML_LOG( "XML parsing Declaration\n" ); #endif returnNode = new MDBXMLDeclaration(); } else if ( StringEqual( p, commentHeader, false, encoding ) ) { #ifdef DEBUG_PARSER MDBXML_LOG( "XML parsing Comment\n" ); #endif returnNode = new MDBXMLComment(); } else if ( StringEqual( p, cdataHeader, false, encoding ) ) { #ifdef DEBUG_PARSER MDBXML_LOG( "XML parsing CDATA\n" ); #endif MDBXMLText* text = new MDBXMLText( "" ); text->SetCDATA( true ); returnNode = text; } else if ( StringEqual( p, dtdHeader, false, encoding ) ) { #ifdef DEBUG_PARSER MDBXML_LOG( "XML parsing Unknown(1)\n" ); #endif returnNode = new MDBXMLUnknown(); } else if ( IsAlpha( *(p+1), encoding ) || *(p+1) == '_' ) { #ifdef DEBUG_PARSER MDBXML_LOG( "XML parsing Element\n" ); #endif returnNode = new MDBXMLElement( "" ); } else { #ifdef DEBUG_PARSER MDBXML_LOG( "XML parsing Unknown(2)\n" ); #endif returnNode = new MDBXMLUnknown(); } if ( returnNode ) { // Set the parent, so it can report errors returnNode->parent = this; } else { if ( doc ) doc->SetError( MDBXML_ERROR_OUT_OF_MEMORY, 0, 0, MDBXML_ENCODING_UNKNOWN ); } return returnNode; }
bool IsAlNum(char c) { return IsAlpha(c) || IsDigit(c); }
static UInt GetNumber(Int readDecimalPoint) { UInt symbol = S_ILLEGAL; UInt i = 0; Char c; UInt seenADigit = 0; UInt seenExp = 0; UInt seenExpDigit = 0; STATE(ValueObj) = 0; c = PEEK_CURR_CHAR(); if (readDecimalPoint) { STATE(Value)[i++] = '.'; } else { // read initial sequence of digits into 'Value' while (IsDigit(c)) { i = AddCharToValue(i, c); seenADigit = 1; c = GET_NEXT_CHAR(); } // maybe we saw an identifier character and realised that this is an // identifier we are reading if (IsIdent(c) || c == '\\') { // if necessary, copy back from STATE(ValueObj) to STATE(Value) if (STATE(ValueObj)) { i = GET_LEN_STRING(STATE(ValueObj)); GAP_ASSERT(i >= MAX_VALUE_LEN - 1); memcpy(STATE(Value), CONST_CSTR_STRING(STATE(ValueObj)), MAX_VALUE_LEN); STATE(ValueObj) = 0; } // this looks like an identifier, scan the rest of it return GetIdent(i); } // Or maybe we saw a '.' which could indicate one of two things: a // float literal or S_DOT, i.e., '.' used to access a record entry. if (c == '.') { GAP_ASSERT(i < MAX_VALUE_LEN - 1); // If the symbol before this integer was S_DOT then we must be in // a nested record element expression, so don't look for a float. // This is a bit fragile if (STATE(Symbol) == S_DOT || STATE(Symbol) == S_BDOT) { symbol = S_INT; goto finish; } // peek ahead to decide which if (PEEK_NEXT_CHAR() == '.') { // It was '.', so this looks like '..' and we are probably // inside a range expression. symbol = S_INT; goto finish; } // Now the '.' must be part of our number; store it and move on i = AddCharToValue(i, '.'); c = GET_NEXT_CHAR(); } else { // Anything else we see tells us that the token is done symbol = S_INT; goto finish; } } // When we get here we have read possibly some digits, a . and possibly // some more digits, but not an e,E,d,D,q or Q // read digits while (IsDigit(c)) { i = AddCharToValue(i, c); seenADigit = 1; c = GET_NEXT_CHAR(); } if (!seenADigit) SyntaxError("Badly formed number: need a digit before or after the " "decimal point"); if (c == '\\') SyntaxError("Badly formed number"); // If we found an identifier type character in this context could be an // error or the start of one of the allowed trailing marker sequences if (IsIdent(c) && c != 'e' && c != 'E' && c != 'd' && c != 'D' && c != 'q' && c != 'Q') { // Allow one letter on the end of the numbers -- could be an i, C99 // style if (IsAlpha(c)) { i = AddCharToValue(i, c); c = GET_NEXT_CHAR(); } // independently of that, we allow an _ signalling immediate conversion if (c == '_') { i = AddCharToValue(i, c); c = GET_NEXT_CHAR(); // After which there may be one character signifying the // conversion style if (IsAlpha(c)) { i = AddCharToValue(i, c); c = GET_NEXT_CHAR(); } } // Now if the next character is alphanumerical, or an identifier type // symbol then we really do have an error, otherwise we return a result if (IsIdent(c) || IsDigit(c)) { SyntaxError("Badly formed number"); } else { symbol = S_FLOAT; goto finish; } } // If the next thing is the start of the exponential notation, read it now. if (IsAlpha(c)) { if (!seenADigit) SyntaxError("Badly formed number: need a digit before or after " "the decimal point"); seenExp = 1; i = AddCharToValue(i, c); c = GET_NEXT_CHAR(); if (c == '+' || c == '-') { i = AddCharToValue(i, c); c = GET_NEXT_CHAR(); } } // Either we saw an exponent indicator, or we hit end of token deal with // the end of token case if (!seenExp) { if (!seenADigit) SyntaxError("Badly formed number: need a digit before or after " "the decimal point"); // Might be a conversion marker if (IsAlpha(c) && c != 'e' && c != 'E' && c != 'd' && c != 'D' && c != 'q' && c != 'Q') { i = AddCharToValue(i, c); c = GET_NEXT_CHAR(); } // independently of that, we allow an _ signalling immediate conversion if (c == '_') { i = AddCharToValue(i, c); c = GET_NEXT_CHAR(); // After which there may be one character signifying the // conversion style if (IsAlpha(c)) i = AddCharToValue(i, c); c = GET_NEXT_CHAR(); } // Now if the next character is alphanumerical, or an identifier type // symbol then we really do have an error, otherwise we return a result if (!IsIdent(c) && !IsDigit(c)) { symbol = S_FLOAT; goto finish; } SyntaxError("Badly formed number"); } // Here we are into the unsigned exponent of a number in scientific // notation, so we just read digits while (IsDigit(c)) { i = AddCharToValue(i, c); seenExpDigit = 1; c = GET_NEXT_CHAR(); } // Look out for a single alphabetic character on the end // which could be a conversion marker if (seenExpDigit) { if (IsAlpha(c)) { i = AddCharToValue(i, c); c = GET_NEXT_CHAR(); symbol = S_FLOAT; goto finish; } if (c == '_') { i = AddCharToValue(i, c); c = GET_NEXT_CHAR(); // After which there may be one character signifying the // conversion style if (IsAlpha(c)) { i = AddCharToValue(i, c); c = GET_NEXT_CHAR(); } symbol = S_FLOAT; goto finish; } } // Otherwise this is the end of the token if (!seenExpDigit) SyntaxError( "Badly formed number: need at least one digit in the exponent"); symbol = S_FLOAT; finish: i = AddCharToValue(i, '\0'); if (STATE(ValueObj)) { // flush buffer AppendBufToString(STATE(ValueObj), STATE(Value), i - 1); } return symbol; }
void CfgNextTok (void) /* Read the next token from the input stream */ { unsigned I; Again: /* Skip whitespace */ while (isspace (C)) { NextChar (); } /* Remember the current position */ CfgErrorLine = InputLine; CfgErrorCol = InputCol; /* Identifier? */ if (C == '_' || IsAlpha (C)) { /* Read the identifier */ I = 0; while (C == '_' || IsAlNum (C)) { if (I < CFG_MAX_IDENT_LEN) { CfgSVal [I++] = C; } NextChar (); } CfgSVal [I] = '\0'; CfgTok = CFGTOK_IDENT; return; } /* Hex number? */ if (C == '$') { NextChar (); if (!isxdigit (C)) { Error ("%s(%u): Hex digit expected", CfgName, InputLine); } CfgIVal = 0; while (isxdigit (C)) { CfgIVal = CfgIVal * 16 + DigitVal (C); NextChar (); } CfgTok = CFGTOK_INTCON; return; } /* Decimal number? */ if (isdigit (C)) { CfgIVal = 0; while (isdigit (C)) { CfgIVal = CfgIVal * 10 + DigitVal (C); NextChar (); } CfgTok = CFGTOK_INTCON; return; } /* Other characters */ switch (C) { case '{': NextChar (); CfgTok = CFGTOK_LCURLY; break; case '}': NextChar (); CfgTok = CFGTOK_RCURLY; break; case ';': NextChar (); CfgTok = CFGTOK_SEMI; break; case '.': NextChar (); if (C == '.') { NextChar (); CfgTok = CFGTOK_DOTDOT; } else { CfgTok = CFGTOK_DOT; } break; case ',': NextChar (); CfgTok = CFGTOK_COMMA; break; case '=': NextChar (); CfgTok = CFGTOK_EQ; break; case ':': NextChar (); CfgTok = CFGTOK_COLON; break; case '\"': NextChar (); I = 0; while (C != '\"') { if (C == EOF || C == '\n') { Error ("%s(%u): Unterminated string", CfgName, InputLine); } if (I < CFG_MAX_IDENT_LEN) { CfgSVal [I++] = C; } NextChar (); } NextChar (); CfgSVal [I] = '\0'; CfgTok = CFGTOK_STRCON; break; case '#': /* Comment */ while (C != '\n' && C != EOF) { NextChar (); } if (C != EOF) { goto Again; } CfgTok = CFGTOK_EOF; break; case EOF: CfgTok = CFGTOK_EOF; break; default: Error ("%s(%u): Invalid character `%c'", CfgName, InputLine, C); } }
void AsmInc (const char* Filename, char CommentStart, int IgnoreUnknown) /* Read an assembler include file */ { char Buf[1024]; char* L; const char* Comment; unsigned Line; unsigned Len; long Val; unsigned DVal; int Sign; unsigned Base; unsigned Digits; StrBuf Ident = STATIC_STRBUF_INITIALIZER; /* Try to open the file for reading */ FILE* F = fopen (Filename, "r"); if (F == 0) { Error ("Cannot open asm include file \"%s\": %s", Filename, strerror (errno)); } /* Read line by line, check for NAME = VALUE lines */ Line = 0; while ((L = fgets (Buf, sizeof (Buf), F)) != 0) { /* One more line read */ ++Line; /* Ignore leading white space */ while (IsBlank (*L)) { ++L; } /* Remove trailing whitespace */ Len = strlen (L); while (Len > 0 && IsSpace (L[Len-1])) { --Len; } L[Len] = '\0'; /* If the line is empty or starts with a comment char, ignore it */ if (*L == '\0' || *L == CommentStart) { continue; } /* Read an identifier */ SB_Clear (&Ident); if (IsAlpha (*L) || *L == '_') { SB_AppendChar (&Ident, *L++); while (IsAlNum (*L) || *L == '_') { SB_AppendChar (&Ident, *L++); } SB_Terminate (&Ident); } else { if (!IgnoreUnknown) { Error ("%s(%u): Syntax error", Filename, Line); } continue; } /* Ignore white space */ L = SkipWhitespace (L); /* Check for := or = */ if (*L == '=') { ++L; } else if (*L == ':' && *++L == '=') { ++L; } else { if (!IgnoreUnknown) { Error ("%s(%u): Missing `='", Filename, Line); } continue; } /* Allow white space once again */ L = SkipWhitespace (L); /* A number follows. Read the sign. */ if (*L == '-') { Sign = -1; ++L; } else { Sign = 1; if (*L == '+') { ++L; } } /* Determine the base of the number. Allow $ and % as prefixes for * hex and binary numbers respectively. */ if (*L == '$') { Base = 16; ++L; } else if (*L == '%') { Base = 2; ++L; } else { Base = 10; } /* Decode the number */ Digits = 0; Val = 0; while (IsXDigit (*L) && (DVal = DigitVal (*L)) < Base) { Val = (Val * Base) + DVal; ++Digits; ++L; } /* Must have at least one digit */ if (Digits == 0) { if (!IgnoreUnknown) { Error ("%s(%u): Error in number format", Filename, Line); } continue; } /* Skip whitespace again */ L = SkipWhitespace (L); /* Check for a comment */ if (*L == CommentStart) { Comment = SkipWhitespace (L+1); if (*Comment == '\0') { Comment = 0; } } else { Comment = 0; } /* Check for a comment character or end of line */ if (*L != CommentStart && *L != '\0') { if (!IgnoreUnknown) { Error ("%s(%u): Trailing garbage", Filename, Line); } continue; } /* Apply the sign */ Val *= Sign; /* Define the symbol and the comment */ AddExtLabel (Val, SB_GetConstBuf (&Ident)); SetComment (Val, Comment); } /* Delete the string buffer contents */ SB_Done (&Ident); /* Close the include file ignoring errors (we were just reading). */ (void) fclose (F); }
bool CgaLexer::IsAlphaNumeric(char c) { return IsAlpha(c) || IsDigit(c); }
static inline bool IsAlphaOrUnderscore(char c) { return IsAlpha(c) || (c == '_'); }
static inline bool IsAlphaNumeric(char c) { return IsAlpha(c) || IsDigit(c); }
static String FormatStopwatch(int64 us, const String& format) { String result, keyPattern; if (us < 0) { result.push_back(U'-'); us = -us; } bool inQuot = false; char32 previousChar = U'\0'; for (size_t i = 0; i < format.length(); ++i) { const char32 ch = format[i]; if (IsAlpha(ch)) { if (inQuot) { result.push_back(ch); } else { if (keyPattern.isEmpty() || ch == previousChar) { keyPattern.push_back(ch); } else { result.append(GetFormattedElement(us, keyPattern)); keyPattern.clear(); keyPattern.push_back(ch); } } } else { if (!keyPattern.isEmpty()) { result.append(GetFormattedElement(us, keyPattern)); keyPattern.clear(); } if (ch == U'\'') { if (format[i + 1] == U'\'') { result.push_back(U'\''); ++i; continue; } inQuot = !inQuot; } else { result.push_back(ch); } } previousChar = ch; } if (!keyPattern.isEmpty()) { result.append(GetFormattedElement(us, keyPattern)); } return result; }
/** * @brief Checks if current character is alphanumeric (a-z|0-9). * * @return */ bool IsAlphaNumberic() const { return IsAlpha() || IsRange('0', '9'); }
bool wxSimpleHtmlParser::IsWord() { return (IsAlpha(GetChar(m_pos))); }
int CharFilterAlphaToLower(int c) { return IsAlpha(c) ? IsLower(c) ? c : ToLower(c) : 0; }
int CharFilterAlphaToUpper(int c) { return IsAlpha(c) ? IsUpper(c) ? c : ToUpper(c) : 0; }
void CSModuleWriter::GenerateManagedEnumsAndConstants(String& source) { Vector<SharedPtr<JSBEnum>> enums = module_->enums_.Values(); Indent(); for (unsigned i = 0; i < enums.Size(); i++) { JSBEnum* jenum = enums[i]; source += "\n"; String line = "public enum " + jenum->GetName() + "\n"; source += IndentLine(line); source += IndentLine("{\n"); HashMap<String, String>& values = jenum->GetValues(); HashMap<String, String>::ConstIterator itr = values.Begin(); Indent(); while (itr != values.End()) { String name = (*itr).first_; String value = (*itr).second_; if (value.Length()) { line = name + " = " + value; } else { line = name; } itr++; if (itr != values.End()) line += ","; line += "\n"; source += IndentLine(line); } Dedent(); source += IndentLine("}\n"); } // constants HashMap<String, JSBModule::Constant>& constants = module_->GetConstants(); if (constants.Size()) { source += "\n"; String line = "public static partial class Constants\n"; source += IndentLine(line); source += IndentLine("{\n"); const Vector<String>& constantsName = constants.Keys(); Indent(); for (unsigned i = 0; i < constantsName.Size(); i++) { const String& cname = constantsName.At(i); JSBModule::Constant& constant = constants[cname]; String managedType = GetManagedPrimitiveType(constant.type); String value = constant.value; if (!value.Length()) continue; //static const unsigned M_MIN_UNSIGNED = 0x00000000; // /static const unsigned M_MAX_UNSIGNED = 0xffffffff; if (cname == "M_MIN_INT") value = "int.MinValue"; if (cname == "M_INFINITY") value = "float.MaxValue"; if (value == "M_MAX_UNSIGNED") value = "0xffffffff"; // Input stuff if (module_->GetName() == "Input") { if (cname.StartsWith("KEY_")) { if (value.Length() == 1 && (IsAlpha(value[0]) || IsDigit(value[0]))) value = "'" + value + "'"; } // https://raw.githubusercontent.com/flibitijibibo/SDL2-CS/master/src/SDL2.cs if (value.StartsWith("SDL_BUTTON_") || value.StartsWith("SDL_HAT_")) { value = "(int) SDL." + value; } else if (value.StartsWith("SDLK_")) { value = "(int) SDL.SDL_Keycode." + value; } else if (value.StartsWith("SDL_SCANCODE_")) { value = "(int) SDL.SDL_Scancode." + value; } else if (value.StartsWith("SDL_CONTROLLER_BUTTON_")) { value = "(int) SDL.SDL_GameControllerButton." + value; } else if (value.StartsWith("SDL_CONTROLLER_AXIS_")) { value = "(int) SDL.SDL_GameControllerAxis." + value; } } String line = "public const " + managedType + " " + cname + " = " + value; if (managedType == "float" && !line.EndsWith("f") && IsDigit(line[line.Length()-1])) line += "f"; line += ";\n"; source += IndentLine(line); } Dedent(); source += "\n"; line = "}\n"; source += IndentLine(line); } source += "\n"; Dedent(); }
void ParseCommand(char *string) { char Command; char Command2 = 0; unsigned int Params[MAX_COMMAND_PARAMS]; unsigned int NumParams=0; /* UsartWriteString("Command Received: "); UsartWriteString(string); UsartWriteString("\n\r"); */ // assume commands are single character followed by numerical parameters sep by spaces // e.g. "s 1 5", "b 7", "b 100 120 001 212 123" Command = string[0]; if(IsAlpha(string[1])) // multi-char command (e.g. pa, oa, ia, etc) Command2 = string[1]; if(Command != 0) { NumParams=GetParams(string,Params); // read any optional parameters after command /* UsartWriteString("CommandID: "); UsartWriteChar(Command); if(Command2 != 0) UsartWriteChar(Command2); UsartWriteString(" #Params: "); UsartWriteChar(48+NumParams); UsartWriteString("\n\r"); */ } else { UsartWriteString("No Command\n\r"); }; unsigned short lcdDataIn; static char buffer[10]; switch(Command) { case 'a': // ADC do immediate conversion PORTQ.OUTCLR = PIN0_bm | PIN2_bm; //ENCODE pins _delay_ms(1); PORTQ.OUTSET = PIN0_bm | PIN2_bm; _delay_ms(1); char value = PORTD.IN; IntToString(value,&buffer[0]); UsartWriteLine(buffer); break; case 'b': // read imager flag PORTA.DIR &= ~0x01; char bb6 = PORTA.IN & 0x01; IntToString(bb6,&buffer[0]); UsartWriteLine(buffer); break; case 'y': // Start Image frame = 0; start_interrupts(); break; case 'z': // Stop Image stop_interrupts(); break; case 'l': lcdDataIn = TSLCDInDat(); IntToString(lcdDataIn,&buffer[0]); UsartWriteLine(buffer); break; case 'x': IntToString(4,&buffer[0]); UsartWriteLine(buffer); break; case 'T': // Usart TX test DoUsartTx(Command2,Params[0],"0123456789"); break; case 'S': // Config SPI port DoSpiConfig(Command2,Params[0]); break; case 'X': // SPI TX test DoSpiTx(Command2,"0123456789"); break; case 's': // Sleep CPU DoSleep(Params[0]); // this will not return break; case 'O': // Set oscillator source DoOscillator(Params[0]); // this will not return break; case 'h': // Usage break; }; return; };
NNT Lexer::NextOperator() { switch (*cursor) { case '`': IncrementCursor(); RETURN_NNT("`", op_bl, 1); case '@': IncrementCursor(); RETURN_NNT("@", op_l, 1); case ',': IncrementCursor(); RETURN_NNT(",", comma, 1); case ';': IncrementCursor(); RETURN_NNT(";", semicolon, 1); case '(': IncrementCursor(); RETURN_NNT("(", l_paren, 1); case ')': IncrementCursor(); RETURN_NNT(")", r_paren, 1); case '[': IncrementCursor(); RETURN_NNT("[", l_bracket, 1); case ']': IncrementCursor(); RETURN_NNT("]", r_bracket, 1); case '{': IncrementCursor(); RETURN_NNT("{", l_brace, 1); case '}': IncrementCursor(); RETURN_NNT("}", r_brace, 1); case '$': IncrementCursor(); RETURN_NNT("$", op_l, 1); case '.': { Cursor cursor_copy = cursor; // Note: safe because we know we have a null-terminator while (*cursor == '.') { IncrementCursor(); } size_t num_dots = cursor.offset - cursor_copy.offset; if (num_dots == 1) { RETURN_NNT(".", op_b, 1); } else { if (num_dots > 2) { ErrorLog::TooManyDots(cursor_copy, num_dots); } RETURN_NNT("..", dots, 2); } } break; case '\\': { Cursor cursor_copy = cursor; size_t dist = 1; IncrementCursor(); ++dist; switch(*cursor) { case '\\': IncrementCursor(); RETURN_NNT("", newline, 0); break; case '\0': // Ignore the following newline IncrementCursor(); return Next(); case ' ': case '\t': while (IsWhitespace(*cursor)) { IncrementCursor(); ++dist; } if (*cursor == '\0') { IncrementCursor(); return Next(); } // Intentionally falling through. Looking at a non-whitespace after a '\' default: ErrorLog::NonWhitespaceAfterNewlineEscape(cursor_copy, dist); return Next(); } } break; case '#': { IncrementCursor(); Cursor cursor_copy = cursor; if (!IsAlpha(*cursor)) { ErrorLog::InvalidHashtag(cursor_copy); return Next(); } do { IncrementCursor(); } while (IsAlphaNumericOrUnderscore(*cursor)); if (cursor.offset - cursor_copy.offset == 0) { ErrorLog::InvalidHashtag(cursor_copy); } char old_char = *cursor; *cursor = '\0'; const char *tag_ref = cursor.line.ptr + cursor_copy.offset; size_t tag_len = strlen(tag_ref); char *tag = new char[tag_len + 1]; strcpy(tag, tag_ref); *cursor = old_char; RETURN_NNT(tag, hashtag, tag_len + 1); } break; case '+': case '%': case '<': case '>': case '|': case '^': { char first_char = *cursor; IncrementCursor(); char *token = new char[3]; token[0] = first_char; if (*cursor == '=') { IncrementCursor(); token[1] = '='; } else { token[1] = '\0'; } token[2] = '\0'; RETURN_NNT(token, op_b, strlen(token)); } break; case '*': IncrementCursor(); if (*cursor == '/') { IncrementCursor(); if (*cursor == '/') { // Looking at "*//" which should be parsed as an asterisk followed by a // one-line comment. BackUpCursor(); RETURN_NNT("*", op_b, 1); } else { Cursor cursor_copy = cursor; cursor_copy.offset -= 2; ErrorLog::NotInMultilineComment(cursor_copy); return Next(); } } else if (*cursor == '=') { IncrementCursor(); RETURN_NNT("*=", op_b, 2); } else { RETURN_NNT("*", op_b, 1); } case '&': { IncrementCursor(); if (*cursor == '=') { IncrementCursor(); RETURN_NNT("&=", op_b, 2); } else { RETURN_NNT("&", op_bl, 1); } } break; case ':': { IncrementCursor(); if (*cursor == '=') { IncrementCursor(); RETURN_NNT(":=", op_b, 2); } else if (*cursor == '>') { IncrementCursor(); RETURN_NNT(":>", op_b, 2); } else { RETURN_NNT(":", colon, 1); } } break; case '!': { IncrementCursor(); if (*cursor == '=') { IncrementCursor(); RETURN_NNT("!=", op_b, 2); } else { RETURN_NNT("!", op_l, 1); } } break; case '-': { IncrementCursor(); if (*cursor == '=') { IncrementCursor(); RETURN_NNT("-=", op_b, 2); } else if (*cursor == '>') { IncrementCursor(); auto nptr = new AST::TokenNode(cursor, "->"); nptr->op = Language::Operator::Arrow; return NNT(nptr, Language::fn_arrow); } else if (*cursor == '-') { IncrementCursor(); RETURN_TERMINAL(Hole, Unknown, IR::Value::None()); } else { RETURN_NNT("-", op_bl, 1); } } break; case '=': { IncrementCursor(); if (*cursor == '=') { IncrementCursor(); RETURN_NNT("==", op_b, 2); } else if (*cursor == '>') { IncrementCursor(); RETURN_NNT("=>", op_b, 2); } else { RETURN_NNT("=", eq, 1); } } break; case '/': { IncrementCursor(); if (*cursor == '/') { // Ignore comments altogether SkipToEndOfLine(); return Next(); } else if (*cursor == '=') { IncrementCursor(); RETURN_NNT("/=", op_b, 2); } else if (*cursor == '*') { IncrementCursor(); char back_one = *cursor; IncrementCursor(); size_t comment_layer = 1; while (comment_layer != 0) { if (ifs.eof()) { ErrorLog::RunawayMultilineComment(); RETURN_NNT("", eof, 0); } else if (back_one == '/' && *cursor == '*') { ++comment_layer; } else if (back_one == '*' && *cursor == '/') { --comment_layer; } back_one = *cursor; IncrementCursor(); } // Ignore comments altogether return Next(); } else { RETURN_NNT("/", op_b, 1); } } break; case '"': { IncrementCursor(); std::string str_lit = ""; while (*cursor != '"' && *cursor != '\0') { if (*cursor == '\\') { IncrementCursor(); switch (*cursor) { case '\'': { str_lit += '\''; Cursor cursor_copy = cursor; --cursor_copy.offset; ErrorLog::EscapedSingleQuoteInStringLit(cursor_copy); } break; case '\\': str_lit += '\\'; break; case '"': str_lit += '"'; break; case 'a': str_lit += '\a'; break; case 'b': str_lit += '\b'; break; case 'f': str_lit += '\f'; break; case 'n': str_lit += '\n'; break; case 'r': str_lit += '\r'; break; case 't': str_lit += '\t'; break; case 'v': str_lit += '\v'; break; default: { Cursor cursor_copy = cursor; --cursor_copy.offset; ErrorLog::InvalidEscapeCharInStringLit(cursor_copy); str_lit += *cursor; } break; } } else { str_lit += *cursor; } IncrementCursor(); } if (*cursor == '\0') { ErrorLog::RunawayStringLit(cursor); } else { IncrementCursor(); } // Not leaked. It's owned by a terminal which is persistent. char *cstr = new char[str_lit.size() + 2]; strcpy(cstr + 1, str_lit.c_str()); cstr[0] = '\1'; RETURN_TERMINAL(StringLiteral, String, IR::Value(cstr)); } break; case '\'': { IncrementCursor(); char result; switch (*cursor) { case '\t': ErrorLog::TabInCharLit(cursor); result = '\t'; break; case '\0': { ErrorLog::RunawayCharLit(cursor); RETURN_TERMINAL(Char, Char, IR::Value::Char('\0')); } case '\\': { IncrementCursor(); switch (*cursor) { case '\"': { result = '"'; Cursor cursor_copy = cursor; --cursor_copy.offset; ErrorLog::EscapedDoubleQuoteInCharLit(cursor_copy); } break; case '\\': result = '\\'; break; case '\'': result = '\''; break; case 'a': result = '\a'; break; case 'b': result = '\b'; break; case 'f': result = '\f'; break; case 'n': result = '\n'; break; case 'r': result = '\r'; break; case 't': result = '\t'; break; case 'v': result = '\v'; break; default: Cursor cursor_copy = cursor; --cursor_copy.offset; ErrorLog::InvalidEscapeCharInCharLit(cursor_copy); result = *cursor; } break; } default: { result = *cursor; } break; } IncrementCursor(); if (*cursor == '\'') { IncrementCursor(); } else { ErrorLog::RunawayCharLit(cursor); } RETURN_TERMINAL(Char, Char, IR::Value::Char(result)); } break; case '?': ErrorLog::InvalidCharQuestionMark(cursor); IncrementCursor(); return Next(); case '~': ErrorLog::InvalidCharTilde(cursor); IncrementCursor(); return Next(); case '_': UNREACHABLE; default: UNREACHABLE; } }
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); }
bool Pxf::IsAlphanumeric(const char c) { return IsAlpha(c) || IsNumeric(c) || c == '_'; }
bool CWebPageDef::ServPagePost( CClient * pClient, LPCTSTR pszURLArgs, TCHAR * pContentData, int iContentLength ) { ADDTOCALLSTACK("CWebPageDef::ServPagePost"); UNREFERENCED_PARAMETER(pszURLArgs); // RETURN: true = this was the page of interest. ASSERT(pClient); if ( pContentData == NULL || iContentLength <= 0 ) return( false ); if ( ! HasTrigger(XTRIG_UNKNOWN)) // this form has no triggers. return( false ); // Parse the data. pContentData[iContentLength] = 0; TCHAR * ppArgs[64]; size_t iArgs = Str_ParseCmds(pContentData, ppArgs, COUNTOF(ppArgs), "&"); if (( iArgs <= 0 ) || ( iArgs >= 63 )) return false; // T or TXT or TEXT = the text fields. // B or BTN or BUTTON = the buttons // C or CHK or CHECK = the check boxes CDialogResponseArgs resp; DWORD dwButtonID = ULONG_MAX; for ( size_t i = 0; i < iArgs; i++ ) { TCHAR * pszNum = ppArgs[i]; while ( IsAlpha(*pszNum) ) pszNum++; int iNum = ATOI(pszNum); while ( *pszNum ) { if ( *pszNum == '=' ) { pszNum++; break; } pszNum++; } switch ( toupper(ppArgs[i][0]) ) { case 'B': dwButtonID = iNum; break; case 'C': if ( !iNum ) continue; if ( ATOI(pszNum) ) { resp.m_CheckArray.Add( iNum ); } break; case 'T': if ( iNum > 0 ) { TCHAR *pszData = Str_GetTemp(); HtmlDeCode( pszData, pszNum ); resp.AddText(static_cast<WORD>(iNum), pszData); } break; } } // Use the data in RES_WEBPAGE block. CResourceLock s; if ( !ResourceLock(s) ) return false; // Find the correct entry point. while ( s.ReadKeyParse()) { if ( !s.IsKeyHead("ON", 2) || ( (DWORD)s.GetArgVal() != dwButtonID )) continue; OnTriggerRunVal(s, TRIGRUN_SECTION_TRUE, pClient, &resp); return true; } // Put up some sort of failure page ? return( false ); }
void VfkStream::ScanFile(int fx) { RTIMING("VfkStream::ScanFile"); Stream& strm = streams[fx]; int64 last_line = strm.GetSize(); while(last_line > 0) { strm.Seek(last_line - 1); if(strm.Get() == '\n') break; last_line--; } strm.Seek(0); try { int c; int64 rowpos = strm.GetPos(); while((c = strm.Get()) == '&' && ((c = strm.Get()) == 'H' || c == 'D') && IsAlpha(strm.Term())) { char type = c; int64 begin = strm.GetPos(); SkipRow(strm); rowpos = strm.GetPos(); int len = (int)(strm.GetPos() - begin); StringBuffer linebuf(len + 1); strm.Seek(begin); strm.Get(linebuf, len); linebuf[len] = 0; const char *b = linebuf; const char *id = b; while(IsIdent(*++b)) ; String ident(id, b); if(*b++ != ';') throw Exc(NFormat("';' expected after '%s' (found: '%c', %2:02x)", ident, *b)); if(type == 'D') { String fident = "X_" + ident; int f = tables.Find(fident); if(f < 0) throw Exc(NFormat("unexpected data for filter table '%s'", ident)); // b = ScanRow(b, tables[f]); } else if(IsAlpha(*b)) { String fident = "X_" + ident; Table& tbl = tables.GetAdd(fident); tbl.name = tbl.rawname = fident; tbl.row_count = 0; ScanHeader(b, tbl); } else { do { Vector<Value> row; row.SetCount(HDR_COUNT); if(*b == '\"') { WString text = ReadString(b, &b); if(IsDateTime(ident) && !IsNull(text)) { Time dt = VfkReadTime(text.ToString(), NULL); if(IsNull(dt)) throw Exc(NFormat("invalid date/time value %s", AsCString(text.ToString()))); row[HDR_DTM] = dt; } else { row[HDR_STR] = text; if(ident == "CODEPAGE") if(text == WString("EE8MSWIN1250")) charset = CHARSET_WIN1250; } } else { double num = ScanDouble(b, &b); if(IsNull(num)) throw Exc("invalid numeric value"); row[HDR_NUM] = num; } int l = header.FindLast(ident); row[HDR_ID] = ident; row[HDR_ORD] = (l >= 0 ? (int)header[l][HDR_ORD] + 1 : 0); header.Add(ident) = row; } while(*b++ == ';'); b--; } } strm.Seek(rowpos); while(strm.Get() == '&' && strm.Get() == 'B' && IsAlpha(strm.Term())) { int64 header_offset = strm.GetPos(); SkipRow(strm); int64 begin_offset = strm.GetPos(); int len = (int)(begin_offset - header_offset); Buffer<char> linebuf(len + 1); strm.Seek(header_offset); strm.Get(linebuf, len); linebuf[len] = 0; const char *b = linebuf; const char *id = b; while(IsIdent(*++b)) ; int idlen = b - id; String ident(id, b); if(*b++ != ';') throw Exc(NFormat("';' expected after '%s' (found: '%c', %2:02x)", ident, *b)); String name = ident; for(const VFKLongName *ln = vfk_long_names; ln->shortname; ln++) if(name == ln->shortname) { name = ln->longname; break; } Table& tbl = tables.GetAdd(name); tbl.name = name; tbl.rawname = ident; ScanHeader(b, tbl); int64 p = begin_offset, e = last_line; Buffer<char> idbuf(idlen + 3); while(p < e) { int64 m = (p + e) >> 1; while(m > p) { char part[100]; int partsize = (int)min<int64>(m - p, sizeof(part)); strm.Seek(m - partsize); strm.Get(part, partsize); const char *x = &part[partsize]; while(x > part && x[-1] != '\n') x--; int lfpos = x - part; if(x > part && --x > part && x[-1] == '\r') x--; m -= partsize - lfpos; if(x <= part) continue; if(*--x != '\xA4') break; m -= lfpos - (x - part); } strm.Seek(m); if(strm.Get(idbuf, idlen + 3) != idlen + 3 || idbuf[0] != '&' || idbuf[1] != 'D' || memcmp(~idbuf + 2, id, idlen) || idbuf[idlen + 2] != ';') e = m; else { SkipRow(strm); p = strm.GetPos(); } } int xgrp = file_groups.GetKey(fx); int f; for(f = 0; f < tbl.file_index.GetCount(); f++) if(file_groups.GetKey(tbl.file_index[f]) == xgrp) break; if(f >= tbl.file_index.GetCount()) { tbl.file_index.Add(fx); tbl.begin_offset.Add(begin_offset); tbl.end_offset.Add(p); } strm.Seek(p); } } catch(Exc e) { throw Exc(NFormat("%s (offset %n): %s", file_groups[fx], strm.GetPos(), e)); } }
int match(const char *mask, const char *name) { const u_char *m = (const u_char *)mask, *n = (const u_char *)name; const char *ma = mask, *na = name; int wild = 0, q = 0, calls = 0; if (!mask || !name) return 1; /* if the mask is "*", it matches everything */ if ((*m == '*') && (*(m + 1) == '\0')) return 0; while (1) { #ifdef MAX_ITERATIONS if (calls++ > MAX_ITERATIONS) break; #endif if (*m == '*') { while (*m == '*') m++; wild = 1; ma = (const char *)m; na = (const char *)n; } if (!*m) { if (!*n) return 0; for (m--; (m > (const u_char *) mask) && (*m == '?' || *m == '&' || *m == '#'); m--) ; if ((m > (const u_char *) mask) && (*m == '*') && (m[-1] != '\\')) return 0; if (!wild) return 1; m = (const u_char *) ma; n = (const u_char *)++ na; } else if (!*n) return 1; if ((*m == '\\') && ((m[1] == '*') || (m[1] == '?') || (m[1] == '&') || (m[1] == '#') || (m[1] == '%'))) { m++; q = 1; } else q = 0; if ((ToLower(*m) != ToLower(*n)) && (((*m != '?') && !(*m == '&' && IsAlpha(*n)) && !(*m == '#' && IsDigit(*n)) && !(*m == '%' && IsNon(*n))) || q)) { if (!wild) return 1; m = (const u_char *) ma; n = (const u_char *)++ na; } else { if (*m) m++; if (*n) n++; } } return 1; }
String CppMacro::Expand(const Vector<String>& p, const Vector<String>& ep) const { String r; const char *s = body; String pp = param; bool variadic = false; if(*pp.Last() == '.') { variadic = true; pp.Trim(pp.GetCount() - 1); } Index<String> param(Split(pp, ',')); static String VA_ARGS("__VA_ARGS__"); // static - Speed optimization while(*s) { if(IsAlpha(*s) || *s == '_') { const char *b = s; s++; while(IsAlNum(*s) || *s == '_') s++; String id(b, s); const char *ss = b; bool cat = false; while(ss > ~body && ss[-1] == ' ') ss--; if(ss >= ~body + 2 && ss[-1] == '#' && ss[-2] == '#') cat = true; ss = s; while(*ss && *ss == ' ') ss++; if(ss[0] == '#' && ss[1] == '#') cat = true; if(id == VA_ARGS) { bool next = false; for(int i = param.GetCount(); i < ep.GetCount(); i++) { if(next) r.Cat(", "); r.Cat((cat ? p : ep)[i]); next = true; } } else { int q = param.Find(id); if(q >= 0) { if(q < ep.GetCount()) r.Cat((cat ? p : ep)[q]); } else r.Cat(id); } continue; } if(s[0] == '#' && s[1] == '#') { int q = r.GetLength(); while(q > 0 && IsSpc(r[q - 1])) q--; r.Trim(q); s += 2; while((byte)*s <= ' ') s++; continue; } if(*s == '#') { const char *ss = s + 1; while(IsSpc(*ss)) ss++; if(IsAlpha(*ss) || *ss == '_') { const char *b = ss; ss++; while(IsAlNum(*ss) || *ss == '_') ss++; String id(b, ss); int q = param.Find(id); if(q >= 0) { if(q <= p.GetCount()) { if(q < p.GetCount()) r.Cat(AsCString(p[q])); s = ss; continue; } } r.Cat(String(s, ss)); s = ss; continue; } } r.Cat(*s++); } return r; }
/**************************************************************************** ** *F NextSymbol() . . . . . . . . . . . . . . . . . get the next symbol, local ** ** 'NextSymbol' reads the next symbol from the input, storing it in the ** variable 'STATE(Symbol)'. If 'STATE(Symbol)' is 'S_IDENT', 'S_INT', ** 'S_FLOAT' or 'S_STRING' the value of the symbol is stored in ** 'STATE(Value)' or 'STATE(ValueObj)'. 'NextSymbol' first skips all ** <space>, <tab> and <newline> characters and comments. ** ** After reading a symbol the current character is the first character ** beyond that symbol. */ static UInt NextSymbol(void) { STATE(SymbolStartLine) = GetInputLineNumber(); STATE(SymbolStartPos) = GetInputLinePosition(); Char c = PEEK_CURR_CHAR(); // if no character is available then get one if (c == '\0') { STATE(In)--; c = GET_NEXT_CHAR(); } // skip over <spaces>, <tabs>, <newlines> and comments while (c == ' ' || c == '\t' || c== '\n' || c== '\r' || c == '\f' || c=='#') { if (c == '#') SKIP_TO_END_OF_LINE(); c = GET_NEXT_CHAR(); } STATE(SymbolStartLine) = GetInputLineNumber(); STATE(SymbolStartPos) = GetInputLinePosition(); // switch according to the character if (IsAlpha(c)) { return GetIdent(0); } UInt symbol; switch (c) { case '.': symbol = S_DOT; c = GET_NEXT_CHAR(); if (c == '.') { symbol = S_DOTDOT; c = GET_NEXT_CHAR(); if (c == '.') { symbol = S_DOTDOTDOT; c = GET_NEXT_CHAR(); } } break; case '!': symbol = S_ILLEGAL; c = GET_NEXT_CHAR(); if (c == '.') { symbol = S_BDOT; GET_NEXT_CHAR(); break; } if (c == '[') { symbol = S_BLBRACK; GET_NEXT_CHAR(); break; } break; case '[': symbol = S_LBRACK; GET_NEXT_CHAR(); break; case ']': symbol = S_RBRACK; GET_NEXT_CHAR(); break; case '{': symbol = S_LBRACE; GET_NEXT_CHAR(); break; case '}': symbol = S_RBRACE; GET_NEXT_CHAR(); break; case '(': symbol = S_LPAREN; GET_NEXT_CHAR(); break; case ')': symbol = S_RPAREN; GET_NEXT_CHAR(); break; case ',': symbol = S_COMMA; GET_NEXT_CHAR(); break; case ':': symbol = S_COLON; c = GET_NEXT_CHAR(); if (c == '=') { symbol = S_ASSIGN; GET_NEXT_CHAR(); break; } break; case ';': symbol = S_SEMICOLON; c = GET_NEXT_CHAR(); if (c == ';') { symbol = S_DUALSEMICOLON; GET_NEXT_CHAR(); break; } break; case '=': symbol = S_EQ; GET_NEXT_CHAR(); break; case '<': symbol = S_LT; c = GET_NEXT_CHAR(); if (c == '=') { symbol = S_LE; GET_NEXT_CHAR(); break; } if (c == '>') { symbol = S_NE; GET_NEXT_CHAR(); break; } break; case '>': symbol = S_GT; c = GET_NEXT_CHAR(); if (c == '=') { symbol = S_GE; GET_NEXT_CHAR(); break; } break; case '+': symbol = S_PLUS; GET_NEXT_CHAR(); break; case '-': symbol = S_MINUS; c = GET_NEXT_CHAR(); if (c == '>') { symbol = S_MAPTO; GET_NEXT_CHAR(); break; } break; case '*': symbol = S_MULT; GET_NEXT_CHAR(); break; case '/': symbol = S_DIV; GET_NEXT_CHAR(); break; case '^': symbol = S_POW; GET_NEXT_CHAR(); break; case '~': symbol = S_TILDE; GET_NEXT_CHAR(); break; case '?': symbol = S_HELP; GetHelp(); break; case '"': symbol = S_STRING; GetString(); break; case '\'': symbol = S_CHAR; GetChar(); break; case '\\': return GetIdent(0); case '_': return GetIdent(0); case '@': return GetIdent(0); case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': return GetNumber(0); case '\377': symbol = S_EOF; *STATE(In) = '\0'; break; default: symbol = S_ILLEGAL; GET_NEXT_CHAR(); break; } return symbol; }
int IsIdStart (int C) /* Return true if the character may start an identifier */ { return IsAlpha (C) || C == '_'; }
Label* CreateAndFillLabelTable ( char** SourceCode, Command* CommandsTable, uint32_t* ProgramSize ) { ASSERT ( SourceCode ); ASSERT ( CommandsTable ); uint32_t NumberLabel = GetNumberLabel ( SourceCode ); Label* LabelTable = ( Label* ) calloc ( NumberLabel + 1, sizeof ( Label ) ); ASSERT ( LabelTable ); //==================== uint32_t i = 0; uint32_t LabelCounter = 0; while ( SourceCode[i] != NULL ) { char* NameLabel = GetLabelName ( SourceCode[i] ); //Mistake in name of label if ( NameLabel == ( char* )( NULL + 1 ) ) { printf( " === Invalid name of label on line %d ===", i + 1 ); errno = EINVAL; return NULL; } //It is right label if ( NameLabel != NULL ) { LabelTable[LabelCounter].NameLabel = NameLabel; LabelTable[LabelCounter].ProgramAddress = *ProgramSize; LabelCounter++; } //It is command or empty string else { uint32_t j = 0; char Command[MaxLengthCommands] = {}; while ( IsSpace ( *( SourceCode[i] + j ) ) == OK ) j++; if ( IsAlpha ( *( SourceCode[i] + j ) ) != OK ) { if ( *( SourceCode[i] + j ) == '\0' || *( SourceCode[i] + j ) == '\r' || *( SourceCode[i] + j ) == '\n' ) { i++; continue; } printf( " === Invalid command on line %d ===", i + 1 ); errno = EINVAL; return NULL; } if ( sscanf ( SourceCode[i] + j, "%[A-Z]", Command ) == 0 ) { printf( " === Invalid command on line %d ===", i + 1 ); errno = EINVAL; return NULL; } else { uint8_t ComSize = 0; if ( GetCommandCodeAndSize ( CommandsTable, Command, &ComSize ) == Error ) { printf( " === This command on line %d not found ===", i + 1 ); errno = EINVAL; return NULL; } *ProgramSize += ComSize; } } i++; } //*ProgramSize += SignatureSize; // Service information return LabelTable; }
static TToken getToken() { oSrcString = sSrcString; int ch = getNextChar(); bool verbStr=false; switch (ch) { case EOFCH: case 0: currTok = tEnd; break; case L',': currTok = tComma; break; case L'+': currTok = tPlus; break; case L'-': currTok = tMinus; break; case L'*': currTok = tMul; break; case L'/': currTok = tDiv; break; case L'(': currTok = tLp; break; case L')': currTok = tRp; break; case L'^': if ((ch = getChar()) == L'^') currTok = tBoolXor; else { putBack(ch); currTok = tBitXor; } break; case L'~': if ((ch = getChar()) != L' ') { putBack(ch); currTok = tBitNot; break; } putBack(ch); //???? currTok = tEnd; break; case L'|': if ((ch = getChar()) == L'|') currTok = tBoolOr; else { putBack(ch); currTok = tBitOr; } break; case L'&': if ((ch = getChar()) == L'&') currTok = tBoolAnd; else { putBack(ch); currTok = tBitAnd; } break; case L'=': if ((ch = getChar()) == L'=') currTok = tEq; else { putBack(ch); currTok = tLet; } break; case L'>': switch ((ch = getChar())) { case L'=': currTok = tGe; break; case L'>': currTok = tBitShr; break; default: putBack(ch); currTok = tGt; break; } break; case L'<': switch (ch = getChar()) { case L'=': currTok = tLe; break; case L'<': currTok = tBitShl; break; default: putBack(ch); currTok = tLt; break; } break; case L'!': if ((ch = getChar()) != L'=') { putBack(ch); currTok = tNot; break; } else currTok = tNe; break; case L'@': ch = getChar(); if (ch != L'"') { putBack(ch); break; } verbStr=true; case L'\"': { TToken __currTok = tNo; currVar = L""; while (((ch = getChar()) != EOFCH)) { if (ch == L'\"') { if (verbStr) { ch = getChar(); if (ch != L'\"') { putBack(ch); break; } } else break; } if (ch == L'\\' && !verbStr) { switch (ch = getChar()) { case L'a' : ch = L'\a'; break; case L'b' : ch = L'\b'; break; case L'f' : ch = L'\f'; break; case L'n' : ch = L'\n'; break; case L'r' : ch = L'\r'; break; case L't' : ch = L'\t'; break; case L'v' : ch = L'\v'; break; case L'\'': ch = L'\''; break; case L'\"': ch = L'\"'; break; case L'\\': ch = L'\\'; break; case L'0': case L'1': case L'2': case L'3': case L'4': case L'5': case L'6': case L'7': // octal: \d \dd \ddd { BYTE n = ch - L'0'; if ((unsigned int)(ch = getChar()) >= L'0' && (unsigned int)ch < L'8') { n = 8 * n + ch - L'0'; if ((unsigned int)(ch = getChar()) >= L'0' && (unsigned int)ch < L'8') n = 8 * n + ch - L'0'; else putBack(ch); } else putBack(ch); ch = n; break; } case L'x': { if (iswxdigit(ch = getChar())) { wchar_t value=hex2ch(ch); for (int ii=0; ii<3; ii++) { if (iswxdigit(ch = getChar())) { value=(value<<4)|hex2ch(ch); } else { putBack(ch); break; } } ch = value; } else { keyMacroParseError(err_Bad_Hex_Control_Char,--sSrcString,pSrcString); __currTok = tEnd; } break; } default: { keyMacroParseError(err_Bad_Control_Char,--sSrcString,pSrcString); __currTok = tEnd; break; } } } if (__currTok != tNo) break; currVar.AppendStr((wchar_t)ch); } if (__currTok == tNo) currTok = tStr; else currTok = __currTok; break; } case L'.': { ch = getChar(); if (iswdigit(ch)) { putBack(ch); ch=L'.'; } else { currTok = tEnd; //??? break; } } case L'0': case L'1': case L'2': case L'3': case L'4': case L'5': case L'6': case L'7': case L'8': case L'9': { static wchar_t buffer[256]; wchar_t *ptrbuffer=buffer; bool isNum = false; bool isHex = false; bool isE = false; bool isPoint = false; int ch2; for (;;) { *ptrbuffer++=(wchar_t)ch; switch (ch) { case L'x': case L'X': if (ptrbuffer == buffer + 2) { ch = getChar(); if (iswxdigit(ch)) { isHex=true; putBack(ch); } else { putBack(ch); isNum=true; break; } } break; case L'.': if (isPoint || isE) { isNum=true; break; } isPoint=true; break; case L'e': case L'E': if (isHex) break; if (isE) { isNum=true; break; } isE=true; ch2 = getChar(); if (ch2 == L'-' || ch2 == L'+') { int ch3=getChar(); if (iswdigit(ch3)) { *ptrbuffer++=(wchar_t)ch2; *ptrbuffer++=(wchar_t)ch3; } else { putBack(ch3); // !iswdigit putBack(ch2); // -+ putBack(ch); // eE } } else if (!iswdigit(ch2)) { putBack(ch2); // !iswdigit putBack(ch); // eE } else putBack(ch); break; case L'a': case L'A': case L'b': case L'B': case L'c': case L'C': case L'd': case L'D': case L'f': case L'F': if (!isHex) { isNum=true; break; } case L'0': case L'1': case L'2': case L'3': case L'4': case L'5': case L'6': case L'7': case L'8': case L'9': //isNum=true; break; default: isNum=true; break; } if (isNum) break; ch = getChar(); } if (ch != EOFCH) putBack(ch); *ptrbuffer++=(wchar_t)0; bool CheckIntNumber=true; if (buffer[0]) { if (!(buffer[1] == L'x' || buffer[1] == L'X')) { for (ptrbuffer=buffer; *ptrbuffer ; ptrbuffer++) { if (*ptrbuffer == L'e' || *ptrbuffer == L'E' || *ptrbuffer == L'.') { CheckIntNumber=false; break; } else if (!iswdigit(*ptrbuffer)) break; } } } else CheckIntNumber=false; if (CheckIntNumber) { currVar = _wcstoi64(buffer,&ptrbuffer,0); currTok = tInt; } else { currVar = wcstod(buffer,&ptrbuffer); currTok = tFloat; } break; } case L'%': ch = getChar(); if ((IsAlphaNum(ch) || ch == L'_') || (ch == L'%' && (IsAlphaNum(*sSrcString) || *sSrcString == L'_'))) { getVarName(ch); putBack(ch); currTok = tVar; } else keyMacroParseError(err_Var_Expected,L""); // BUG nameString break; default: { if (IsAlpha(ch)) // || ch == L'_' ???? { TToken __currTok = tNo; getFarName(ch); if (ch == L' ') { while (ch == L' ') ch = getNextChar(); } if (ch == L'(') //!!!! а пробелы пропустить? ДА! __currTok = tFunc; else { putBack(ch); for (int i = 0 ; i < MKeywordsSize ; i++) if (!StrCmpI(nameString, MKeywords[i].Name)) { FARVar = MKeywords[i].Value; __currTok = tFARVar; break; } if (__currTok == tNo) { if (IsProcessFunc || currTok == tFunc || currTok == tLt) // TODO: уточнить { if (KeyNameMacroToKey(nameString) == -1 && KeyNameToKey(nameString) == -1 && checkMacroConst(nameString)) __currTok = tConst; else { DWORD k=KeyNameToKey(nameString); if (k != (DWORD)-1) { currVar = (__int64)k; __currTok = tInt; //?? } else { keyMacroParseError(err_Var_Expected,oSrcString,pSrcString,nameString); } } } else { if (KeyNameMacroToKey(nameString) == -1) { if (KeyNameToKey(nameString) == -1) { if (checkMacroConst(nameString)) __currTok = tConst; else keyMacroParseError(err_Unrecognized_keyword,nameString); } else { currVar = (__int64)KeyNameToKey(nameString); __currTok = tInt; //?? } } } } } if (__currTok != tNo) currTok=__currTok; } else currTok = tEnd; break; } } return currTok; }
TiXmlNode* TiXmlNode::Identify( const char* p, TiXmlEncoding encoding ) { TiXmlNode* returnNode = 0; p = SkipWhiteSpace( p, encoding ); if( !p || !*p || *p != '<' ) { return 0; } p = SkipWhiteSpace( p, encoding ); if ( !p || !*p ) { return 0; } // What is this thing? // - Elements start with a letter or underscore, but xml is reserved. // - Comments: <!-- // - Decleration: <?xml // - Everthing else is unknown to tinyxml. // const char* xmlHeader = { "<?xml" }; const char* commentHeader = { "<!--" }; const char* dtdHeader = { "<!" }; const char* cdataHeader = { "<![CDATA[" }; if ( StringEqual( p, xmlHeader, true, encoding ) ) { #ifdef DEBUG_PARSER TIXML_LOG( "XML parsing Declaration\n" ); #endif returnNode = new TiXmlDeclaration(); } else if ( StringEqual( p, commentHeader, false, encoding ) ) { #ifdef DEBUG_PARSER TIXML_LOG( "XML parsing Comment\n" ); #endif returnNode = new TiXmlComment(); } else if ( StringEqual( p, cdataHeader, false, encoding ) ) { #ifdef DEBUG_PARSER TIXML_LOG( "XML parsing CDATA\n" ); #endif TiXmlText* text = new TiXmlText( "" ); text->SetCDATA( true ); returnNode = text; } else if ( StringEqual( p, dtdHeader, false, encoding ) ) { #ifdef DEBUG_PARSER TIXML_LOG( "XML parsing Unknown(1)\n" ); #endif returnNode = new TiXmlUnknown(); } else if ( IsAlpha( *(p+1), encoding ) || *(p+1) == '_' ) { #ifdef DEBUG_PARSER TIXML_LOG( "XML parsing Element\n" ); #endif returnNode = new TiXmlElement( "" ); } else { #ifdef DEBUG_PARSER TIXML_LOG( "XML parsing Unknown(2)\n" ); #endif returnNode = new TiXmlUnknown(); } if ( returnNode ) { // Set the parent, so it can report errors returnNode->parent = this; } return returnNode; }
int SSPParser::getNextToken(void *Val) { YYSTYPE *Value = static_cast<YYSTYPE*>(Val); StringRef BufferData = Buf->getBuffer(); const char *Data = BufferData.data(); const char* CurCh = Data+CurPos; while (CurPos < BufferData.size() && (*CurCh == '\t' || *CurCh == ' ' || *CurCh == '\r' || *CurCh == '\n')) { CurPos++; CurCh = Data+CurPos; } if (CurPos >= BufferData.size()) return 0; // EOF if (*CurCh == '+') { CurPos++; return PLUS; } else if (*CurCh == '-') { CurPos++; return MINUS; } else if (*CurCh == '*') { CurPos++; return ASTERISK; } else if (*CurCh == '/') { CurPos++; return SLASH; } else if (*CurCh == '$') { CurPos++; return DOLLAR; } else if (*CurCh == '@') { CurPos++; return AT; } else if (IsAlpha(*CurCh)) { const char *Start = CurCh; size_t Length = 0; do { Length++; CurPos++; CurCh = Data+CurPos; } while (CurPos < BufferData.size() && (IsAlphaOrDigit(*CurCh) || *CurCh == '_')); StringRef *Str = new StringRef(Start, Length); // Check for keywords if (Str->compare("double") == 0) { return DOUBLE; } else if (Str->compare("field") == 0) { return FIELD; } else if (Str->compare("float") == 0) { return FLOAT; } else if (Str->compare("grid") == 0) { return GRID; } else if (Str->compare("in") == 0) { return IN; } else if (Str->compare("inout") == 0) { return INOUT; } else if (Str->compare("is") == 0) { return IS; } else if (Str->compare("let") == 0) { return LET; } else if (Str->compare("out") == 0) { return OUT; } else if (Str->compare("param") == 0) { return PARAM; } else if (Str->compare("program") == 0) { return PROGRAM; } // Not a keyword InternedStrings.push_back(Str); Value->Ident = Str; return IDENT; } else if (IsDigit(*CurCh)) { const char *Start = CurCh; size_t Length = 0; bool IsFloat = false; do { if (*CurCh == '.') IsFloat = true; Length++; CurPos++; CurCh = Data+CurPos; } while (CurPos < BufferData.size() && (IsDigit(*CurCh) || *CurCh == '.')); if (CurPos < BufferData.size() && (*CurCh == 'e' || *CurCh == 'E')) { // Start of an exponent IsFloat = true; CurPos++; CurCh = Data+CurPos; Length++; if (CurPos == BufferData.size() || (!IsDigit(*CurCh) && *CurCh != '-')) { SrcMgr.PrintMessage(SMLoc::getFromPointer(Data+CurPos), SourceMgr::DK_Error, "Missing exponent"); return 0; } if (*CurCh == '-') { Length++; CurPos++; CurCh = Data+CurPos; if (CurPos == BufferData.size() || !IsDigit(*CurCh)) { SrcMgr.PrintMessage(SMLoc::getFromPointer(Data+CurPos), SourceMgr::DK_Error, "Missing exponent"); return 0; } } do { Length++; CurPos++; CurCh = Data+CurPos; } while (CurPos < BufferData.size() && IsDigit(*CurCh)); } StringRef Str = StringRef(Start, Length); if (IsFloat) { APFloat DoubleValue = APFloat(APFloat::IEEEdouble, Str); Value->DoubleConst = DoubleValue.convertToDouble(); return DOUBLECONST; } else { long IntValue = atol(Str.data()); Value->IntConst = IntValue; return INTCONST; } } else if (*CurCh == '=') { CurPos++; return EQUALS; } else if (*CurCh == '(') { CurPos++; return OPENPARENS; } else if (*CurCh == ')') { CurPos++; return CLOSEPARENS; } else if (*CurCh == '[') { CurPos++; return OPENBRACE; } else if (*CurCh == ']') { CurPos++; return CLOSEBRACE; } else if (*CurCh == ',') { CurPos++; return COMMA; } else if (*CurCh == ':') { CurPos++; return COLON; } CurPos++; // If we get here, then we have no idea how to lex this! printError("Unknown symbol"); return 0; }