**
** For the latest info, see http://code.google.com/p/my-basic/
**
-** Copyright (c) 2011 - 2013 Tony & Tony's Toy Game Development Team
+** Copyright (c) 2011 - 2014 paladin_t
**
** Permission is hereby granted, free of charge, to any person obtaining a copy of
** this software and associated documentation files (the "Software"), to deal in
/** Macros */
#define _VER_MAJOR 1
#define _VER_MINOR 0
-#define _VER_REVISION 37
+#define _VER_REVISION 40
#define _MB_VERSION ((_VER_MAJOR * 0x01000000) + (_VER_MINOR * 0x00010000) + (_VER_REVISION))
-#define _MB_VERSION_STRING "1.0.0037"
+#define _MB_VERSION_STRING "1.0.0040"
/* Uncomment this line to treat warnings as error */
/*#define _WARING_AS_ERROR*/
"Integer expected",
"ELSE statement expected",
"TO statement expected",
+ "NEXT statement expected",
"UNTIL statement expected",
"Loop variable expected",
"Jump label expected",
+ "Variable expected",
"Invalid identifier usage",
"Calculation error",
"Divide by zero",
+ "MOD by zero",
"Invalid expression",
"Out of memory",
/** Extended abort */
val->data.integer = strcmp(_str1, _str2) __optr 0; \
} while(0)
-#define _proc_div_by_zero(__s, __tuple, __exit, __result) \
+#define _proc_div_by_zero(__s, __tuple, __exit, __result, __kind) \
do { \
_object_t opndv1; \
_object_t opndv2; \
val->type = _DT_REAL; \
val->data.integer = _FINF; \
} \
- _handle_error_on_obj((__s), SE_RN_DIVIDE_BY_ZERO, ((__tuple) && *(__tuple)) ? ((_object_t*)(((_tuple3_t*)(*(__tuple)))->e1)) : 0, MB_FUNC_WARNING, __exit, __result); \
+ _handle_error_on_obj((__s), __kind, ((__tuple) && *(__tuple)) ? ((_object_t*)(((_tuple3_t*)(*(__tuple)))->e1)) : 0, MB_FUNC_WARNING, __exit, __result); \
} \
} while(0)
/* Set current error information */
mb_assert(s && err >= 0 && err < _countof(_ERR_DESC));
- s->last_error = err;
+ if(s->last_error == SE_NO_ERR) {
+ s->last_error = err;
+ }
}
const char* _get_error_desc(mb_error_e err) {
return result;
}
+int mb_gets(char* buf, int s) {
+ /* Safe stdin reader function */
+ int result = 0;
+ if(fgets(buf, s, stdin) == 0) {
+ fprintf(stderr, "Error reading.\n");
+ exit(1);
+ }
+ result = (int)strlen(buf);
+ if(buf[result - 1] == '\n')
+ buf[result - 1] = '\0';
+
+ return result;
+}
+
/* ========================================================} */
/*
mb_assert(s && l);
- _proc_div_by_zero(s, l, _exit, result);
+ _proc_div_by_zero(s, l, _exit, result, SE_RN_DIVIDE_BY_ZERO);
_instruct_num_op_num(/, l);
_exit:
mb_assert(s && l);
+ _proc_div_by_zero(s, l, _exit, result, SE_RN_MOD_BY_ZERO);
_instruct_int_op_int(%, l);
+_exit:
return result;
}
goto _exit;
}
+ if(!ast) {
+ _handle_error_on_obj(s, SE_RN_NEXT_EXPECTED, DON(ast), MB_FUNC_ERR, _exit, result);
+ }
obj = (_object_t*)(ast->data);
}
ast = (_ls_node_t*)(*l);
obj = (_object_t*)(ast->data);
+ if(!obj || obj->type != _DT_VAR) {
+ _handle_error_on_obj(s, SE_RN_VARIABLE_EXPECTED, DON(ast), MB_FUNC_ERR, _exit, result);
+ }
if(obj->data.variable->data->type == _DT_INT || obj->data.variable->data->type == _DT_REAL) {
- gets(line);
+ mb_gets(line, sizeof(line));
obj->data.variable->data->type = _DT_INT;
obj->data.variable->data->data.integer = (int_t)strtol(line, &conv_suc, 0);
if(*conv_suc != '\0') {
}
obj->data.variable->data->data.string = (char*)mb_malloc(256);
memset(obj->data.variable->data->data.string, 0, 256);
- gets(line);
+ mb_gets(line, sizeof(line));
strcpy(obj->data.variable->data->data.string, line);
} else {
result = MB_FUNC_ERR;
**
** For the latest info, see http://code.google.com/p/my-basic/
**
-** Copyright (c) 2011 - 2013 Tony & Tony's Toy Game Development Team
+** Copyright (c) 2011 - 2014 paladin_t
**
** Permission is hereby granted, free of charge, to any person obtaining a copy of
** this software and associated documentation files (the "Software"), to deal in
SE_RN_INTEGER_EXPECTED,
SE_RN_ELSE_EXPECTED,
SE_RN_TO_EXPECTED,
+ SE_RN_NEXT_EXPECTED,
SE_RN_UNTIL_EXPECTED,
SE_RN_LOOP_VAR_EXPECTED,
SE_RN_JUMP_LABEL_EXPECTED,
+ SE_RN_VARIABLE_EXPECTED,
SE_RN_INVALID_ID_USAGE,
SE_RN_CALCULATION_ERROR,
SE_RN_DIVIDE_BY_ZERO,
+ SE_RN_MOD_BY_ZERO,
SE_RN_INVALID_EXPRESSION,
SE_RN_OUT_OF_MEMORY,
/** Extended abort */
MBAPI int mb_set_error_handler(mb_interpreter_t* s, mb_error_handler_t h);
MBAPI int mb_set_printer(mb_interpreter_t* s, mb_print_func_t p);
+MBAPI int mb_gets(char* buf, int s);
+
#ifdef MB_COMPACT_MODE
# pragma pack()
#endif /* MB_COMPACT_MODE */