You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
971 B
C

7 years ago
#include <parser.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
7 years ago
int s_put(interpreter *it)
7 years ago
{
char *s = igetarg_string(it, 0);
printf("%s\n", s);
return 0;
7 years ago
}
int s_type(interpreter *it)
{
variable *v = (variable *)it->stack[0];
switch (v->valtype) {
case STRING:
puts("string");
break;
case INTEGER:
puts("integer");
break;
case FLOAT:
puts("float");
break;
case FUNC:
puts("func");
break;
default:
puts("unknown");
break;
}
return 0;
}
int quit(interpreter *it)
{
(void)it;
exit(0);
return 0;
}
int main()
7 years ago
{
interpreter interp;
iinit(&interp);
inew_cfunc(&interp, "put", s_put);
inew_cfunc(&interp, "tp", s_type);
inew_cfunc(&interp, "q", quit);
7 years ago
char *line = 0;
unsigned int size;
int result;
while (1) {
printf("%d> ", interp.lnidx);
getline(&line, &size, stdin);
*strchr(line, '\n') = '\0';
result = idoline(&interp, line);
if (result != 0)
printf("Error: %d\n", result);
7 years ago
}
return 0;
}