Пример #1
0
ExprAST *Parser::handleType(std::string type) {


    if(currentToken.type!=TOK_TYPE){
        return Error("missing type", currentToken.line);
    }
    getNextToken();

    if(currentToken.type != TOK_IDENT){
        return Error("missing identifier", currentToken.line);
    }

    std::string identifier = currentToken.value;

    getNextToken();


    switch (currentToken.type) {
        case TOK_SEMICOLON:
            return handleVariable(identifier,type);
        case TOK_OPARENTHESES:
            return handleFunction(identifier,type);
        default:
            return nullptr;
    }

}
Пример #2
0
void DwarfVariableFinder::findVariables(const DWARFDie &die) {

  for (auto child = die.getFirstChild(); child; child = child.getSibling()) {
    switch(child.getTag()) {
      case dwarf::DW_TAG_variable:
      case dwarf::DW_TAG_formal_parameter:
      case dwarf::DW_TAG_constant:
        handleVariable(child);
        break;
      default:
        if (child.hasChildren())
          findVariables(child);
    }
  }
}
int main(int argc, const char *argv[])
{
    if (argc < 3) {
        return 1;
    }

    TCPClient socket("localhost", atoi(Config::ROOM_PORT), false);
    auto comm = shared_ptr<Communication>(new TCPCommunication(socket));
    auto g = shared_ptr<Entity>(new Entity(comm, 10));

    auto print_buffer = [] (Entity& sender, const std::string& buffer)
                        { cout << "[" << sender.getName() << "] >> " << buffer << endl; };

    auto handle_var = [] (Entity& sender, const std::string& buffer)
    {
        if (protocol::Var::validate(buffer)) {
            std::string err;
            auto object = Json::parse(buffer, err)[protocol::Var::tag];
            handleVariable(sender.relatives().get(), object);
        }
    };

    g->acceptMessageVisitor(print_buffer);
    g->acceptMessageVisitor(handleJoin);
    g->acceptMessageVisitor(handleQuit);
    g->acceptMessageVisitor(handle_var);

    g->setName(string(argv[1]));
    g->setMaxRelatives(4);
    g->setVariable("var1", string(argv[2]));

    thread dispatch([&](){g->dispatch();});

    while (true) {
        g->print();
        usleep(500000);
    }

    return 0;
}
Пример #4
0
// reverse polish calculator
int main(void) {
    int type;
    double op2;
    char s[MAXOP];
    
    while ((type = getop(s)) != EOF) {
        switch(type) {
            case NUMBER:
                push(atof(s));
                break;
            case FUNCTION:
                handleMathFunction(s);
                break;
            case VARIABLE:
                handleVariable(s);
                break;
            case '+':
                push(pop() + pop());
                break;
            case '-':
                op2 = pop();
                push(pop() - op2);
                break;
            case '*':
                push(pop() * pop());
                break;
            case '/':
                op2 = pop();
                if (op2 != 0.0) {
                    push(pop() / op2);
                } else {
                    printf("error: division by zero\n");
                }
                break;
            case '%':
                op2 = pop();
                if (op2 != 0.0) {
                    push((int)pop() % (int)op2);
                } else {
                    printf("error: modulo by zero\n");
                }
                break;
            case PEEK:
                // peek top value of the stack
                printf("\t%.8g peek value\n", peek());
                break;
            case DUPL:
                // duplicate the top value of the stack
                duplicateTop();
                break;
            case SWAP:
                swap();
                break;
            case CLEAR:
                clear1();
                break;
            case '\n':
                last = pop();
                printf("\t%.8g\n", last);
                break;
            default:
                printf("error: unknown command %s\n", s);
                break;
        }
    }
    return 0;
}
Пример #5
0
bool testHandler() {
	SPConfig config = (SPConfig)calloc(1, spConfigGetConfigStructSize());
	SP_CONFIG_MSG msg = SP_CONFIG_SUCCESS;

	ASSERT_TRUE(config != NULL);

	ASSERT_FALSE(handleVariable(config, "a", 1, "spImagesDirectori", "C:\\MyDocuments\\",
			&msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_LINE);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spImagesDirectory", "C:\\My Documents\\",
			&msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_STRING);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spImagesPrefix", "my image", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_STRING);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spImagesSuffix", ".jpj", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_STRING);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spNumOfImages", "-9000", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_INTEGER);
	msg = SP_CONFIG_SUCCESS;

	// check that a valid int is according to the rules in the forum (next 4 tests)
	ASSERT_TRUE(handleVariable(config, "a", 1, "spNumOfImages", "014", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);
	ASSERT_TRUE(spConfigGetNumOfImages(config, &msg) == 14);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_TRUE(handleVariable(config, "a", 1, "spNumOfImages", "+1", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);
	ASSERT_TRUE(spConfigGetNumOfImages(config, &msg) == 1);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spNumOfImages", "1.0", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_INTEGER);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spNumOfImages", "20 40", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_INTEGER);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spNumOfSimilarImages", "0", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_INTEGER);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spKNN", "aaa", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_INTEGER);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spLoggerLevel", "5", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_INTEGER);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spPCADimension", "9", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_INTEGER);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spPCADimension", "30", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_INTEGER);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spKDTreeSplitMethod", "something", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_KDTREE_SPLIT_METHOD);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spExtractionMode", "tru", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_BOOLEAN);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_FALSE(handleVariable(config, "a", 1, "spMinimalGUI", "fal", &msg));
	ASSERT_TRUE(msg == SP_CONFIG_INVALID_BOOLEAN);
	msg = SP_CONFIG_SUCCESS;

	ASSERT_TRUE(handleVariable(config, "a", 1, "spImagesDirectory", "C:\\Documents\\",
			&msg));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);
	ASSERT_TRUE(!strcmp(spConfigGetImagesDirectory(config, &msg), "C:\\Documents\\"));

	ASSERT_TRUE(handleVariable(config, "a", 1, "spImagesSuffix", ".bmp",
			&msg));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);
	ASSERT_TRUE(!strcmp(spConfigGetImagesSuffix(config, &msg), ".bmp"));

	ASSERT_TRUE(handleVariable(config, "a", 1, "spNumOfFeatures", "80",
			&msg));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);
	ASSERT_TRUE(spConfigGetNumOfFeatures(config, &msg) == 80);

	ASSERT_TRUE(handleVariable(config, "a", 1, "spPCADimension", "19",
			&msg));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);
	ASSERT_TRUE(spConfigGetPCADim(config, &msg) == 19);

	ASSERT_TRUE(handleVariable(config, "a", 1, "spExtractionMode", "true",
			&msg));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);
	ASSERT_TRUE(spConfigIsExtractionMode(config, &msg));

	ASSERT_TRUE(handleVariable(config, "a", 1, "spKDTreeSplitMethod", "INCREMENTAL",
			&msg));
	ASSERT_TRUE(msg == SP_CONFIG_SUCCESS);
	ASSERT_TRUE(spConfigGetSplitMethod(config, &msg) == INCREMENTAL);

	spConfigDestroy(config);
	return true;
}