예제 #1
0
void ExprSMTLIBPrinter::printUpdatesAndArray(const UpdateNode *un,
                                             const Array *root) {
  if (un != NULL) {
    *p << "(store ";
    p->pushIndent();
    printSeperator();

    // recurse to get the array or update that this store operations applies to
    printUpdatesAndArray(un->next, root);

    printSeperator();

    // print index
    printExpression(un->index, SORT_BITVECTOR);
    printSeperator();

    // print value that is assigned to this index of the array
    printExpression(un->value, SORT_BITVECTOR);

    p->popIndent();
    printSeperator();
    *p << ")";
  } else {
    // The base case of the recursion
    *p << root->name;
  }
}
예제 #2
0
void ExprSMTLIBPrinter::printSelectExpr(const ref<SelectExpr> &e,
                                        ExprSMTLIBPrinter::SMTLIB_SORT s) {
  // This is the if-then-else expression

  *p << "(" << getSMTLIBKeyword(e) << " ";
  p->pushIndent(); // add indent for recursive call

  // The condition
  printSeperator();
  printExpression(e->getKid(0), SORT_BOOL);

  /* This operator is special in that the remaining children
   * can be of any sort.
   */

  // if true
  printSeperator();
  printExpression(e->getKid(1), s);

  // if false
  printSeperator();
  printExpression(e->getKid(2), s);

  p->popIndent(); // pop indent added for recursive call
  printSeperator();
  *p << ")";
}
예제 #3
0
    void printSelectStatementInfo(SelectStatement* stmt, uintmax_t numIndent) {
        inprint("SelectStatement", numIndent);
        inprint("Fields:", numIndent+1);
        for (Expr* expr : *stmt->selectList) printExpression(expr, numIndent+2);

        inprint("Sources:", numIndent+1);
        printTableRefInfo(stmt->fromTable, numIndent+2);

        if (stmt->whereClause != NULL) {
            inprint("Search Conditions:", numIndent+1);
            printExpression(stmt->whereClause, numIndent+2);
        }


        if (stmt->unionSelect != NULL) {
            inprint("Union:", numIndent+1);
            printSelectStatementInfo(stmt->unionSelect, numIndent+2);
        }

        if (stmt->order != NULL) {
            inprint("OrderBy:", numIndent+1);
            printExpression(stmt->order->expr, numIndent+2);
            if (stmt->order->type == kOrderAsc) inprint("ascending", numIndent+2);
            else inprint("descending", numIndent+2);
        }

        if (stmt->limit != NULL) {
            inprint("Limit:", numIndent+1);
            inprint(stmt->limit->limit, numIndent+2);
        }
    }
예제 #4
0
    void printOperatorExpression(Expr* expr, uintmax_t numIndent) {
        if (expr == NULL) {
            inprint("null", numIndent);
            return;
        }

        switch (expr->op_type) {
        case Expr::SIMPLE_OP:
            inprintC(expr->op_char, numIndent);
            break;
        case Expr::AND:
            inprint("AND", numIndent);
            break;
        case Expr::OR:
            inprint("OR", numIndent);
            break;
        case Expr::NOT:
            inprint("NOT", numIndent);
            break;
        default:
            inprintU(expr->op_type, numIndent);
            break;
        }
        printExpression(expr->expr, numIndent+1);
        if (expr->expr2 != NULL) printExpression(expr->expr2, numIndent+1);
    }
예제 #5
0
파일: model.c 프로젝트: Younday/AI1
void printExpression(Expression e) {
  if (e->operator == CONSTANT) {
    printf ("%s", (e->atom==TRUE ? "true" :"false"));
    return;
  }
  if (e->operator == IDENTIFIER) {
    printf("%s", identifiers[e->atom]);
    return;
  }
  if (e->operator == NEG) {
    printf ("!");
    printExpression(e->operand1);
    return;
  }

  printf("(");
  printExpression(e->operand1);

  switch(e->operator) {
  case EQUIV:
    printf (" <=> ");
    break;
  case IMPLIES:
    printf (" => ");
    break;
  case AND:
    printf ("*");
    break;
  case OR:
    printf (" + ");
    break;
  }
  printExpression(e->operand2);
  printf(")");
}
예제 #6
0
void ExprSMTLIBPrinter::printNotEqualExpr(const ref<NeExpr> &e) {
  *p << "(not (";
  p->pushIndent();
  *p << "="
     << " ";
  p->pushIndent();
  printSeperator();

  /* The "=" operators allows both sorts. We assume
   * that the second argument sort should be forced to be the same sort as the
   * first argument
   */
  SMTLIB_SORT s = getSort(e->getKid(0));

  printExpression(e->getKid(0), s);
  printSeperator();
  printExpression(e->getKid(1), s);
  p->popIndent();
  printSeperator();

  *p << ")";
  p->popIndent();
  printSeperator();
  *p << ")";
}
예제 #7
0
void printMoveStatement(FILE* file, IR_myStatement statement, int spaceNum)
{
    fprintf(file, "Move(");
    printExpression(file, statement->u.move.dst, spaceNum + 2);

    indentAndPrintToFile(file, spaceNum, ", ");
    printExpression(file, statement->u.move.src, spaceNum + 2);

    indentAndPrintToFile(file, spaceNum, ")\n");
}
예제 #8
0
void printBinOperation(FILE* file, IR_myExp exp, int spaceNum)
{
    fprintf(file, "BinOperation(%s, ", g_binOperatorStr[exp->u.binOperation.op]);
    printExpression(file, exp->u.binOperation.left, spaceNum + 2);

    indentAndPrintToFile(file, spaceNum, ", ");
    printExpression(file, exp->u.binOperation.right, spaceNum + 2);

    indentAndPrintToFile(file, spaceNum, ")\n");
}
예제 #9
0
void ExprSMTLIBPrinter::printCastToSort(const ref<Expr> &e,
                                        ExprSMTLIBPrinter::SMTLIB_SORT sort) {
  switch (sort) {
  case SORT_BITVECTOR:
    if (humanReadable) {
      p->breakLineI();
      *p << ";Performing implicit bool to bitvector cast";
      p->breakLine();
    }
    // We assume the e is a bool that we need to cast to a bitvector sort.
    *p << "(ite";
    p->pushIndent();
    printSeperator();
    printExpression(e, SORT_BOOL);
    printSeperator();
    *p << "(_ bv1 1)";
    printSeperator(); // printing the "true" bitvector
    *p << "(_ bv0 1)";
    p->popIndent();
    printSeperator(); // printing the "false" bitvector
    *p << ")";
    break;
  case SORT_BOOL: {
    /* We make the assumption (might be wrong) that any bitvector whos unsigned
     *decimal value is
     * is zero is interpreted as "false", otherwise it is true.
     *
     * This may not be the interpretation we actually want!
     */
    Expr::Width bitWidth = e->getWidth();
    if (humanReadable) {
      p->breakLineI();
      *p << ";Performing implicit bitvector to bool cast";
      p->breakLine();
    }
    *p << "(bvugt";
    p->pushIndent();
    printSeperator();
    // We assume is e is a bitvector
    printExpression(e, SORT_BITVECTOR);
    printSeperator();
    *p << "(_ bv0 " << bitWidth << ")";
    p->popIndent();
    printSeperator(); // Zero bitvector of required width
    *p << ")";

    if (bitWidth != Expr::Bool)
      std::cerr << "ExprSMTLIBPrinter : Warning. Casting a bitvector (length "
                << bitWidth << ") to bool!" << std::endl;

  } break;
  default:
    assert(0 && "Unsupported cast!");
  }
}
예제 #10
0
파일: model.c 프로젝트: Younday/AI1
void showExpSet(char *name, int size, Expression expset[]) {
  int i;
  printf("%s = [\n", name);
  for (i=0; i + 1 < size; i++) {
    printf("  ");
    printExpression(expset[i]);
    printf(" ;\n");
  }
  printf("  ");
  printExpression(expset[i]);
  printf("\n]\n");
}
예제 #11
0
void Expression1::printExpression()
{
  if(altNum == 1) {
    trm->printTrm();
  } else if(altNum == 2){
      trm->printTrm();
      cout<<"+";
      printExpression();
  } else if(altNum ==3) {
      trm->printTrm();
      cout<<"-";
      printExpression();
  }
}
예제 #12
0
파일: parser.c 프로젝트: BanditCat/lnz4
void printExpression( const LNZprogram* p, u32 expression, u32 level, 
		      const LNZprogram* names ){
  u64 ind = indexHelper( p, expression, names );
  if( ind && level ){
    u64 len;
    const u8* name;
    if( names != NULL )
      name = getName( names->names, ind, &len );
    else
      name = getName( p->names, ind, &len );
    for( u64 i = 0; i < len; ++i )
      putchar( (int)name[ i ] );
  }else{
    if( p->heap[ expression ].type == LNZ_LAMBDA_TYPE ){
      printf( "\\" );
      ind = 0;
      while( p->heap[ expression ].type == LNZ_LAMBDA_TYPE && !ind ){
	printf( "l%u", expression );
	expression = p->heap[ expression ].data;
	++level;
	ind = getIndex( p->pointers, (const u8*)( &expression ), sizeof( u32 ) );
	if( p->heap[ expression ].type == LNZ_LAMBDA_TYPE && !ind )
	  printf( " " );
	else{
	  printf( "." );
	  printExpression( p, expression, level + 1, names );
	}
      }
    }else if( p->heap[ expression ].type == LNZ_APPLICATION_TYPE ){
      u32 low = p->heap[ expression ].data & (u32)( -1 );
      u32 high = p->heap[ expression ].data >> 32;
      ind = indexHelper( p, high, names );
      u64 lind = indexHelper( p, low, names );
      if( p->heap[ low ].type == LNZ_LAMBDA_TYPE && !lind ){ 
	printf( "[" );
	printExpression( p, low, level + 1, names );
	printf( "]" );
      }else
	printExpression( p, low, level + 1, names );
      if( ( p->heap[ high ].type == LNZ_APPLICATION_TYPE || 
	  p->heap[ high ].type == LNZ_LAMBDA_TYPE ) && !ind ){

	printf( " [" );
	printExpression( p, high, level + 1, names );
	printf( "]" );
      }else{
	printf( " " );
	printExpression( p, high, level + 1, names );
      }
    }else if( p->heap[ expression ].type == LNZ_STRING_TYPE ){
예제 #13
0
void printExpression(struct Expression *expr, int depth) {
	if (expr == NULL) {
		printf("%*sNothing\n", depth, "");
		return;
	}

	if (expr->type == BRIDI) {
		printf("%*sbridi\n", depth, "");
		printf("%*sPredicate:\n", depth, "");
		printExpression(expr->pred, depth + 2);
		printf("%*sx1:\n", depth, "");
		printExpression(expr->x1, depth + 2);
		printf("%*sx2:\n", depth, "");
		printExpression(expr->x2, depth + 2);
		printf("%*sx3:\n", depth, "");
		printExpression(expr->x3, depth + 2);
		printf("%*sx4:\n", depth, "");
		printExpression(expr->x4, depth + 2);
		printf("%*sx5:\n", depth, "");
		printExpression(expr->x5, depth + 2);
	} else if (expr->type == GISMU) {
		printf("%*sgismu: %s\n", depth, "", expr->word);
	} else if (expr->type == CMAVO) {
		printf("%*scmavo: %s\n", depth, "", expr->word);
	} else if (expr->type == TANRU) {
		printf("%*stanru\n", depth, "");
		printf("%*stanru base:\n", depth, "");
		printExpression(expr->tanru_base, depth + 2);
		printf("%*stanru descriptor:\n", depth, "");
		printExpression(expr->tanru_desc, depth + 2);
	}
}
예제 #14
0
int main() {
    char* strMid = "9+(3-1)*3+10/2+1000*10";
    Sequence mid;
    initSequence(&mid);
    initMid(&mid, strMid);
    printExpression(&mid);

    Sequence post;
    initSequence(&post);
    initPost(&mid, &post);
    printExpression(&post);

    printf("Result=%d\n", calculate(&post));
    return 0;
}
예제 #15
0
void printJumpStatement(FILE* file, IR_myStatement statement, int spaceNum)
{
    fprintf(file, "Jump(");
    printExpression(file, statement->u.jump.exp, spaceNum + 2);

    indentAndPrintToFile(file, spaceNum, ")\n");
}
예제 #16
0
void printCJumpStatement(FILE* file, IR_myStatement statement, int spaceNum)
{
    fprintf(file, "CJump(%s, ", g_relOperatorStr[statement->u.cjump.op]);
    printExpression(file,  statement->u.cjump.left, spaceNum + 2);

    indentAndPrintToFile(file, spaceNum, ", ");
    printExpression(file,  statement->u.cjump.right, spaceNum + 2);

    indentAndPrintToFile(file, spaceNum, ", ");
    myLabel trueLabel = statement->u.cjump.trueLabel;
    fprintf(file, "%s, ", trueLabel == NULL ? "empty" : MySymbol_GetName(trueLabel));
    myLabel falseLabel = statement->u.cjump.falseLabel;
    fprintf(file, "%s, ", falseLabel == NULL ? "empty" : MySymbol_GetName(falseLabel));

    indentAndPrintToFile(file, spaceNum, ")\n");
}
예제 #17
0
void printMem(FILE* file, IR_myExp exp, int spaceNum)
{
    fprintf(file, "Mem(");
	printExpression(file, exp->u.mem, spaceNum + 2);

	indentAndPrintToFile(file, spaceNum, ")\n");
}
예제 #18
0
void printCall(FILE* file, IR_myExp exp, int spaceNum)
{
    fprintf(file, "Call(");
	printExpression(file, exp->u.call.func, spaceNum + 2);

	IR_myExpList exps = exp->u.call.args;
	while (exps)
	{
	    indentAndPrintToFile(file, spaceNum, ", ");
	    printExpression(file, exps->head, spaceNum + 2);

	    exps = exps->tails;
	}

	indentAndPrintToFile(file, spaceNum, ")\n");
}
예제 #19
0
 void printTableRefInfo(TableRef* table, uintmax_t numIndent) {
     switch (table->type) {
     case kTableName:
         inprint(table->name, numIndent);
         break;
     case kTableSelect:
         printSelectStatementInfo(table->select, numIndent);
         break;
     case kTableJoin:
         inprint("Join Table", numIndent);
         inprint("Left", numIndent+1);
         printTableRefInfo(table->join->left, numIndent+2);
         inprint("Right", numIndent+1);
         printTableRefInfo(table->join->right, numIndent+2);
         inprint("Join Condition", numIndent+1);
         printExpression(table->join->condition, numIndent+2);
         break;
     case kTableCrossProduct:
         for (TableRef* tbl : *table->list) printTableRefInfo(tbl, numIndent);
         break;
     }
     if (table->alias != NULL) {
         inprint("Alias", numIndent+1);
         inprint(table->alias, numIndent+2);
     }
 }
예제 #20
0
void ExprSMTLIBPrinter::printCastExpr(const ref<CastExpr> &e) {
  /* sign_extend and zero_extend behave slightly unusually in SMTLIBv2
   * instead of specifying of what bit-width we would like to extend to
   * we specify how many bits to add to the child expression
   *
   * e.g
   * ((_ sign_extend 64) (_ bv5 32))
   *
   * gives a (_ BitVec 96) instead of (_ BitVec 64)
   *
   * So we must work out how many bits we need to add.
   *
   * (e->width) is the desired number of bits
   * (e->src->getWidth()) is the number of bits in the child
   */
  unsigned int numExtraBits = (e->width) - (e->src->getWidth());

  *p << "((_ " << getSMTLIBKeyword(e) << " " << numExtraBits << ") ";

  p->pushIndent(); // add indent for recursive call
  printSeperator();

  // recurse
  printExpression(e->src, SORT_BITVECTOR);

  p->popIndent(); // pop indent added for recursive call
  printSeperator();

  *p << ")";
}
예제 #21
0
void printESeq(FILE* file, IR_myExp exp, int spaceNum)
{
    fprintf(file, "Eseq(");
	printStatement(file, exp->u.eseq.statement, spaceNum + 2);

	indentAndPrintToFile(file, spaceNum, ", ");
	printExpression(file, exp->u.eseq.exp, spaceNum + 2);

	indentAndPrintToFile(file, spaceNum, ")\n");
}
예제 #22
0
double evaluateExpression(SuffixExpression expression){
	
	int length = expression.size();
	if(length == 2)
		return expression[0];
	int i=0;
	while(i<length-1){//ignore the ending '#'

#ifdef LOCAL_DEBUG
		printExpression(expression);
#endif
		while(expression[i].type != Item::OPERATOR){
			i++;
		}
		//found an operator
		int positionOfOperator = i;
		double a, b;
		i--;
		while(expression[i].type != Item::OPERAND){
			i--;
		}
		a = expression[i];
		expression[i].clear();
		i--;
		while(expression[i].type != Item::OPERAND){
			i--;
		}
		b = expression[i];
		expression[i].clear();

		//now operands found
		double result;
		switch(expression[positionOfOperator]){
		case '+':
			result = b+a;
			break;
		case '-':
			result = b-a;
			break;
		case '*':
			result = b*a;
			break;
		case '/':
			result = b/a;
			break;
		default:
			throw "unknown operator";
		}

		expression[positionOfOperator] = result;
		i = positionOfOperator + 1;
	}
	return expression[length-2];
}
예제 #23
0
void CodeGenerator::printOutput(const Node *outputNode)
{
	ofs << "std::cout << ";
	Node *argument = outputNode->son;
	while(argument)
	{
		printExpression(argument);
		argument = argument->bro;
		if(argument)
			ofs << " << ";
	}
	ofs << ';' << std::endl;
}
예제 #24
0
void CodeGenerator::printExpression(const Node *operatorNode)
{
	if(!operatorNode)
		return;

	unsigned long long key;
	switch(operatorNode->kind)
	{
	case VAR:
		key = SymbolTable::hash(operatorNode->val.sVal);
		if(symbolTable.isInScopes(key))
			ofs << operatorNode->val.sVal;
		else
		{
			std::cerr << "variable is not declared : " << operatorNode->val.sVal << std::endl;
			exit(-1);
		}
		break;

	case INT:
		ofs << operatorNode->val.iVal;
		break;

	case CHAR:
		ofs << operatorNode->val.cVal;
		break;

	case STRING:
		ofs << '\"' << operatorNode->val.sVal << '\"';
		break;

//	case FUNCTION:
//		break;
	}

	printExpression(operatorNode->son);
	if(operatorNode->son)
		printExpression(operatorNode->son->bro);
}
예제 #25
0
void ExprSMTLIBPrinter::printSortArgsExpr(const ref<Expr> &e,
                                          ExprSMTLIBPrinter::SMTLIB_SORT s) {
  *p << "(" << getSMTLIBKeyword(e) << " ";
  p->pushIndent(); // add indent for recursive call

  // loop over children and recurse into each expecting they are of sort "s"
  for (unsigned int i = 0; i < e->getNumKids(); i++) {
    printSeperator();
    printExpression(e->getKid(i), s);
  }

  p->popIndent(); // pop indent added for recursive call
  printSeperator();
  *p << ")";
}
예제 #26
0
void ExprSMTLIBPrinter::printReadExpr(const ref<ReadExpr> &e) {
  *p << "(" << getSMTLIBKeyword(e) << " ";
  p->pushIndent();

  printSeperator();

  // print array with updates recursively
  printUpdatesAndArray(e->updates.head, e->updates.root);

  // print index
  printSeperator();
  printExpression(e->index, SORT_BITVECTOR);

  p->popIndent();
  printSeperator();
  *p << ")";
}
예제 #27
0
void ExprSMTLIBPrinter::printExtractExpr(const ref<ExtractExpr> &e) {
  unsigned int lowIndex = e->offset;
  unsigned int highIndex = lowIndex + e->width - 1;

  *p << "((_ " << getSMTLIBKeyword(e) << " " << highIndex << "  " << lowIndex
     << ") ";

  p->pushIndent(); // add indent for recursive call
  printSeperator();

  // recurse
  printExpression(e->getKid(0), SORT_BITVECTOR);

  p->popIndent(); // pop indent added for the recursive call
  printSeperator();
  *p << ")";
}
예제 #28
0
void ExprSMTLIBPrinter::printQuery() {
  if (humanReadable) {
    *p << "; Query from solver turned into an assert";
    p->breakLineI();
  }

  p->pushIndent();
  *p << "(assert";
  p->pushIndent();
  printSeperator();

  printExpression(queryAssert, SORT_BOOL);

  p->popIndent();
  printSeperator();
  *p << ")";
  p->popIndent();
  p->breakLineI();
}
예제 #29
0
void ExprSMTLIBPrinter::printConstraints() {
  if (humanReadable)
    *o << "; Constraints" << endl;

  // Generate assert statements for each constraint
  for (ConstraintManager::const_iterator i = query->constraints.begin();
       i != query->constraints.end(); i++) {
    *p << "(assert ";
    p->pushIndent();
    printSeperator();

    // recurse into Expression
    printExpression(*i, SORT_BOOL);

    p->popIndent();
    printSeperator();
    *p << ")";
    p->breakLineI();
  }
}
예제 #30
0
 void printInsertStatementInfo(InsertStatement* stmt, uintmax_t numIndent) {
     inprint("InsertStatment", numIndent);
     inprint(stmt->tableName, numIndent+1);
     if (stmt->columns != NULL) {
         inprint("Columns", numIndent+1);
         for (char* col_name : *stmt->columns) {
             inprint(col_name, numIndent+2);
         }
     }
     switch (stmt->type) {
     case InsertStatement::kInsertValues:
         inprint("Values", numIndent+1);
         for (Expr* expr : *stmt->values) {
             printExpression(expr, numIndent+2);
         }
         break;
     case InsertStatement::kInsertSelect:
         printSelectStatementInfo(stmt->select, numIndent+1);
         break;
     }
 }