コード例 #1
0
ファイル: parser.cpp プロジェクト: forsaken1/compiler
void Parser::Parse() {
	Next();
	if(simple)
		top = Statement();
	else
		top = Program();
}
コード例 #2
0
/* <If> ::= if ( <Condition> ) <Statement> <If Prime> */
bool SyntaxAnalyzer::If()
{
    if(rrr == k_if)
    {
        NextRecord();
        if(rrr == s_openbracketround)
        {
            NextRecord();
            Condition();
            if(rrr == s_closebracketround)
            {
                NextRecord();
				Statement();
                IfPrime();
                logger.Log("<If> ::= if ( <Condition> ) <Statement> <If Prime>");
                return true;
            }
            else
            {
                insert(s_closebracketround);
                return true;
            }
        }
        else
        {
            insert(s_openbracketround);
            return true;
        }
    }
    else
    {
        // no error
        return false;
    }
}
コード例 #3
0
/* <While> ::= while ( <Condition> ) <Statement> */
bool SyntaxAnalyzer::While()
{  
    if(rrr == k_while)
    {
        NextRecord();
        if(rrr == s_openbracketround)
        {
            NextRecord();
            Condition();
            if(rrr == s_closebracketround)
            {
				NextRecord();
                Statement();
                // log
				logger.Log("While> ::= while ( <Condition> ) <Statement>");
                return true;
            }
            else
            {
                insert(s_closebracketround);
                return true;
            }
        }
        else
        {
            insert(s_openbracketround);
            return true;
        }
    }
    else
    {
        // no error
        return false;
    } 
}
コード例 #4
0
ファイル: stmt.c プロジェクト: Aliandrana/cc65
static void WhileStatement (void)
/* Handle the 'while' statement */
{
    int         PendingToken;
    CodeMark    CondCodeStart;  /* Start of condition evaluation code */
    CodeMark    CondCodeEnd;    /* End of condition evaluation code */
    CodeMark    Here;           /* "Here" location of code */

    /* Get the loop control labels */
    unsigned LoopLabel  = GetLocalLabel ();
    unsigned BreakLabel = GetLocalLabel ();
    unsigned CondLabel  = GetLocalLabel ();

    /* Skip the while token */
    NextToken ();

    /* Add the loop to the loop stack. In case of a while loop, the condition
    ** label is used for continue statements.
    */
    AddLoop (BreakLabel, CondLabel);

    /* We will move the code that evaluates the while condition to the end of
    ** the loop, so generate a jump here.
    */
    g_jump (CondLabel);

    /* Remember the current position */
    GetCodePos (&CondCodeStart);

    /* Emit the code position label */
    g_defcodelabel (CondLabel);

    /* Test the loop condition */
    TestInParens (LoopLabel, 1);

    /* Remember the end of the condition evaluation code */
    GetCodePos (&CondCodeEnd);

    /* Define the head label */
    g_defcodelabel (LoopLabel);

    /* Loop body */
    Statement (&PendingToken);

    /* Move the test code here */
    GetCodePos (&Here);
    MoveCode (&CondCodeStart, &CondCodeEnd, &Here);

    /* Exit label */
    g_defcodelabel (BreakLabel);

    /* Eat remaining tokens that were delayed because of line info
    ** correctness
    */
    SkipPending (PendingToken);

    /* Remove the loop from the loop stack */
    DelLoop ();
}
コード例 #5
0
ファイル: parser.cpp プロジェクト: kkthx/bi-pjp-sfe
Statm *ElsePart()
{
   if (Symb.type == kwELSE) {
      Symb = readLexem();
      return Statement();
   }
   return 0;
}
コード例 #6
0
Database::Statement Database::prepare(const String &request)
{
	sqlite3_stmt *stmt = NULL;
	if(sqlite3_prepare_v2(mDb, request.c_str(), -1, &stmt, NULL) != SQLITE_OK)
		 throw DatabaseException(mDb, String("Unable to prepare request \"")+request+"\"");

	return Statement(mDb, stmt);
}
コード例 #7
0
ファイル: TKSwitch.cpp プロジェクト: Y-Less/yavascript
Token &
	TKSwitch::
	STD(SyntaxHandler & sh)
{
	Conditional(sh);
	Statement(sh);
	return *this;
}
コード例 #8
0
ファイル: parser.cpp プロジェクト: kkthx/bi-pjp-sfe
void CompoundStatementPrime()
{
   if (Symb.type == SEMICOLON) {
      Symb = readLexem();
      Statement();
      CompoundStatementPrime();
   }
}
コード例 #9
0
ファイル: parser.cpp プロジェクト: kkthx/bi-pjp-sfe
StatmList *CompoundStatement()
{
   Compare(kwBEGIN, __LINE__);
   Statm *p = Statement();
   StatmList *su = new StatmList(p, CompoundStatementPrimed());
   Compare(kwEND, __LINE__);
   return su;
}
コード例 #10
0
ファイル: User2.cpp プロジェクト: heftyfunseeker/cs375
//=========================================================
bool Parser::Scope () {
    PrintRule rule("Scope");
    if (Accept(TokenType::OpenCurley) == false) {
        return false;
    }
    while (Statement());

    return rule.Accept(Expect(TokenType::CloseCurley));
}
コード例 #11
0
Soprano::Statement Soprano::Util::SimpleStatementIteratorBackend::current() const
{
    if ( m_iterator != m_statements.constEnd() ) {
        return *m_iterator;
    }
    else {
        return Statement();
    }
}
コード例 #12
0
ファイル: parser.cpp プロジェクト: kkthx/bi-pjp-sfe
StatmList *CompoundStatementPrimed()
{
   if (Symb.type == SEMICOLON) {
      Symb = readLexem();
      Statm *p = Statement();
      return new StatmList(p, CompoundStatementPrimed());
   }
   return 0;
}
コード例 #13
0
/* <If Prime> ::= endif | else <Statement> endif */
void SyntaxAnalyzer::IfPrime()
{
    if(rrr == k_endif)
    {
        NextRecord();
        logger.Log("<If Prime> ::= endif>");
    }
    else if(rrr == k_else)
    {
        NextRecord();
        Statement();
        if(rrr == k_endif)
        {
            NextRecord();
			logger.Log("<If Prime> ::= endif | else <Statement> endif");
        }
        else
        {
            insert(k_endif);
        }
    }
    else
    {
        // assume they forgot an else
        insert(k_else);
        if(Statement())
        {
            if(rrr == k_endif)
            {
                NextRecord();
			    logger.Log("<If Prime> ::= endif | else <Statement> endif");
            }
            else
            {
                insert(k_endif);
            }
        }
        else
        {
            insert(k_endif);
        }
    }
}
コード例 #14
0
Statement Statement::combine( Statement &rhs ) {
	if ( !isEmpty() ) {
		if ( !rhs.isEmpty() ) {
			return Statement(  SS( *this, rhs )  );
		} else {
			return *this;
		}
	}
	return rhs;
}
コード例 #15
0
ファイル: nrlmodel.cpp プロジェクト: KDE/soprano
Soprano::Error::ErrorCode Soprano::NRLModel::removeGraph( const QUrl& graph )
{
    QList<Node> metadataGraphs = FilterModel::executeQuery( QString("select ?mg where { ?mg %1 %2 . }")
                                                            .arg(Node::resourceToN3(Soprano::Vocabulary::NRL::coreGraphMetadataFor()) )
                                                            .arg(Node::resourceToN3(graph)),
                                                            Query::QueryLanguageSparql ).iterateBindings(0).allNodes();
    foreach ( const Node& mg, metadataGraphs ) {
        // we can only use removeAllStatements(Statement) here since all other variants will come back to
        // our version below which in turn calls us again
        FilterModel::removeAllStatements( Statement( Node(), Node(), Node(), mg ) );
    }
コード例 #16
0
void Parser:: Statements_1() {
   if(lookahead == T_SEMICOLON) {
   		match(T_SEMICOLON);
   		Statement();
   		Statements_1();
   	}
   	else {
   		//do nothing
   	}
   		

}
コード例 #17
0
ファイル: parser.cpp プロジェクト: kkthx/bi-pjp-sfe
void ElsePart(int adrIFJ)
{
   if (Symb.type == kwELSE) {
      Symb = readLexem();
      int adrJU = Gener(JU);
      PutIC(adrIFJ);
      Statement();
      PutIC(adrJU);
   } else {
      PutIC(adrIFJ);
   }
}
コード例 #18
0
ファイル: parser.cpp プロジェクト: forsaken1/compiler
Node* Parser::StatementList() {
	Node *first = Statement();

	if(first != NULL) {
		Node *second = StatementList();
		if(second == NULL)
			return first;

		return new NodeStmt("(stmt)", first, second);
	}
	return NULL;
}
コード例 #19
0
/*
============
Term
============
*/
def_t *Compiler::Term( void )
{
	def_t	   *e;
	int      op;
	etype_t	t;
	
	if ( lex.Check( "!" ) )
	{
		e = Expression( NOT_PRIORITY );
		t = e->type->type;
		switch( t )
		{
		case ev_float :
			op = OP_NOT_F;
            break;
			
		case ev_string :
            op = OP_NOT_S;
            break;
			
		case ev_entity :
			op = OP_NOT_ENT;
            break;
			
		case ev_vector :
            op = OP_NOT_V;
            break;
			
		case ev_function :
            op = OP_NOT_FNC;
            break;
			
		default :
			lex.ParseError( "type mismatch for !" );
			
            // shut up compiler
            op = OP_NOT_FNC;
            break;
		}
		
		return Statement( &pr_opcodes[ op ], e, 0 );
	}
	
	if ( lex.Check( "(" ) )
	{
		e = Expression( TOP_PRIORITY );
		lex.Expect( ")" );
		
		return e;
	}
	
	return ParseValue();
}
コード例 #20
0
/* <Statement List> ::= <Statement> <Statement List Prime> */
bool SyntaxAnalyzer::StatementList()
{
	if(Statement())
    {
	    StatementListPrime();
        logger.Log("<Statement List> ::= <Statement> <Statement List Prime>");
        return true;
    }
    else
    {
        return false;
    }
}
コード例 #21
0
statementBlock* sintactico::Block()
{
    if(CurrentToken->tipo == LLAVE_I)
    {
        list<var_decl*> *var_declarations = new list<var_decl*>();
        list<statement*> *statements = new list<statement*>();
        CurrentToken = Lexer->NexToken();
        while(CurrentToken->tipo == KWBOOL || CurrentToken->tipo == KWINT)
        {
            statementDeclaration::Type type;

            if(CurrentToken->tipo == KWBOOL){
                type = statementDeclaration::BOOL;
            }else{
                type = statementDeclaration::INT;
            }
            var_decl* varDecl = VarDecl();
            varDecl->setType(type);

            var_declarations->push_back(varDecl);
            if(Fallo)
                return NULL;

        }
        while(CurrentToken->tipo == IDENTIFICADOR || CurrentToken->tipo == KWIF || CurrentToken->tipo == KWWHILE
              ||CurrentToken->tipo == KWFOR || CurrentToken->tipo == KWRETURN || CurrentToken->tipo == KWBREAK
              ||CurrentToken->tipo == KWBREAK || CurrentToken->tipo == KWCONTINUE || CurrentToken->tipo == KWPRINT
              ||CurrentToken->tipo == KWREAD || CurrentToken->tipo == LLAVE_I)
        {
            statements->push_back(Statement());//aqui hay problemas
            if(Fallo)
                return NULL;
        }

        if(CurrentToken->tipo != LLAVE_D)
        {
            Fallo = true;
            MensajeError("Se esperaba '}'",Lexer->linea);
            return NULL;
        }
        CurrentToken = Lexer->NexToken();
        return new statementBlock(var_declarations, statements,Lexer->linea);
    }
    else
    {
        Fallo = true;
        MensajeError("Se esperaba '}'",Lexer->linea);
        return NULL;
    }

}
コード例 #22
0
ファイル: parser.cpp プロジェクト: kkthx/bi-pjp-sfe
Statm *Statement()
{
   switch (Symb.type) {
   case IDENT: {
      Var *var = new Var(varAddr(Symb.ident),false);
      Symb = readLexem();
      Compare(ASSIGN, __LINE__);
      return new Assign(var, Expression());
   }
   case kwWRITE:
      Symb = readLexem();
      return new Write(Expression());
   case kwREAD:
      Symb = readLexem();
      char id[MAX_IDENT_LEN];
      Compare_IDENT(id, __LINE__);
      return new Read(new Var(varAddr(id), false));
   case kwIF: {
      Symb = readLexem();
      Expr *cond = Condition();
      Compare(kwTHEN, __LINE__);
      Statm *prikaz = Statement();
      return new If(cond, prikaz, ElsePart());
   }
   case kwWHILE: {
      Expr *cond;
      Symb = readLexem();
      cond = Condition();
      Compare(kwDO, __LINE__);
      return new While(cond, Statement());
   }
   case kwBEGIN:
      return CompoundStatement();
   default:
      return new Empty;
   }
}
コード例 #23
0
TreeNode* Parser::Block()
{
	TreeNode* block = new TreeNode(currentToken, blockNode, "block");

	while (currentToken.type == tokEOL) getToken(); // skip newlines
	matchToken(tokBegin);
	while (currentToken.type == tokEOL) getToken(); // skip newlines
	while ( (currentToken.type != tokEnd) && (currentToken.type != tokEOF) )
	{
		block->appendChild( Statement() );
		while (currentToken.type == tokEOL) getToken(); // blocks can have newlines between their statements
	}
	matchToken(tokEnd);
	return block;
}
コード例 #24
0
ファイル: DB.cpp プロジェクト: GarysRefererence2014/SoftHSMv2
DB::Statement DB::Connection::prepare(const std::string &format, ...){
	// pstatement will hold a dynamically allocated string that needs to be deleted.
	char *pstatement = NULL;

	// short form
	char statement[128];
	va_list args;
	va_start(args, format);
	int cneeded = vsnprintf(statement,sizeof(statement),format.c_str(),args);
	va_end(args);
	if (cneeded<0) {
		DB::logError("Connection::prepare: vsnprintf encoding error");
		return Statement();
	}
	if (((size_t)cneeded)>=sizeof(statement)) {
		// long form
		pstatement = new char[cneeded+1];
		if (!pstatement) {
			DB::logError("Connection::prepare: out of memory");
			return Statement();
		}
		va_start(args, format);
		bool ok = vsnprintf(pstatement,cneeded+1,format.c_str(),args)==cneeded;
		va_end(args);
		if (!ok) {
			DB::logError("Connection::prepare: vsnprintf error");
			delete[] pstatement;
			return  Statement();
		}
	}

	sqlite3_stmt *stmt = NULL;
	int rv = sqlite3_prepare_v2(_db,
								pstatement ? pstatement : statement,
								cneeded+1,
								&stmt,
								NULL);

	if (pstatement)
		delete[] pstatement;

	if (rv != SQLITE_OK) {
		reportErrorDB(_db);
		if (stmt)
			sqlite3_finalize(stmt);
		return Statement();
	}

	if (!stmt) {
		DB::logError("Connection::prepare: expected sqlite3_prepare_v2 to return a compiled "
					"statement, got NULL, out of memory ?");
		return Statement();
	}

	return Statement(stmt);
}
コード例 #25
0
TreeNode* Parser::ForEach()
{
	TreeNode* fNode = new TreeNode(currentToken, forEachNode);
	preservedToken = currentToken;
	matchToken(tokForEach);

	fNode->appendChild( Expression() );
	matchToken(tokIn);
	fNode->appendChild( Expression() );

	if (currentToken.type == tokBegin) fNode->appendChild( Block() ); // for followed by a block
	else fNode->appendChild( Statement() ); // while followed by single statement

	return fNode;
}
コード例 #26
0
ファイル: Writer.cpp プロジェクト: xhy20070406/PDAL
void Writer::TurnOn_SDO_PC_Trigger(std::string trigger_name)
{

    if (!trigger_name.size()) return;

    std::ostringstream oss;

    std::string base_table_name = boost::to_upper_copy(getOptions().getValueOrThrow<std::string>("base_table_name"));

    oss << "ALTER TRIGGER " << trigger_name << " ENABLE ";

    Statement statement = Statement(m_connection->CreateStatement(oss.str().c_str()));
    statement->Execute();


}
コード例 #27
0
ファイル: unparse.cpp プロジェクト: prog012/jikes
void AstBlock::Unparse(Ostream& os, LexStream* lex_stream)
{
    if (debug_unparse)
        os << "/*AstBlock:#" << id << "*/"
           << "/*no_braces:" << no_braces << "*/";
    if (label_opt)
        os << lex_stream -> NameString(label_opt) << ": ";
    if (! no_braces)
        os << '{' << endl;
    for (unsigned i = 0; i < NumStatements(); i++)
        Statement(i) -> Unparse(os, lex_stream);
    if (! no_braces)
        os << '}' << endl;
    if (debug_unparse)
        os << "/*:AstBlock#" << id << "*/";
}
コード例 #28
0
ファイル: pass1.cpp プロジェクト: huffman/CRUDASM7
void Pass1::accept_asgn(
	std::string asgn_nm, ParseNode *asgn_rhs, ParseNode *simple, std::string insn_name, Insn &insn,
	char asz, char osz
)
{
	/// fixme, do this!
	// 1. Get size of asgn_nm (destination of assignment).
	//    Actually, we can just look up asgn_nm in the symbol table.
	// 2. asgn_rhs is an 'rhs' node.
	//    If the rhs node is a NUM token then we have to give it a size that matches the destination
	//    size.
	// 3. Evaluation of 'rhs'.
	//    a. [?]
	
	std::map<std::string, Symbol *>::iterator symiter = symtab2.find(asgn_nm);
	if(symiter == symtab2.end())
	{
		throw ParseError("Destination of assignment not found in symbol table: " + asgn_nm,
			simple->lineNum,
			simple->fileNum,
			__LINE__
		);
	}
	Symbol &destsym = *symiter->second;
	Size &destsize = destsym.size;
	
	insn.stmts.push_back(Statement(SO_ASGN));
	Statement &stmt = insn.stmts.back();
	stmt.osz = osz;
	stmt.asz = asz;
	stmt.dest = &destsym;
	assert(stmt.dest->type == ST_LOCAL || stmt.dest->type == ST_EXTERN || stmt.dest->type == ST_ARGNAME);
	stmt.src.push_back(Rhs());
	Rhs &rhsT = stmt.src.back();
	
	accept_rhs(rhsT, asgn_rhs, insn_name, insn, destsize);
	
	if(rhsT.size.base != destsize.base || rhsT.size.scalar != destsize.scalar)
	{
///std::cout << rhsT.size.base << " " << rhsT.size.scalar << " " << destsize.base << " " << destsize.scalar << std::endl;
		throw ParseError("Size mismatch for assignment to " + asgn_nm,
			simple->lineNum,
			simple->fileNum,
			__LINE__
		);
	}
}
コード例 #29
0
bool syntaxparser::StatementList(){
	bool bStatementList = false;
	if (displayFlag){
		cout<<"<Statement List> ::= <Statement> <Statement List>"<<endl;
		printproduction("<Statement List> ::= <Statement> <Statement List>");
	}
	
	if(Statement()){
		bStatementList = true;
	}
	else
		error("Missing Statement");
		if (token == "keyword" || token == "identifier"){
			bStatementList = true;
			StatementList();
		}
	return bStatementList;
}
コード例 #30
0
shared_ptr<IDbStatement> Connection::_prepare(const String &sql)
{
	//RealtimeStatsScopeTimer RSS(_S("Debug"), _S("Sqlite - Connection::prepare"));
	//OS_LOG_WARNING(sql);

#ifdef OS_ENABLE_DATABASE_ANALYZE
	RealtimeStatsScopeTimer RSS(_S("Debug"), _S("Sqlite - ") + preAnalyze(sql));
#endif

	shared_ptr<Statement> statement(OS_NEW Statement(m_cs));
	statement->prepare(m_connection, sql);

#ifdef OS_ENABLE_DATABASE_ANALYZE
	postAnalyze(sql);
#endif

	return statement;
}