Example #1
0
	List<Token*> tokenize(char* str) {
		
		string* temp = new string();
		string* code = new string(str);
		List<Token*> result;
		Symbol prev = oddsym;
		
		// Add the script start token.
		result.add(new Token(scriptstartsym, (char*)"\0"));
		
		// Parse the code.
		for ( int i = 0; i < code->size() ; i++ ) {
			// Get the character.
			char c = code->getAt(i);
			Symbol s = convert(prev, new string(c));
			
			// Check for some kind of known symbol.
			if (isFinished(temp, c, s) || i == code->size() - 1) {		
			
				// Skip empty strings.
				if ( temp->size() > 0 ) {
					// Otherwise, convert the string into a symbol and add it.
					prev = convert(prev, temp);
					Token* token = new Token(prev, temp->toString());
					if (!processSymbol(token, &result, code, &i)) {
						prev = token->sym;
						result.add(token);
					}
				}
				
				// Clear stuff out.
				temp->clear();
				
				// If the character is not whitespace and it's not known
				// append it. Otherwise, if it's known, add to result.
				if ( c != ' ' && (s == ident || s == member || s == number) ) {
					temp->append(c);			
				} else if ( s != ident && s != member && s != number) {
					prev = s;
					Token* token = new Token();
					token->sym = prev; token->val = (new string(c))->toString();
					if (!processSymbol(token, &result, code, &i)) {
						prev = token->sym;
						result.add(token);
					}
				}
			} else {
				temp->append(c);
			}
		}
		
		// Add the script terminate token.
		result.add(new Token(scriptendsym, (char*)"\0"));
		return result;
	}
Example #2
0
bool LRParser::parse(std::string input) {
	input_ = input;
	counter_ = 0;

	// Push state 1
	stack_.push("1");

	while (input_.length()+1 != counter_) {
		// As long as not all of the input has been consumed.
		// Read the symbol
		std::pair<EAction, std::string> theAction = processSymbol();
		// Perform the action
		bool accept = performAction(theAction);

		// If we ended up in a blank entry or another error our input is invalid.
		if (!accept) {
			return false;
		}
		// If we had the accept action and we have consumed our whole input: our input is valid.
		else if (stack_.empty() && accept && (counter_ == input_.length())) {
			//std::cout << *this << std::endl;
			return true;
		}
	}
	// Our input has been consumed and we do not have a startsymbol: our input is invalid.
	return false;
}
Example #3
0
void PropertyBrowser::processObject(IScaObject *object)
{
    QtProperty *property;

    property = m_stringManager->addProperty(PROPERTY_TYPE);
    m_stringManager->setReadOnly(property, true);
    m_stringManager->setValue(property, object->getTypeName());
    addProperty(property, PROPERTY_TYPE);

    if (object->getType() != IScaObject::LINK)
    {
        property = m_stringManager->addProperty(PROPERTY_FILEPATH);
        m_stringManager->setValue(property, object->getFile().absoluteFilePath());
        addProperty(property, PROPERTY_FILEPATH);
    }

    property = m_stringManager->addProperty(PROPERTY_ANNOTATION);
    m_stringManager->setValue(property, object->getAnnotation());
    addProperty(property, PROPERTY_ANNOTATION);

    switch (object->getType())
    {
    case IScaObject::BINARYBLOCK:
        processBinaryBlock(static_cast<IScaObjectBinaryBlock *>(object));
        break;
    case IScaObject::IDENTIFIER:
        processIdentifier(static_cast<IScaObjectIdentifier *>(object));
        break;
    case IScaObject::TEXTBLOCK:
        processTextBlock(static_cast<IScaObjectTextBlock *>(object));
        break;
    case IScaObject::SYMBOL:
        processSymbol(static_cast<IScaObjectSymbol *>(object));
        break;
    case IScaObject::LINE:
        processLine(static_cast<IScaObjectLine *>(object));
        break;
    case IScaObject::LINK:
        processLink(static_cast<Link *>(object));
        break;
    default:
        qDebug() << "[PropertyManager]: unknown type while processing, " << object->getType();
        break;
    }
}