int main(void) { uint8_t i; uint8_t r; uint8_t seg; uint8_t mi; // message index uint8_t bi; // buffer index uint8_t ltr; uint8_t b; unsigned char buffer[7] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00}; setup(); // test: put first letter of message in buffer mi = 0; ltr = readNextChar(mi); // main event loop while (1) { // load charater into buffer for (bi = 0; bi < 5; bi++) { buffer[bi] = pgm_read_byte(&(font[ltr][bi])); } // display the buffer for (b = 1; b < 30; b++) { // loop through the cathode columns for (i = 7; i > 0; i--) { // set 4051 CBA input address pins PORTD |= (i << 2); // shift 2 to skip PD0 and PD1 seg = buffer[i-1]; for (r = 0; r < 5; r++) { if (seg & (1 << r)) { // toggle anode bit PORTC ^= (1 << r); _delay_ms (MSECSDELAYPOST); PORTC ^= (1 << r); } } // clear 4051 CBA input address pins PORTD &= ~(i << 2); // shift 2 to skip PD0 and PD1 } } // get next letter mi = (mi+1) % MAXLEN; ltr = readNextChar(mi); } return 0; }
void XmlDocument::readQuotedString (String& result) { auto quote = readNextChar(); while (! outOfData) { auto c = readNextChar(); if (c == quote) break; --input; if (c == '&') { readEntity (result); } else { auto start = input; for (;;) { auto character = *input; if (character == quote) { result.appendCharPointer (start, input); ++input; return; } if (character == '&') { result.appendCharPointer (start, input); break; } if (character == 0) { setLastError ("unmatched quotes", false); outOfData = true; break; } ++input; } } } }
void XmlDocument::readQuotedString (String& result) { const juce_wchar quote = readNextChar(); while (! outOfData) { const juce_wchar c = readNextChar(); if (c == quote) break; --input; if (c == '&') { readEntity (result); } else { const String::CharPointerType start (input); size_t numChars = 0; for (;;) { const juce_wchar character = *input; if (character == quote) { result.appendCharPointer (start, numChars); ++input; return; } else if (character == '&') { result.appendCharPointer (start, numChars); break; } else if (character == 0) { outOfData = true; setLastError ("unmatched quotes", false); break; } ++input; ++numChars; } } } }
void LexicalAnalyzer::setUp(char* fileName, StringTable* stringTable){ //Open the filestream fileStream.open(fileName); fsm.associateStringTable(stringTable); //Populate the first character readNextChar(); }
Token LexicalAnalyzer::getNextToken(){ Token rv; fsm.reset(); //Load the next character untill the FSM blocks. while(fsm.transition(this->currentChar) != FSM_BLOCK){ readNextChar(); } rv.type = fsm.getTokenType(); rv.info = -1; //Error out if token is invalid. if(rv.type == TOKEN_INVALID_TOKEN_TYPE){ THROW_ERROR("Bad token type"); } //Handle string or integer values. if(rv.type == TOKEN_STRING || rv.type == TOKEN_IDENTIFIER){ rv.info = fsm.writeString(); } if(rv.type == TOKEN_INT){ rv.info = fsm.getIntValue(); } return rv; }
bool XmlDocument::parseDTD() { if (CharacterFunctions::compareUpTo (input, CharPointer_ASCII ("<!DOCTYPE"), 9) == 0) { input += 9; const String::CharPointerType dtdStart (input); for (int n = 1; n > 0;) { const juce_wchar c = readNextChar(); if (outOfData) return false; if (c == '<') ++n; else if (c == '>') --n; } dtdText = String (dtdStart, input - 1).trim(); } return true; }
static int skipWhite (void) { int c; do c = readNextChar (); while (c == ' ' || c == '\t'); return c; }
void XmlDocument::skipHeader() { const int headerStart = input.indexOf (CharPointer_UTF8 ("<?xml")); if (headerStart >= 0) { const int headerEnd = (input + headerStart).indexOf (CharPointer_UTF8 ("?>")); if (headerEnd < 0) return; #if JUCE_DEBUG const String header (input + headerStart, (size_t) (headerEnd - headerStart)); const String encoding (header.fromFirstOccurrenceOf ("encoding", false, true) .fromFirstOccurrenceOf ("=", false, false) .fromFirstOccurrenceOf ("\"", false, false) .upToFirstOccurrenceOf ("\"", false, false).trim()); /* If you load an XML document with a non-UTF encoding type, it may have been loaded wrongly.. Since all the files are read via the normal juce file streams, they're treated as UTF-8, so by the time it gets to the parser, the encoding will have been lost. Best plan is to stick to utf-8 or if you have specific files to read, use your own code to convert them to a unicode String, and pass that to the XML parser. */ jassert (encoding.isEmpty() || encoding.startsWithIgnoreCase ("utf-")); #endif input += headerEnd + 2; } skipNextWhiteSpace(); const int docTypeIndex = input.indexOf (CharPointer_UTF8 ("<!DOCTYPE")); if (docTypeIndex < 0) return; input += docTypeIndex + 9; const String::CharPointerType docType (input); int n = 1; while (n > 0) { const juce_wchar c = readNextChar(); if (outOfData) return; if (c == '<') ++n; else if (c == '>') --n; } dtdText = String (docType, (size_t) (input.getAddress() - (docType.getAddress() + 1))).trim(); }
/* While ANSI only permits lines of the form: * # line n "filename" * Earlier compilers generated lines of the form * # n filename * GNU C will output lines of the form: * # n "filename" * So we need to be fairly flexible in what we accept. */ static vString *readFileName (void) { vString *const fileName = vStringNew (); boolean quoteDelimited = FALSE; int c = skipWhite (); if (c == '"') { c = readNextChar (); /* skip double-quote */ quoteDelimited = TRUE; } while (c != EOF && c != '\n' && (quoteDelimited ? (c != '"') : (c != ' ' && c != '\t'))) { vStringPut (fileName, c); c = readNextChar (); } if (c == '\n') pushBackChar (c); vStringPut (fileName, '\0'); return fileName; }
static unsigned long readLineNumber (void) { unsigned long lNum = 0; int c = skipWhite (); while (c != EOF && isdigit (c)) { lNum = (lNum * 10) + (c - '0'); c = readNextChar (); } pushBackChar (c); if (c != ' ' && c != '\t') lNum = 0; return lNum; }
XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements) { XmlElement* node = nullptr; skipNextWhiteSpace(); if (outOfData) return nullptr; if (*input == '<') { ++input; String::CharPointerType endOfToken (XmlIdentifierChars::findEndOfToken (input)); if (endOfToken == input) { // no tag name - but allow for a gap after the '<' before giving an error skipNextWhiteSpace(); endOfToken = XmlIdentifierChars::findEndOfToken (input); if (endOfToken == input) { setLastError ("tag name missing", false); return node; } } node = new XmlElement (input, endOfToken); input = endOfToken; LinkedListPointer<XmlElement::XmlAttributeNode>::Appender attributeAppender (node->attributes); // look for attributes for (;;) { skipNextWhiteSpace(); const juce_wchar c = *input; // empty tag.. if (c == '/' && input[1] == '>') { input += 2; break; } // parse the guts of the element.. if (c == '>') { ++input; if (alsoParseSubElements) readChildElements (*node); break; } // get an attribute.. if (XmlIdentifierChars::isIdentifierChar (c)) { String::CharPointerType attNameEnd (XmlIdentifierChars::findEndOfToken (input)); if (attNameEnd != input) { const String::CharPointerType attNameStart (input); input = attNameEnd; skipNextWhiteSpace(); if (readNextChar() == '=') { skipNextWhiteSpace(); const juce_wchar nextChar = *input; if (nextChar == '"' || nextChar == '\'') { XmlElement::XmlAttributeNode* const newAtt = new XmlElement::XmlAttributeNode (attNameStart, attNameEnd); readQuotedString (newAtt->value); attributeAppender.append (newAtt); continue; } } else { setLastError ("expected '=' after attribute '" + String (attNameStart, attNameEnd) + "'", false); return node; } } } else { if (! outOfData) setLastError ("illegal character found in " + node->getTagName() + ": '" + c + "'", false); } break; } } return node; }
XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements) { XmlElement* node = nullptr; skipNextWhiteSpace(); if (outOfData) return nullptr; const int openBracket = input.indexOf ((juce_wchar) '<'); if (openBracket >= 0) { input += openBracket + 1; int tagLen = findNextTokenLength(); if (tagLen == 0) { // no tag name - but allow for a gap after the '<' before giving an error skipNextWhiteSpace(); tagLen = findNextTokenLength(); if (tagLen == 0) { setLastError ("tag name missing", false); return node; } } node = new XmlElement (String (input, (size_t) tagLen)); input += tagLen; LinkedListPointer<XmlElement::XmlAttributeNode>::Appender attributeAppender (node->attributes); // look for attributes for (;;) { skipNextWhiteSpace(); const juce_wchar c = *input; // empty tag.. if (c == '/' && input[1] == '>') { input += 2; break; } // parse the guts of the element.. if (c == '>') { ++input; if (alsoParseSubElements) readChildElements (node); break; } // get an attribute.. if (XmlIdentifierChars::isIdentifierChar (c)) { const int attNameLen = findNextTokenLength(); if (attNameLen > 0) { const String::CharPointerType attNameStart (input); input += attNameLen; skipNextWhiteSpace(); if (readNextChar() == '=') { skipNextWhiteSpace(); const juce_wchar nextChar = *input; if (nextChar == '"' || nextChar == '\'') { XmlElement::XmlAttributeNode* const newAtt = new XmlElement::XmlAttributeNode (String (attNameStart, (size_t) attNameLen), String::empty); readQuotedString (newAtt->value); attributeAppender.append (newAtt); continue; } } } } else { if (! outOfData) setLastError ("illegal character found in " + node->getTagName() + ": '" + c + "'", false); } break; } } return node; }
Token* Scanner::produce() { if (!_nextChar) { return new Token(COMPLETE, NULL); } switch (_nextChar) { case ' ': readNextChar(); return new Token(SPACE, NULL); break; case '=': readNextChar(); return new Token(EQ, NULL); break; case '<': readNextChar(); return new Token(LT, NULL); break; case '/': readNextChar(); return new Token(SL, NULL); break; case '>': readNextChar(); return new Token(GT, NULL); break; case '"': { std::string *sb = new string(); readNextChar(); while (_nextChar != '"') { sb->push_back(_nextChar); readNextChar(); } readNextChar(); return new Token(STRING_LITERAL, sb->c_str()); } break; // default: // readNextChar(); // return new Token(SPACE, NULL); // break; } std::string *sb = new string(); if (isChar(_nextChar)) { while (isChar(_nextChar)) { sb->push_back(_nextChar); readNextChar(); } if (keywords[sb->c_str()]) { return new Token((Type) keywords[sb->c_str()], NULL); } else { return new Token(UNKNOW, NULL); } } else { while (_nextChar && (_nextChar) != '<') { sb->push_back(_nextChar); readNextChar(); } // ConvertUtf8ToGBK(sb->c_str()); return new Token(TEXT, sb->c_str()); } }