void script_command_parser::add_script_command(std::string& input) {
    std::transform(input.begin(), input.end(), input.begin(), ::tolower);

    std::regex check_binary(".*b:.+?\\s(.+?)\\s.+");
    std::smatch matches;
    if (std::regex_match(input, matches, check_binary)) {
        if (isscript_command((std::string)matches[1], script_command::Type::LEFT_RIGHT)) { return; }
        script_command command = script_command(matches[1], script_command::Type::LEFT_RIGHT);
        commands.push_back(command);
    }
    else {
        std::regex check_unary(".*u:(.+)?\\s.+");
        if (std::regex_match(input, matches, check_unary)) {
            if (isscript_command((std::string)matches[1], script_command::Type::RIGHT)) { return; }
            script_command command = script_command(matches[1], script_command::Type::RIGHT);
            commands.push_back(command);
        } 
        else {
            std::regex check_null(".*n:(.+)");
            if (std::regex_match(input, matches, check_null)) {
                if (isscript_command((std::string)matches[1], script_command::Type::NONE)) { return; }
                script_command command = script_command(matches[1], script_command::Type::NONE);
                commands.push_back(command);
            }
        }
    }
}
Beispiel #2
0
/*
 * Extra a token from input.
 * If TOKEN_ERROR, something bad has happened in the attempt to do so.
 * Otherwise, this returns a valid token (possibly end of input).
 */
static enum token
tokenise(const char **v, char *buf, enum token lasttok)
{
	size_t		i, sz;

	/* Short-circuit this case. */
	if ('\0' == **v)
		return(TOKEN_END);

	/* Look for token in our predefined inputs. */
	for (i = 0; i < TOK__MAX; i++)
		if ('\0' != toks[i].key && **v == toks[i].key) {
			switch (toks[i].arity) {
			case (ARITY_NONE):
				(*v)++;
				return((enum token)i);
			case (ARITY_ONE):
				if ( ! check_unary(lasttok))
					continue;
				break;
			case (ARITY_TWO):
				if ( ! check_binary(lasttok))
					continue;
				break;
			}
			(*v)++;
			return((enum token)i);
		}

	/* See if we're a real number or identifier. */
	if (isdigit((int)**v) || '.' == **v) {
		sz = 0;
		for ( ; isdigit((int)**v) || '.' == **v; (*v)++) {
			assert(sz < BUFSZ);
			buf[sz++] = **v;
		}
		buf[sz] = '\0';
		return(TOKEN_NUMBER);
	} else if (isalpha((int)**v)) {
		sz = 0;
		for ( ; isalpha((int)**v); (*v)++) {
			assert(sz < BUFSZ);
			buf[sz++] = **v;
		}
		buf[sz] = '\0';
		if (0 == strcmp(buf, "sqrt"))
			return(TOKEN_SQRT);
		else if (0 == strcmp(buf, "exp"))
			return(TOKEN_EXPF);
	} 

	/* Eh... */
	return(TOKEN_ERROR);
}
Beispiel #3
0
		void add_reserved_word(std::string input_) {
			std::regex check_binary(".*b:.+?\\s(.+?)\\s.+");
			std::smatch matches;
			if (std::regex_match(input_, matches, check_binary)) {
				reserved_words.insert(matches[1]);
			}
			else {
				std::regex check_unary(".*u:(.+)?\\s.+");
				if (std::regex_match(input_, matches, check_unary)) {
					reserved_words.insert(matches[1]);
				}
				else {
					std::regex check_null(".*n:(.+)");
					if (std::regex_match(input_, matches, check_null)) {
						reserved_words.insert(matches[1]);
					}
				}
			}
            script_command_parser::add_script_command(input_);
		}
Beispiel #4
0
int check_types_in_expr(ast_node root) {
  symhashtable_t *hash = NULL;
  symnode_t *node = NULL;
  ast_node anode = NULL;

  switch (root->node_type) {
    case OP_ASSIGN_N:
    //check_binary(root);
    check_assignment(root);
    break;

    case OP_PLUS_N:
    check_binary(root);
    break;

    case OP_MINUS_N:
    check_binary(root);
    break;

    case OP_NEG_N:
    check_unary(root);
    break;

    case OP_TIMES_N:
        check_binary(root);
    break;

    case OP_DIVIDE_N:
        check_binary(root);
    break;

    case OP_EQUALS_N:
        check_binary(root);
    break;

    case OP_INCREMENT_N:
        check_unary(root);
    break;

    case OP_DECREMENT_N:
        check_unary(root);
    break;

    case OP_MODULUS_N:
        check_binary(root);
    break;

    case OP_LESS_THAN_N:
        check_binary(root);
    break;

    case OP_LESS_EQUAL_N:
        check_binary(root);
    break;

    case OP_GREATER_THAN_N:
        check_binary(root);
    break;

    case OP_GREATER_EQUAL_N:
        check_binary(root);
    break;

    case OP_NOT_EQUAL_N:
        check_binary(root);
    break;

    case OP_AND_N:
        check_binary(root);
    break;

    case OP_OR_N:
        check_binary(root);
    break;

    case OP_NOT_N:
        check_unary(root);
    break;

    case RETURN_N:
        check_unary(root);
    break;

    default:
      // printf("at default of switch\n");
      break;


  }

  /* Recurse on each child of the subtree root, with a depth one
     greater than the root's depth. */
  ast_node child;
  for (child = root->left_child; child != NULL; child = child->right_sibling)
    check_types_in_expr(child);
  return 0;
}