Esempio n. 1
0
static int
dump_endpoint(int argc, char** argv)
{
	if (argc < 2) {
		kprintf("usage: tcp_endpoint [address]\n");
		return 0;
	}

	TCPEndpoint* endpoint = (TCPEndpoint*)parse_expression(argv[1]);
	endpoint->Dump();

	return 0;
}
Esempio n. 2
0
static struct selection_statement *parse_switch_statement(struct parser *parser) {
	struct expression *expr;
	struct selection_statement *selstmt = selection_statement_init(SEL_TYPE_SWITCH);
	struct statement *stmt;

	expect(parser->lexer, TOK_LPAREN);
	expr = parse_expression(parser);
	expect(parser->lexer, TOK_RPAREN);
	stmt = parse_statement(parser);

	selstmt->switch_stmt.expr = expr;
	selstmt->switch_stmt.stmt = stmt;
	return selstmt;
}
Esempio n. 3
0
static struct iteration_statement *parse_while_statement(struct parser *parser) {
	struct expression *expr;
	struct statement *stmt;
	struct iteration_statement *iter_stmt = iteration_statement_init(ITER_TYPE_WHILE);

	expect(parser->lexer, TOK_LPAREN);
	expr = parse_expression(parser);
	expect(parser->lexer, TOK_RPAREN);
	stmt = parse_statement(parser);

	iter_stmt->while_stmt.expr = expr;
	iter_stmt->while_stmt.stmt = stmt;
	return iter_stmt;
}
void parse_primary_expression(void) {
  Token t = get_token();
  if (t.type == T_OPEN_BRACKET) {
    parse_expression();
    t = get_token();
    if (t.type != T_CLOSE_BRACKET) {
      fprintf(stderr, "Syntax Error: Mismatch Bracket\n");
      exit(-1);
    }
  } else {
    unget_token();
    parse_split();
  }
}
Esempio n. 5
0
struct node *parse_argument(struct compiler *compiler)
{
    struct node *result = alloc_node(compiler, N_ARGUMENT);

    result->left = parse_expression(compiler);
    result->right = 0;

    if(lexer_matches(compiler, T_COMMA))
        result->right = parse_argument(compiler);
    else
        result->right = 0;

    return result;
}
Esempio n. 6
0
 static inline boost::optional<mapnik::expression_ptr> xml_attribute_cast_impl(xml_tree const& tree, std::string const& source)
 {
     std::map<std::string,mapnik::expression_ptr>::const_iterator itr = tree.expr_cache_.find(source);
     if (itr != tree.expr_cache_.end())
     {
         return itr->second;
     }
     else
     {
         mapnik::expression_ptr expr = parse_expression(source);
         tree.expr_cache_.emplace(source,expr);
         return expr;
     }
 }
Esempio n. 7
0
/** parse_FOR            parse for statements.
 *
 *      for(<statement>; <expression>; <expression>)
 *              <statement>;
 *
 * @param p_function_id : ptr to this statements function Id.
 */
void cx_parser::parse_FOR(cx_symtab_node* p_function_id) {

    int break_point = put_location_marker();
    int statementMarker = put_location_marker();
    int condition_marker = put_location_marker();
    int increment_marker = put_location_marker();

    get_token_append(); // for

    conditional_get_token_append(tc_left_paren, err_missing_left_paren);

    if (token != tc_semicolon) {
        // declaration would go here //
        parse_declarations_or_assignment(p_function_id);
        conditional_get_token_append(tc_semicolon, err_missing_semicolon);
    } else get_token_append();

    fixup_location_marker(condition_marker);
    if (token != tc_semicolon) {

        // expr 2
        check_boolean(parse_expression());
        conditional_get_token_append(tc_semicolon, err_missing_semicolon);
    } else get_token_append();

    fixup_location_marker(increment_marker);
    if (token != tc_right_paren) {
        // expr 3
        parse_expression();
    }

    conditional_get_token_append(tc_right_paren, err_missing_right_paren);
    fixup_location_marker(statementMarker);
    parse_statement(p_function_id);
    fixup_location_marker(break_point);

}
Esempio n. 8
0
NodeBase* NodeStopRecord::run(base_script_t* param) {
    if (NULL == param) {
        IVR_WARN("base_script_t pointer should not be null");
        return NULL;
    }

    IVR_TRACE("%s", enter(param->name_var_map).c_str());

    const char* exit = EXIT_FAIL;
    string callid;
    fw_id_t fs_no = param->fid;

    if (true == parse_expression(_callid, param->name_var_map, callid)) {
        IVR_TRACE("callid=%s", callid.c_str());

        fs_opr_t* opr = NULL;

        if (fs_mgr_t::instance()->fetch_opr(fs_no, &opr) == IVR_SUCCESS) {
            if (NULL != opr) {
                if (opr->record(callid.c_str(), "", false) == IVR_SUCCESS) {
                    exit = EXIT_SUCC;
                } else {
                    IVR_WARN("opr stop record failed(callid %s)", _callid.c_str());
                }

                fs_mgr_t::instance()->free_opr(&opr);
            } else {
                IVR_WARN("fetch opr failed. freeswitch no is %d", fs_no);
            }
        }
    } else {
        IVR_WARN("parse callid failed(%s)", _callid.c_str());
    }

    NodeBase* exit_node_ptr = NULL;
    std::map<std::string, NodeBase*>::iterator citr;
    citr = _exit_node_map.find(exit);

    if (citr != _exit_node_map.end()) {
        exit_node_ptr = citr->second;

        IVR_TRACE("%s exit from %s()",
                  leave(param->name_var_map).c_str(), exit);
    } else {
        IVR_WARN("Can not find exit %s in _exit_node_map", exit);
    }

    return exit_node_ptr;
}
Esempio n. 9
0
File: parser.c Progetto: Saruta/a2c
struct instruction *parse_for(void)
{
  int decreasing = 0;
  eat(FOR);
  struct expr *lhs = parse_expression();
  struct assignment *a = parse_assignment(lhs);
  if (current_lang == LANG_EN && lookahead[0]->type == DECREASING)
  {
    decreasing = 1;
    eat(DECREASING);
  }
  else
    eat(UNTIL);
  struct expr *until = parse_expression();
  if (current_lang == LANG_FR && lookahead[0]->type == DECREASING)
  {
    decreasing = 1;
    eat(DECREASING);
  }
  eat(DO); eat(EOL);
  instructionlist_t block = parse_block();
  eat(END); eat(FOR); eat(EOL);
  return forblock(a, until, decreasing, block);
}
Esempio n. 10
0
/*
 *	RETURN statement
 *	Handles RETURN [ <expression> ] ;
 */
void
parse_return(TOKEN *first_token)
{
    TOKEN	token;
    int	token_class;

    out_white_space(first_token);
    out_str("return");

    token_class = parse_expression(&token);
    if (token_class != END_OF_LINE)
        parse_error("';' expected");
    else
        out_token(&token);
}
Esempio n. 11
0
File: v7.c Progetto: di3online/v7
static enum v7_err parse_if_statement(struct v7 *v7) {
  int old_no_exec = v7->no_exec;

  TRY(match(v7, '('));
  TRY(parse_expression(v7));
  TRY(match(v7, ')'));
  assert(v7->no_exec || v7->sp > 0);  // Stack may be empty if v7->no_exec
  if (!v7->no_exec && !v7_is_true(v7_top(v7)[-1])) {
    v7->no_exec = 1;
  }
  TRY(parse_compound_statement(v7));
  v7->no_exec = old_no_exec;

  return V7_OK;
}
Esempio n. 12
0
File: parse.c Progetto: Reen/gnuplot
struct at_type *
temp_at()
{
    if (at != NULL)
	free_at(at);
    
    at = (struct at_type *) gp_alloc(sizeof(struct at_type), "action table");

    memset(at, 0, sizeof(*at));		/* reset action table !!! */
    at_size = MAX_AT_LEN;

    parse_recursion_level = 0;
    parse_expression();
    return (at);
}
Esempio n. 13
0
/** parse_WHILE          parse while statement.
 *
 *      while(<expression>)
 *            <statement>;
 *
 * @param p_function_id : ptr to this statements function Id.
 */
void cx_parser::parse_WHILE(cx_symtab_node* p_function_id) {

    int break_point = put_location_marker();

    get_token_append(); // while
    conditional_get_token_append(tc_left_paren, err_missing_left_paren);

    check_boolean(parse_expression());

    conditional_get_token_append(tc_right_paren, err_missing_right_paren);

    parse_statement(p_function_id);

    fixup_location_marker(break_point);
}
Esempio n. 14
0
File: v7.c Progetto: di3online/v7
//  statement  =  declaration | return_statement | if_statement
//                assignment | expression [ ";" ]
static enum v7_err parse_statement(struct v7 *v7, int *is_return_statement) {
  if (*v7->cursor == '_' || is_alpha(*v7->cursor)) {
    TRY(parse_identifier(v7));    // Load identifier into v7->tok, v7->tok_len
    if (test_token(v7, "var", 3)) {
      TRY(parse_declaration(v7));
    } else if (test_token(v7, "return", 6)) {
      TRY(parse_return_statement(v7));
      if (is_return_statement != NULL) *is_return_statement = 1;
    } else if (test_token(v7, "if", 2)) {
      TRY(parse_if_statement(v7));
    } else {
      v7->cursor = v7->tok;
      TRY(parse_expression(v7));
    }
  } else {
    TRY(parse_expression(v7));
  }

  // Skip optional semicolons
  while (*v7->cursor == ';') match(v7, *v7->cursor);

  //return is_return_statement;
  return V7_OK;
}
Esempio n. 15
0
static int
cmd_faults(int argc, char** argv)
{
	if (argc > 2) {
		print_debugger_command_usage(argv[0]);
		return B_KDEBUG_ERROR;
	}

	if (argc == 2)
		gInvokeCommandDirectly = parse_expression(argv[1]) == 0;

	kprintf("Fault handling is %s%s.\n", argc == 2 ? "now " : "",
		gInvokeCommandDirectly ? "off" : "on");
	return 0;
}
Esempio n. 16
0
static int SiS19X_DebuggerCommand(int argc, char** argv)
{
    const char* usageInfo = "usage:" DRIVER_NAME " [index] <t|r>\n"
                            " - t - dump Transmit ring;\n"
                            " - r - dump Receive ring.\n"
                            " - g - dump reGisters.\n";

    uint64 cardId = 0;
    int cmdIndex = 1;

    if (argc < 2) {
        kprintf(usageInfo);
        return 0;
    } else if (argc > 2) {
        cardId = parse_expression(argv[2]);
        cmdIndex++;
    }

    if (cardId >= numCards) {
        kprintf("%" B_PRId64 " - invalid index.\n", cardId);
        kprintf(usageInfo);
        return 0;
    }

    Device* device = gDevices[cardId];
    if (device == NULL) {
        kprintf("Invalid device pointer!!!.\n");
        return 0;
    }

    switch(*argv[cmdIndex]) {
    case 'g':
        device->DumpRegisters();
        break;
    case 't':
        device->fTxDataRing.Dump();
        break;
    case 'r':
        device->fRxDataRing.Dump();
        break;
    default:
        kprintf("'%s' - invalid parameter\n", argv[cmdIndex]);
        kprintf(usageInfo);
        break;
    }

    return 0;
}
Esempio n. 17
0
File: v7.c Progetto: di3online/v7
// variable = identifier { '.' identifier | '[' expression ']' }
static enum v7_err parse_variable(struct v7 *v7) {
  struct v7_val **v = NULL, key = str_to_val(v7->tok, v7->tok_len);
  struct v7_val *ns = find(v7, &key), ro_prop;

  if (!v7->no_exec) {
    TRY(v7_make_and_push(v7, V7_UNDEF));
    v = v7_top(v7);
  }

  while (*v7->cursor == '.' || *v7->cursor == '[') {
    int ch = *v7->cursor;

    TRY(match(v7, ch));
    CHECK(v7->no_exec || ns != NULL, V7_SYNTAX_ERROR);
    v7->cur_obj = ns;

    if (ch == '.') {
      TRY(parse_identifier(v7));
      if (!v7->no_exec) {
        key = str_to_val(v7->tok, v7->tok_len);
        ns = get2(ns, &key);
        if (ns != NULL && ns->type == V7_RO_PROP) {
          ns->v.prop_func(v7->cur_obj, &ro_prop);
          ns = &ro_prop;
        }
      }
    } else {
      TRY(parse_expression(v7));
      TRY(match(v7, ']'));
      if (!v7->no_exec) {
        ns = get2(ns, v7_top(v7)[-1]);
        if (ns != NULL && ns->type == V7_RO_PROP) {
          ns->v.prop_func(v7->cur_obj, &ro_prop);
          ns = &ro_prop;
        }
        TRY(inc_stack(v7, -1));
      }
    }
  }

  if (v != NULL && ns != NULL) {
    free_val(v7, v[-1]);
    v[-1] = ns;
    v[-1]->ref_count++;
  }

  return V7_OK;
}
Esempio n. 18
0
File: parser.c Progetto: cenan/betik
static ifstatement_t* parse_if(parser_t* p)
{
	ifstatement_t* ifstatement = (ifstatement_t*)malloc(sizeof(ifstatement_t));
	match(p, TT_IF);
	ifstatement->expression = parse_expression(p);
	ifstatement->block = parse_block(p);
	token_type_t tok = get_token(p->t);
	if (TT_ELSE == tok) {
		ifstatement->else_block = parse_block(p);
		match(p, TT_END);
	} else {
		ifstatement->else_block = 0;
		expect(p, TT_END);
	}
	return ifstatement;
}
Esempio n. 19
0
File: parser.c Progetto: Saruta/a2c
struct instruction *parse_if(void)
{
  instructionlist_t elseblock;
  eat(IF);
  struct expr *cond = parse_expression();
  eat(THEN); eat(EOL);
  instructionlist_t block = parse_block();
  if (lookahead[0]->type == ELSE)
  {
    eat(ELSE); eat(EOL);
    elseblock = parse_block();
  }
  else elseblock = empty_instructionlist();
  eat(END); eat(IF); eat(EOL);
  return ifthenelseblock(cond, block, elseblock);
}
Esempio n. 20
0
File: parser.c Progetto: Saruta/a2c
struct instruction *parse_while(void)
{
  eat(WHILE); 
  if (current_lang == LANG_FR)
    eat(SO);

  struct expr *cond = parse_expression();
  eat(DO); eat(EOL);
  instructionlist_t block = parse_block();
  eat(END); eat(WHILE); 
  if (current_lang == LANG_FR)
    eat(SO); 

  eat(EOL);
  return whileblock(cond, block);
}
Esempio n. 21
0
/*
 *	IF statement
 */
void
parse_if(TOKEN *first_token)
{
    TOKEN	token;

    out_white_space(first_token);
    out_str("if (");

    if ((parse_expression(&token) != RESERVED) ||
            (token.token_type != THEN))
        parse_error("Missing THEN in IF statement");
    else {
        out_pre_line(&token);
        out_char(')');
        out_white_space(&token);
    }
}
Esempio n. 22
0
File: parser.c Progetto: Saruta/a2c
struct instruction *parse_switch(void)
{
  instructionlist_t otherwiseblock;
  eat(SWITCH);
  struct expr *cond = parse_expression();
  eat(DO); eat(EOL);
  caseblocklist_t caselist = empty_caseblocklist();
  while (lookahead[0]->type != END && lookahead[0]->type != OTHERWISE)
    list_push_back(caselist, parse_caseblock());
  if (lookahead[0]->type == OTHERWISE)
  {
    eat(OTHERWISE);
    otherwiseblock = parse_block();
  } else otherwiseblock = empty_instructionlist();
  eat(END); eat(SWITCH); eat(EOL);
  return switchblock(cond, caselist, otherwiseblock);
}
Esempio n. 23
0
Node* Parser::parse_constant_definition()
{ // expects TOKEN_WORD as a current token
	Node *node = create_node(NODE_CONSTANT_DEFINITION);
	node->constant_definition_name = _current->word;

	next_token();

	if (_current->kind != TOKEN_EQUALS) {
		error("Error: expected '=' in constant definition for \"%s\"",
				node->constant_definition_name.c_str());
	} else {
		next_token();
		node->next.push_back(parse_expression());
	}

	return node;
}
Esempio n. 24
0
	void Parser::parse_return(StatementList *list)
	{
		ReturnNode *node = list->add<ReturnNode>(memory_pool);

		node->range.capture(lexer.lexeme);
		
		step();

		if(is_expression(lexeme()))
		{
			node->has_value = true;
			node->value = parse_expression();
			lexer.lexeme.prev_set(node->range);
		}
		else
			node->has_value = false;
	}
Esempio n. 25
0
struct node *parse_array_element(struct compiler *compiler)
{
    struct node *result = alloc_node(compiler, N_ARRAY_ELEMENT);

    result->left = parse_expression(compiler);

    if(lexer_current(compiler) == T_COMMA)
    {
        lexer_next(compiler);

        result->right  = parse_array_element(compiler);
    }
    else
        result->right = 0;

    return result;
}
Esempio n. 26
0
ASTNode* parse_phi(std::vector<token> &tokens, tokIter &it) {
  START_PARSE(PhiNode);
  READ_TEXT("phi");
  while(check_next(tokens,it,OPENBRACE)) {
    it++;
    ASTNode* expr = parse_expression(tokens,it);
    if (!expr) PARSE_ERR("phi node had a bad value?");
    if (!check_next(tokens,it,VAR)) { delete expr; PARSE_ERR("phi node had bad predecessor?");}
    it++;
    std::string pred = it->text;
    if (!check_next(tokens,it,CLOSEBRACE)) { delete expr; PARSE_ERR("phi node format...");};
    it++;
    node->values.push_back(ASTsubtree(expr));
    node->source_blocks.push_back(current_function+pred);
  }
  SUCCEED_PARSE;
}
Esempio n. 27
0
File: v7.c Progetto: di3online/v7
//  factor  =   number | string_literal | "(" expression ")" |
//              variable | "this" | "null" | "true" | "false" |
//              "{" object_literal "}" |
//              "[" array_literal "]" |
//              function_definition |
//              function_call
static enum v7_err parse_factor(struct v7 *v7) {
  int old_sp = v7_sp(v7);

  if (*v7->cursor == '(') {
    TRY(match(v7, '('));
    TRY(parse_expression(v7));
    TRY(match(v7, ')'));
  } else if (*v7->cursor == '\'' || *v7->cursor == '"') {
    TRY(parse_string_literal(v7));
  } else if (*v7->cursor == '{') {
    TRY(parse_object_literal(v7));
  } else if (is_alpha(*v7->cursor) || *v7->cursor == '_') {
    TRY(parse_identifier(v7));
    if (test_token(v7, "this", 4)) {
      inc_stack(v7, 1);
      v7_top(v7)[-1] = &v7->scopes[v7->current_scope];
    } else if (test_token(v7, "null", 4)) {
      TRY(v7_make_and_push(v7, V7_NULL));
    } else if (test_token(v7, "true", 4)) {
      TRY(v7_make_and_push(v7, V7_BOOL));
      v7_top(v7)[-1]->v.num = 1;
    } else if (test_token(v7, "false", 5)) {
      TRY(v7_make_and_push(v7, V7_BOOL));
      v7_top(v7)[-1]->v.num = 0;
    } else if (test_token(v7, "function", 8)) {
      TRY(parse_function_definition(v7, NULL, 0));
    } else if (test_token(v7, "delete", 6)) {
      TRY(parse_delete(v7));
    } else {
      TRY(parse_variable(v7));
    }
  } else {
    TRY(parse_num(v7));
  }

  if (*v7->cursor == '(') {
    TRY(parse_function_call(v7));
  }

  // Don't leave anything on stack if no execution flag is set
  if (v7->no_exec) {
    inc_stack(v7, old_sp - v7->sp);
  }

  return V7_OK;
}
Esempio n. 28
0
/** parse_SWITCH         parse switch statements.
 *
 *      switch(<expression>){
 *              case <const-expression>:
 *              default:
 *      }
 *
 * NOTE:
 *      Broken/not implemented yet.
 *
 * @param p_function_id : ptr to this statements function Id.
 */
void cx_parser::parse_SWITCH(cx_symtab_node* p_function_id) {

    get_token_append();
    conditional_get_token_append(tc_left_paren, err_missing_left_paren);

    cx_type *p_expr_type = parse_expression()->base_type();

    conditional_get_token_append(tc_right_paren, err_missing_right_paren);

    if ((p_expr_type != p_integer_type)
            && (p_expr_type != p_char_type)
            && (p_expr_type->form != fc_enum)) {
        cx_error(err_incompatible_types);
    }

    parse_statement(p_function_id);

}
Esempio n. 29
0
File: parse.cpp Progetto: ubsan/pink
static statement parse_stmt(str_iter& iter) {
  statement stmt;
  auto cur_tok = token::get(iter);

  cur_tok.match(token_match()
    .keyword_return([&]() {
      stmt.kind = Stmt_return;
      stmt.data.return_ = parse_expression(iter);
    })
    .close_brace([&]() {
      stmt.kind = Stmt_none;
    })
    ._([&](){
      cur_tok.error(str("statement"));
    })
  );
  return stmt;
}
Esempio n. 30
0
// DebugPort
int
KernelDebug::DebugPort(int argc, char** argv)
{
	if (argc < 2) {
		kprintf("usage: ufs_port <port pointer>\n");
		return 0;
	}
	RequestPort *port = (RequestPort*)parse_expression(argv[1]);
	kprintf("port %p:\n", port);
	kprintf("  status      : %lx\n", port->fPort.fInitStatus);
	kprintf("  is owner    : %d\n", port->fPort.fOwner);
	kprintf("  owner port:   %ld\n", port->fPort.fInfo.owner_port);
	kprintf("  client port:  %ld\n", port->fPort.fInfo.client_port);
	kprintf("  size:         %ld\n", port->fPort.fInfo.size);
	kprintf("  capacity:     %ld\n", port->fPort.fCapacity);
	kprintf("  buffer:       %p\n", port->fPort.fBuffer);
	return 0;
}