예제 #1
0
파일: Parser.cpp 프로젝트: DNPA/OcfaArch
std::list<SimpleExpression> Parser::simple_expression_list(){
	std::list<SimpleExpression> se;
	if (lexer->getToken() == TOK_AND){
		match(TOK_AND, "expression_list_aux");
		se.push_back(simple_expression());
		std::list<SimpleExpression> exprlist (simple_expression_list());
		
		/* copy exprlist into se as merge requires operator< or something */
		for (std::list<SimpleExpression>::iterator i = exprlist.begin();
				i != exprlist.end();
				++i)
			se.push_back(*i);
	}
	return se;
}
예제 #2
0
/*fact parser:*/
void
fact (void)
{
  switch (lookahead)
    {
    case INTCTE://constante inteira
      match (INTCTE);
      break;
    case '('://parênteses
      match ('(');
      expr ();
      match (')');
      break;
    case ID://identificador
      {
            
      /*geração de código de máquina*/
      {printf("\tmov %s, %%eax\n", lexeme);}
      
	if (symtab_lookup (lexeme) == -1)
	  {
	    deupau ();
	  }
      }
      match (ID);
      if (lookahead == '(')
	{
	  match ('(');
	  exprlist ();
	  match (')');
	}
      else
	{
	  while (lookahead == '[')
	    {
	      idxsynt ();
	    }
	}
      break;
    default:
      ;
    }
}
예제 #3
0
void SqlCompiler::genInsertValues(const SyntaxNode *n,              // n == insert_stmt
                                  StatementTable &table) {
  NodeList    columnlist((n->child(1)->childCount() == 0) ? NULL : n->child(1)->child(0));
  SyntaxNode *insertwhat = n->child(2); // == VALUES
  NodeList    exprlist(insertwhat->child(0));
  Array<InsertColumnExpression> icemap;

  if(columnlist.size() == 0) { // no columnnames specified. use all columns of tabledefinition
    if(exprlist.size() != table.getColumnCount()) {
      syntaxError(insertwhat,SQL_INVALID_EXPRLIST,_T("Invalid number of expressions specified"));
      return;
    }
    for(UINT i = 0; i < table.getColumnCount(); i++)
      icemap.add(InsertColumnExpression(table,i,exprlist[i]));
  }
  else { // columnnames specified
    if(columnlist.size() != exprlist.size()) {
      syntaxError(insertwhat,SQL_INVALID_EXPRLIST,_T("Invalid number of expressions specified"));
      return;
    }
    for(UINT i = 0; i < columnlist.size(); i++) {
      const TCHAR *name = columnlist[i]->name();
      int colindex = table.findColumnIndex(name);
      if(colindex < 0)
        syntaxError(columnlist[i],SQL_INVALID_COLUMNNAME,_T("Invalid columnname:<%s>"),name);
      else {
        bool found = false;
        for(UINT j = 0; j < icemap.size(); j++) { // check not already spec
          if(icemap[j].m_colIndex == colindex) {
            syntaxError(columnlist[i],SQL_COLUMN_ALREADY_DEFINED,_T("Column <%s> already specified"),name);
            found = true;
            break;
          }
        }
        if(!found)
          icemap.add(InsertColumnExpression(table,colindex,exprlist[i]));
      }
    }
    if(columnlist.size() > table.getColumnCount())
      syntaxError(insertwhat,SQL_TOO_MANY_COLUMNS,_T("Too many columns specified"));
    else {
      if(columnlist.size() < table.getColumnCount()) // check, that unspecified columns have nulls-allowed or defaultvalue
        for(UINT i = 0; i < table.getColumnCount(); i++) {
          bool found = false;
          for(UINT j = 0; j < icemap.size(); j++) {
            if(icemap[j].m_colIndex == i) {
              found = true;
              break;
            }
          }
          if(!found) { // unspecified column
            SyntaxNode *defaultvalue = fetchDefaultValueNode(table.getColumn(i));
            if(defaultvalue == NULL)
              syntaxError(n->child(0),SQL_NODEFAULT_OR_NULLALLOWED,_T("Column <%s> has no default-value or null-allowed"),table.getColumn(i).m_name.cstr());
            else
              icemap.add(InsertColumnExpression(table,i,defaultvalue));
          }
        }
    }
  }
  if(ok()) {
    // icemap.size == tableDef.colcount. i.e all columns has an expression
    int hostvarcounter = 0;
    for(UINT i = 0; i < icemap.size(); i++) {
      findHostVarIndex(icemap[i].m_expr,hostvarcounter);
    }
  }
  if(ok()) {
    for(UINT i = 0; i < icemap.size(); i++)
      checkExpressionType(icemap[i]);
  }

  if(ok()) {
    m_code.appendIns2(CODETUPINIT,0,table.getColumnCount());
    for(UINT i = 0; i < icemap.size(); i++) {
      bool dummy;
      genExpression(reduceExpression(icemap[i].m_expr,dummy));
      m_code.appendIns2(CODEPOPTUP,0,icemap[i].m_colIndex);
    }
    m_code.appendIns0(CODETRBEGIN);
    m_code.appendIns1(CODEPUSHCONST,m_code.appendConst(table.getSequenceNo()));
    m_code.appendIns1(CODETUPINSERT,0);
    m_code.appendIns0(CODETRCOMMIT);
  }
#ifdef TRACECOMP
  m_code.dump();
#endif

//  if(ok()) {
//    FILE *dmp = FOPEN(_T("fisk"),_T("w"));
//    for(int i = 0; i < icemap.size(); i++)
//      icemap[i].dump(dmp);
//    m_code.dump(dmp);
//    fclose(dmp);
//  }
}
예제 #4
0
/* statements:
 * 		stmt ->   beginblock
 */
void
stmt (void)
{
    {printf("\t<stm.asm.list>\n");}
    
  switch (lookahead)
    {
    case BEGIN:
      beginblock ();
      break;
/* 			| ifstmt  	 */

    case IF:
      ifstmt ();
      break;
/* 			| whlstmt  	 */
    case WHILE:
      whlstmt ();
      break;
/* 			| repstmt  	 */
    case REPEAT:
      repstmt ();
      break;
/* 			| forstmt  	 */
    case FOR:
      forstmt ();
      break;
/*  			| casestmt  	 */
    case CASE:
      casestmt ();
      break;
/* 			| prccall    	 */
/*			| assgstm    	 */
    case ID:
      
      /*ação semântica*/   
      {printf("\t<idstm.asm.list>\n");}   
         
      match (ID);
      if (lookahead == '[' || lookahead == ASGNM)
	{
	  while (lookahead == '[')
	    {
	      idxsynt ();
	    }
	  /* ':=' == ASGNM */
	  match (ASGNM);
	  expr ();
	}
      else
	{
	  if (lookahead == '(')
	    {
	      match ('(');
	      exprlist ();
	      match (')');
	    }
	}
      break;
      /*                     | ""
       */
    default:
      ;
    }				/*end switch */
}