Esempio n. 1
0
// Parser for integers (eg, "123") or an integer range (eg, "123..456")
bool
get_range(const char **s, uint32 *pstart, uint32 *pend)
{
    uint32 start, end;
    const char *tmp = *s;
    int ret = get_expression(&tmp, &start);
    if (!ret)
        return ret;
    if (tmp[0] != '.' || tmp[1] != '.') {
        // Only a single integer present.
        *s = tmp;
        *pend = *pstart = start;
        return ret;
    }
    // Looks like an integer range.
    tmp += 2;
    ret = get_expression(&tmp, &end);
    if (ret) {
        *s = tmp;
        if (start > end) {
            *pstart = end;
            *pend = start;
        } else {
            *pstart = start;
            *pend = end;
        }
    }
    return ret;
}
Esempio n. 2
0
void sysFncExec(TknKind kd) /* 내장함수실행 */
{
  double d;
  string s;

  switch (kd) {
  case Toint:
       code = nextCode();
       stk.push((int)get_expression('(', ')'));               /* 끝수 버림 */
       break;
  case Input:
       nextCode(); nextCode(); code = nextCode();       /* input ( ) 건너뜀 */
       getline(cin, s);                                        /* 1행 읽기  */
       stk.push(atof(s.c_str()));                   /* 숫자로 변환해서 저장 */
       break;
  case Print: case Println:
       do {
         code = nextCode();
         if (code.kind == String) {                             /* 문자열 출력 */
           cout << code.text; code = nextCode();
         } else {
           d = get_expression();             /* 함수 내에서 exit 가능성이 있다 */
           if (!exit_Flg) cout << d;                              /* 수치 출력 */
         }
       } while (code.kind == ',');               /* , 라면 파라미터가 계속된다 */
       if (kd == Println) cout << endl;                  /* println이면 줄바꿈 */
       break;
  }
}
		auto do_binary_operator_complex(
			vector_expression<LExpr> const& lhs,
			vector_expression<RExpr> const& rhs,
			std::index_sequence<Is...>) noexcept
		{
			using vector_type = vector<typename Expr::value_type, Expr::size(), typename Expr::base_tag>;
			using binary_functor_type = typename Expr::functor_type;
			return vector_type{ binary_functor_type::get<Is>(get_expression(lhs), get_expression(rhs))... };
		}
Esempio n. 4
0
int main(int argc, char *argv[]) {
    int i, j, output;
    int test;
    char combinestr[100] = "(";
    if(argc == 1) {
        printf("Logical Expression 1 :\n");
        get_expression(ipstr);
        truth_table(ipstr, fnvalues1, &numvar);

        strcat(combinestr, ipstr);
        strcat(combinestr, "=");
        printf("\nLogical Expression 2 :\n");
        get_expression(ipstr);
        truth_table(ipstr, fnvalues2, &numvar);
        strcat(combinestr, ipstr);
        strcat(combinestr, ")");

        truth_table(combinestr, fnvalues1, &numvar);

        test = test_for_tautology(fnvalues1, numvar);
        if(test == 1)
            printf("\nThe given functions are equivalent!\n");
        else
            printf("\nThe given functions are NOT equivalent!\n");
    }
    else if(argc != 3) {
        printf("Please enter exactly two logical expressions!");
        return 0;
    }
    else {
        printf("Logical Expression 1 :\n");
        strcpy(ipstr, argv[1]);
        truth_table(ipstr, fnvalues1, &numvar);

        strcat(combinestr, ipstr);
        strcat(combinestr, "=");
        printf("\nLogical Expression 2 :\n");
        strcpy(ipstr, argv[2]);
        truth_table(ipstr, fnvalues2, &numvar);
        strcat(combinestr, ipstr);
        strcat(combinestr, ")");

        truth_table(combinestr, fnvalues1, &numvar);

        test = test_for_tautology(fnvalues1, numvar);
        if(test == 1)
            printf("\nThe given functions are equivalent!\n");
        else
            printf("\nThe given functions are NOT equivalent!\n");

    }

    return 0;
}
Esempio n. 5
0
void bitsetVar::setVar(const char *s) {
    uint32 idx, val;
    if (!get_expression(&s, &idx) || !get_expression(&s, &val)) {
        ScriptError("Expected <index> <value>");
        return;
    }
    if (idx > maxavail) {
        ScriptError("Index out of range (0..%d)", maxavail);
        return;
    }
    ASSIGNBIT(data, idx, val);
}
Esempio n. 6
0
static void
LedSet(const char *cmd, const char *args)
{
    uint32 id, value;
    if (!get_expression(&args, &id) || !get_expression(&args, &value)) {
        ScriptError("Expected <id> <value>");
        return;
    }
    NLED_SETTINGS_INFO settings;
    settings.LedNum = id;
    settings.OffOnBlink = value;
    int ret = late_NLedSetDevice(NLED_SETTINGS_INFO_ID, &settings);
    if (!ret)
        Output("Return status of NLedSetDevice indicates failure");
}
Esempio n. 7
0
      size_t find_expression(const ExpressionTypePtr& expression) const
      {
        for(size_t i=0; i<num_expressions(); ++i)
          if(get_expression(i) == expression) return i;

        return num_expressions();
      }
Esempio n. 8
0
int main() {
    float num1, num2;
    char operation;
    char expression[51];
    const int done = int('e');
    fputs("enter an expresson to be evaluated.\nCurrently supports +-/*\n", stdout);
    fflush(stdout);
    while(1) {
        get_expression(expression, sizeof expression);
        printf("done = %i; expression = %s; int(expression) = %i\n", done, expression, int(expression));
        switch(atoi(expression)) {
        case done:
            return(0);
            break;
        default:
            fputs("Invalid expression\n", stdout);
        }

        printf("%s\n", expression);
        /* scanf("%f%c%f", &num1, &operation, &num2); */
        /* if(operation == '+') */
        /* printf("%f\n", num1 + num2); */
        /* if(operation == '/') */
        /* printf("%f\n", num1 / num2); */
        /* if(operation == '-') */
        /* printf("%f\n", num1 - num2); */
        /* if(operation == '*') */
        /* printf("%f\n", num1 * num2); */
    }
    return 0;
}
Esempio n. 9
0
static bool get_args (const char **s, const char *keyw, uint32 *args, uint count)
{
  if (!count)
    return true;

  if (peek_char (s) != '(')
  {
    ScriptError("%s(%d args) expected", keyw, count);
    return false;
  }

  (*s)++;
  while (count--)
  {
    if (!get_expression (s, args, 0, count ? 0 : PAREN_EXPECT | PAREN_EAT))
    {
error:
      ScriptError("not enough arguments to function %s", keyw);
      return false;
    }

    if (!count)
      break;

    if (peek_char (s) != ',')
      goto error;

    (*s)++;
    args++;
  }

  return true;
}
Esempio n. 10
0
int main (int argc, char **argv) {
    if (argc < 2) {
        printf("Usage - `hexcalc {expression}`\n");
        return 0;
    }
    
    FILE *fp;
    int status;
    char path[1024];
    
    char *expression = get_expression(argc, argv);
    printf("evaling: %s\n", expression);
    
    char *exec_cmd = get_exec_cmd(expression);
    fp = popen(exec_cmd, "r");
    if (fp == NULL) {
        printf("Failed to run command\n" );
        return 1;
    }
    
    while (fgets(path, sizeof(path) - 1, fp) != NULL) {
        printf("result : %s", path);
    }
    
    free(expression);
    free(exec_cmd);
    
    pclose(fp);
    return 0;
}
Esempio n. 11
0
END_TEST

START_TEST (test_expression)
{
    int i;
    expression *e = get_expression("c1, symbol O+C");

    ck_assert_ptr_ne(e,NULL);
    ck_assert_int_eq(e->type, E_SELECTION);
    ck_assert_ptr_ne(e->left, NULL);
    ck_assert_ptr_eq(e->right, NULL);
    ck_assert_str_eq(e->value, "c1");
    ck_assert_int_eq(e->left->type,E_SYMBOL);
    ck_assert_ptr_ne(e->left->left,NULL);
    ck_assert_ptr_eq(e->left->right,NULL);
    ck_assert_int_eq(e->left->left->type,E_PLUS);
    ck_assert_int_eq(e->left->left->left->type,E_ID);
    ck_assert_int_eq(e->left->left->right->type,E_ID);
    ck_assert_str_eq(e->left->left->right->value,"C");
    ck_assert_str_eq(e->left->left->left->value,"O");
    for (i = E_SELECTION; i <= E_RANGE_OPEN_R; ++i) {
        ck_assert_ptr_ne(e_str(i), NULL);
    }
    ck_assert_ptr_eq(e_str(E_RANGE_OPEN_R+1), NULL);
}
bool PossibleWord::operator==(const PossibleWord& rhs) const
{
    return (is_valid() == rhs.is_valid() && 
            get_expression() == rhs.get_expression() &&
            get_tiles_to_use() == rhs.get_tiles_to_use() &&
            get_score() == rhs.get_score());
}
Esempio n. 13
0
bool intListVar::setVarItem(void *p, const char *s) {
    uint32 *d = (uint32*)p;
    if (! get_expression(&s, d)) {
        ScriptError("Expected <int>");
        return false;
    }
    return true;
}
Esempio n. 14
0
END_TEST

START_TEST (test_debug) /* this test just runs the debug output code to not get artificially low coverage */
{
    FILE *devnull = fopen("/dev/null", "w");
    expression *e = get_expression("c1, symbol O+C");
    print_expr(devnull, e, 0);
}
Esempio n. 15
0
static void
cmd_memaccess(const char *tok, const char *args)
{
    bool virt = toupper(tok[0]) == 'V';
    uint32 addr, size;
    if (!get_expression(&args, &addr) || !get_expression(&args, &size)) {
        ScriptError("Expected <addr> <size>");
        return;
    }

    alignMemAddr(&addr);

    if (virt)
        memDump((uint8 *)addr, size);
    else
        memPhysDump(addr, size);
}
Esempio n. 16
0
static void
cmd_sleep(const char *cmd, const char *args)
{
    uint32 msec;
    if (!get_expression(&args, &msec)) {
        ScriptError("Expected <milliseconds>");
        return;
    }
    Sleep(msec);
}
Esempio n. 17
0
void syntaxChk() /* 구문 검사 */
{
  syntaxChk_mode = true;
  for (Pc=1; Pc<(int)intercode.size(); Pc++) {
    code = firstCode(Pc);
    switch (code.kind) {
    case Func: case Option: case Var:                         /* 검사 완료 */
      break;
    case Else: case End: case Exit:
      code = nextCode(); chk_EofLine();
      break;
    case If: case Elif: case While:
      code = nextCode(); (void)get_expression(0, EofLine);            /* 식값 */
      break;
    case For:
      code = nextCode();
      (void)get_memAdrs(code);                              /* 제어 변수 주소 */
      (void)get_expression('=', 0);                                 /* 초깃값 */
      (void)get_expression(To, 0);                                  /* 최종값 */
      if (code.kind == Step) (void)get_expression(Step,0);          /* 증분값 */
      chk_EofLine();
      break;
    case Fcall:                                         /* 대입 없는 함수 호출 */
      fncCall_syntax(code.symNbr);
      chk_EofLine();
      (void)stk.pop();                                          /* 반환 값 불필요 */
      break;
    case Print: case Println:
      sysFncExec_syntax(code.kind);
      break;
    case Gvar: case Lvar:                                           /* 대입문 */
      (void)get_memAdrs(code);                                   /* 좌변 주소 */
      (void)get_expression('=', EofLine);                        /* 우변식 값 */
      break;
    case Return:
      code = nextCode();                                              /* 반환 값 */
      if (code.kind!='?' && code.kind!=EofLine) (void)get_expression();
      if (code.kind == '?') (void)get_expression('?', 0);
      chk_EofLine();
      break;
    case Break:
      code = nextCode();
      if (code.kind == '?') (void)get_expression('?', 0);
      chk_EofLine();
      break;
    case EofLine:
      break;
    default:
      err_exit("잘못된 기술입니다: ", kind_to_s(code.kind));
    }
  }
  syntaxChk_mode = false;
}
Esempio n. 18
0
static void
cmd_test(const char *cmd, const char *args)
{
    uint32 val;
    if (!get_expression(&args, &val)) {
        ScriptError("expected <expr>");
        return;
    }
    if (val)
        scrInterpret(args, ScriptLine);
}
Esempio n. 19
0
void rwfuncVar::setVar(const char *s) {
    uint32 val;
    uint32 args[50];
    if (!get_args(&s, name, args, numargs))
        return;
    if (!get_expression(&s, &val)) {
        ScriptError("Expected <value>");
        return;
    }
    func(true, args, val);
}
Esempio n. 20
0
void sysFncExec_syntax(TknKind kd) /* 내장 함수 검사*/
{
  switch (kd) {
  case Toint:
       code = nextCode(); (void)get_expression('(', ')');
       stk.push(1.0);
       break;
  case Input:
       code = nextCode();
       code = chk_nextCode(code, '('); code = chk_nextCode(code, ')');
       stk.push(1.0);                                             /* 적당한 값 */
       break;
  case Print: case Println:
       do {
         code = nextCode();
         if (code.kind == String) code = nextCode();        /* 문자열 출력 확인 */
         else (void)get_expression();                           /* 값 출력 확인 */
       } while (code.kind == ',');                /* , 라면 파라미터가 계속된다 */
       chk_EofLine();
       break;
  }
}
Esempio n. 21
0
static void
cmd_msgbox(const char *tok, const char *x)
{
    wchar_t title[MAX_CMDLEN];
    wchar_t msg[MAX_CMDLEN];
    uint32 flags = 0;

    get_wtoken(&x, title, ARRAY_SIZE(title));
    get_wtoken(&x, msg, ARRAY_SIZE(msg));
    get_expression(&x, &flags);

    MsgBoxResult = MessageBox(0, msg, title, flags);
}
Esempio n. 22
0
static void
cmd_runscript(const char *cmd, const char *args)
{
    char vn[MAX_CMDLEN];
    if (get_token(&args, vn, sizeof(vn))) {
        ScriptError("file name expected");
        return;
    }
    uint32 ignore = 0;
    get_expression(&args, &ignore);

    scrExecute(vn, !ignore);
}
Esempio n. 23
0
File: parser.c Progetto: fwum/fwum
static func_declaration *analyze_func(parse_source *source) {
	parse_token current = get_mandatory_token(source);
	func_declaration *func = new(func);
	func->parameters = ll_new();
	if(current.type != WORD) {
		semantic_error("Function declaration must be in the form func <name>(<parameters>) <returntype> {<block>}", current.origin);
	}
	func->name = current.data;
	current = get_mandatory_token(source);
	if(current.data.data[0] != '(') {
		semantic_error("Function name must be followed by an open parenthesis", current.origin);
	}
	current = get_mandatory_token(source);
	while(current.data.data[0] != ')') {
		statement *name = new(name);
		name->type = NAME;
		name->children = ll_new();
		if(current.type != WORD) {
			printf("%s\n", evaluate(current.data));
			semantic_error("Parameter names must be a valid identifier", current.origin);
		}
		name->data = current.data;
		statement *param_type = parse_type_literal(source);
		ll_add_first(name->children, param_type);
		param_type->children = NULL;
		ll_add_last(func->parameters, name);
		current = get_mandatory_token(source);
		if(current.data.data[0] == ',') {
			current = get_mandatory_token(source);
		}
	}
    statement *returnType = parse_type_literal(source);
	func->type = returnType->data;
    free(returnType);
	current = peek_mandatory_token(source);
	if(current.data.data[0] != '{') {
		semantic_error("Function bodies must start with an open brace ('{')", current.origin);
	}
	int indent = 1;
	get_mandatory_token(source);
	func->root = new(func->root);
	func->root->type = ROOT;
	func->root->data = new_slice("");
	func->root->children = ll_new();
	while(indent > 0) {
		statement *state = get_expression(source, &indent);
		if(state != NULL)
			ll_add_last(func->root->children, state);
	}
	return func;
}
Esempio n. 24
0
static void
powerMon(const char *cmd, const char *args)
{
    uint32 seconds;
    if (!get_expression(&args, &seconds))
        seconds = 0;

    uint32 start_time = GetTickCount();
    uint32 cur_time = start_time;
    uint32 fin_time = cur_time + seconds * 1000;

    for (;;) {
        SYSTEM_POWER_STATUS_EX2 stat2;
        memset(&stat2, 0, sizeof(stat2));
        int ret = late_GetSystemPowerStatusEx2(&stat2, sizeof(stat2), false);
        if (!ret) {
            Output(C_INFO "GetSystemPowerStatusEx2");
            return;
        }

        Output("%06d: %5d %5d %% %5ld %5ld %5ld %5ld "
               "%5d %5d %5ld %5ld %5d %5d"
               "  %5d %5d %5ld %5ld %5ld %5ld %5ld %5d",
               cur_time - start_time,                  //
               stat2.BatteryFlag,                      //
               stat2.BatteryLifePercent,               //
               stat2.BatteryVoltage,                   //  
               stat2.BatteryCurrent,                   //  
               stat2.BatteryAverageCurrent,            //  
               stat2.BatteryTemperature,               //  
               stat2.ACLineStatus,                     //  0x00
               stat2.Reserved1,                        //  0x00
               stat2.BatteryLifeTime,                  //  -1
               stat2.BatteryFullLifeTime,              //  -1
               stat2.Reserved2,                        //  0x00
               stat2.BackupBatteryFlag,                //  0x01
               stat2.BackupBatteryLifePercent,         //  255
               stat2.Reserved3,                        //  0x00
               stat2.BackupBatteryLifeTime,            //  -1
               stat2.BackupBatteryFullLifeTime,        //  -1
               stat2.BatteryAverageInterval,           //  0
               stat2.BatterymAHourConsumed,            //  0
               stat2.BackupBatteryVoltage,             //  0
               stat2.BatteryChemistry);                 //  5

        cur_time = GetTickCount();
        if (cur_time >= fin_time)
            break;
        Sleep(1000);
    }
}
Esempio n. 25
0
/* frdl hndl */
HRESULT CALLBACK frdl(PDEBUG_CLIENT4 Client, PCSTR args)
{
    HRESULT ret=E_FAIL;
    set_client(Client);

    ULONG64 fh_val;
    if (!get_expression(args, &fh_val, &args)) goto finish;

    if (fh_val) file_rdln((FILE*)fh_val);

    ret=S_OK;
finish:
    return ret;
}
Esempio n. 26
0
/* fwrt hndl input */
HRESULT CALLBACK fwrt(PDEBUG_CLIENT4 Client, PCSTR args)
{
    HRESULT ret=E_FAIL;
    set_client(Client);

    ULONG64 fh_val;
    if (!get_expression(args, &fh_val, &args)) goto finish;
    for (; *args && isspace(*args); args++);

    if (fh_val && file_wrtstr((FILE*)fh_val, args)) ret=S_OK;

finish:
    return ret;
}
Esempio n. 27
0
/* fcls hndl */
HRESULT CALLBACK fcls(PDEBUG_CLIENT4 Client, PCSTR args)
{
    HRESULT ret=E_FAIL;
    set_client(Client);

    ULONG64 fh_val;
    if (!get_expression(args, &fh_val, NULL)) goto finish;

    if (!fh_val || fclose((FILE*)fh_val)) {
        err_dbgprintf("File closure error\n");
    } else ret=S_OK;
finish:
    return ret;
}
bool PossibleWord::operator<(const PossibleWord& rhs) const
{
    if (is_valid() < rhs.is_valid())
    {
        return true;
    }
    else if (is_valid() == rhs.is_valid())
    {
        if (get_expression() < rhs.get_expression())
        {
            return true;
        }
        else if (get_expression() == rhs.get_expression())
        {
            if (get_tiles_to_use() < rhs.get_tiles_to_use())
            {
                return true;
            }
            else if (get_tiles_to_use() == rhs.get_tiles_to_use())
            {
                return get_score() < rhs.get_score();
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }
}
Esempio n. 29
0
		std::unique_ptr<Expression> PostfixOperatorParser::parse(ElsaParser* parser, std::unique_ptr<Expression> left)
		{
			auto exp = std::make_unique<PostfixOperatorExpression>();
			exp->set_expression(std::move(left));
			exp->set_operator(parser->current_token()->get_type());

			// Consume the operator token
			parser->consume();

			exp->set_type(parser->type_checker().get_expression_type(exp->get_expression()));

			if(parser->current_token()->get_type() == TokenType::Semicolon)
				parser->consume(TokenType::Semicolon);

			return std::move(exp);
		}
Esempio n. 30
0
void fncCall_syntax(int fncNbr) /* 함수 호출 검사 */
{
  int argCt = 0;

  code = nextCode(); code = chk_nextCode(code, '(');
  if (code.kind != ')') {                                       /* 인수가 있다 */
    for (;; code=nextCode()) {
      (void)get_expression(); ++argCt;                /* 인수식 처리와 인수 개수 */
      if (code.kind != ',') break;                     /* , 이면 인수가 계속된다 */
    }
  }
  code = chk_nextCode(code, ')');                                /* ) 일 것 */
  if (argCt != Gtable[fncNbr].args)                       /* 인수 개수 검사 */
    err_exit(Gtable[fncNbr].name, " 함수의 인수 개수가 잘못되었습니다");
  stk.push(1.0);                                          /* 적당한 반환 값 */
}