--- /dev/null
+go = 1
+while (go == 1) {
+ print("> ")
+ input = gets()
+ answer = solve(input)
+ if (answer == 42) {
+ go = 0
+ }
+ print("\n")
+ print(answer)
+ print("\n")
+}
else if (a->type == STRING && b->type == STRING)
r->value.f = !strcmp((const char *)a->value.p, (const char *)b->value.p);
else
- return seterror(EBADPARAM);
+ r->value.f = 0.0f; // *sshhh*
+ //return seterror(EBADPARAM);
return 0;
}
}
free(it->lines);
- free(it->vars);
- for (uint32_t i = 0; i < MAX_VARS; i++)
+ for (uint32_t i = 0; i < MAX_VARS; i++) {
+ if (it->vars[i].type == STRING)
+ free((void *)it->vars[i].value.p);
free(it->names[i]);
+ }
+ free(it->vars);
free(it->names);
free(it->stack);
v->value.p = (uint32_t)strclone(s);
}
-int idoline(instance *it, const char *s)
+int iaddline(instance *it, const char *s)
{
variable **ops = iparse(it, s);
if (ops == 0)
return 0;
it->lines[it->lnidx] = ops;
+ it->lnidx++;
+ return 0;
+}
+int irun(instance *it)
+{
variable **copy;
+ it->lnidx = 0;
loop:
//if (it->ret != 0)
// itryfree(it->ret);
variable *ret = igetvar(it, "ANS");
ret->type = it->ret->type;
ret->value.p = it->ret->value.p;
+ itryfree(it->ret);
it->ret = ret;
}
void idelinstance(instance *it);
/**
- * Adds and runs the line through the parser instance.
- * This parses and runs the line, while storing it at the current line index.
- * @param it the current instance
- * @param s the line to parse/run
+ * Parses the given line of script, and adds it to the end of the instance's
+ * stored script.
+ * @param it the instance to use
+ * @param s the line to load
+ * @return zero for success, otherwise error
+ */
+int iaddline(instance *it, const char *s);
+
+/**
+ * Runs the instance with its loaded script until there's nothing more to run.
+ * @param the instance to use
+ * @return an error code, or zero if success
*/
-int idoline(instance *it, const char *s);
+int irun(instance *it);
/**
* Makes a C function visible to the script.
*/
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "parser.h"
return 0;
}
+int gets(instance *it)
+{
+ char *line = 0;
+ size_t size;
+ getline(&line, &size, stdin);
+ *strchr(line, '\n') = '\0';
+ variable *v = make_vars(0, line);
+ free(line);
+ ipush(it, (uint32_t)v);
+ return 0;
+}
+
int main(int argc, char **argv)
{
if (argc != 2) {
instance *it = inewinstance();
inew_cfunc(it, "print", print);
+ inew_cfunc(it, "gets", gets);
char *line = 0;
size_t size;
int result;
while (getline(&line, &size, fp) != -1) {
*strchr(line, '\n') = '\0';
- result = idoline(it, line);
+ result = iaddline(it, line);
if (result != 0)
printf("Error: %d\n", result);
- //if (it->ret != 0)
- // printf("%s = %f\n", line, it->ret->value.f);
}
-
+ free(line);
fclose(fp);
+
+ irun(it);
idelinstance(it);
return 0;
}
}
}
-checka
+checka()
print("Increment a...")
a = a + 1
-checka
+checka()
d = 0
while (d < 20) {