コード例 #1
0
ファイル: Parser.cpp プロジェクト: resistor/rsl-llvm
void Parser::parseBlockBody() {
  Token t = lex.peek();
  if (t.type == Token::LBRACE) {
    lex.consume(Token::LBRACE);
    parseStatements();
    lex.consume(Token::RBRACE);
  } else {
    switch (t.type) {
      case Token::FLOAT:
      case Token::STRING:
      case Token::COLOR:
      case Token::POINT:
      case Token::VECTOR:
      case Token::NORMAL:
      case Token::MATRIX:
      case Token::UNIFORM:
      case Token::VARYING:
        parseVariableDecl();
        break;
      case Token::IDENTIFIER:
        if (lex.peek(2).type == Token::LPAREN)
          parseCallStmt();
        else
          parseAssignmentStmt();
        break;
      case Token::SEMI:
        lex.consume(Token::SEMI);
        break;
      case Token::IF:
        parseIfStmt();
        break;
      case Token::FOR:
        parseForLoop();
        break;
      case Token::WHILE:
        parseWhileLoop();
        break;
      case Token::SOLAR:
        parseSolarLoop();
        break;
      case Token::ILLUMINATE:
        parseIlluminateLoop();
        break;
      case Token::ILLUMINANCE:
        parseIlluminanceLoop();
        break;
      case Token::BREAK:
        parseBreakStmt();
        break;
      case Token::CONTINUE:
        parseContinueStmt();
        break;
      case Token::RETURN:
        parseReturnStmt();
        break;
      default:
        assert(0 && "Expected a statement!");
    }
  }
}
コード例 #2
0
void QuickClassParser::parse( const QString &code )
{
    formCode = code;
    QString expr;
    globalClass.name = gname;
    globalClass.type = QuickClass::Global;
    currClass = &globalClass;
    static int functionLength = strlen( "function" );
    static int constructorLength = strlen( "constructor" );

    for ( pos = 0; pos < (int)formCode.length(); ++pos ) {
	if ( legalChars.find( formCode[ pos ] ) == -1 )
	    expr = "";
	else
	    expr += formCode[ pos ];
	if ( expr == QString::fromLatin1("var")
             || expr == QString::fromLatin1("const")
             || expr == QString::fromLatin1("static") ) {
	    int i = pos + 1;
	    while ( formCode[ i ] == ' ' || formCode[ i ] == '\t' )
		++i;
	    if ( formCode.mid( i, 8 ) != QString::fromLatin1("function") ) {
		++pos;
		parseVariableDecl( expr );
	    }
	    expr = "";
	    continue;
	} else if ( expr == QString::fromLatin1("private")
                    || expr == QString::fromLatin1("protected")
                    || expr == QString::fromLatin1("public") ) {
	    lastAccess = expr;
	    expr = QString::fromLatin1("");
	    continue;
	} else if ( expr == QString::fromLatin1("function")
                    || expr == QString::fromLatin1("constructor") ) {
	    ++pos;
	    parseFunction( expr == QString::fromLatin1("function")
                           ? functionLength
                           : constructorLength );
	    expr = "";
	    continue;
	} else if ( expr == QString::fromLatin1("connect") ) {
	    ++pos;
	    parseConnections();
	    expr = "";
	    continue;
	} else if ( expr == QString::fromLatin1("//") ) {
	    pos--;
	    parseCppComment();
	    expr = "";
	    continue;
	} else if ( expr == QString::fromLatin1("/*") ) {
	    pos--;
	    parseCComment();
	    expr = "";
	    continue;
	} else if ( expr == QString::fromLatin1("class") ) {
	    if ( currClass != &globalClass )
		clsses.append( *currClass );
	    currClass = new QuickClass;
	    currClass->type = QuickClass::Class;
	    ++pos;
	    parseClassStart();
	    expr = "";
	} else if (  formCode[ pos ] == '}' ) {
	    if ( currClass != &globalClass )
		clsses.append( *currClass );
	    currClass = &globalClass;
	}
    }
    if ( currClass != &globalClass )
	clsses.append( *currClass );
    clsses.append( globalClass );
}