Multi-statements in cmdline args. Added tests.
Commented out unnecessary deleteEnv() in main(). Was segfaulting. May be a bigger bug, there.
This commit is contained in:
parent
340af00a29
commit
60d6022d46
|
@ -350,13 +350,11 @@ Object parseEval(const char *input, struct Environment *env)
|
|||
}
|
||||
}
|
||||
#endif
|
||||
// int statements = 0;
|
||||
int i = 0;
|
||||
int parens = 0;
|
||||
Object obj;
|
||||
struct Slice *tok = tokens;
|
||||
while(tok[i].text != NULL) {
|
||||
//printf("tok[%d].text[0]: '%c'\n", i, tok[i].text[0]);
|
||||
if(tok[i].text[0] == '(') {
|
||||
parens++;
|
||||
} else if(tok[i].text[0] == ')') {
|
||||
|
@ -366,18 +364,11 @@ Object parseEval(const char *input, struct Environment *env)
|
|||
tok = &tok[i + 1];
|
||||
i = -1;
|
||||
obj = eval(&parsed, env);
|
||||
//printf("End statement:\n");
|
||||
//printObj(&obj);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
// for(int i = 0; i < statements; i++) {
|
||||
// Object parsed = parse(tokens).obj;
|
||||
// }
|
||||
// Object parsed = parse(tokens).obj;
|
||||
free(tokens);
|
||||
// return eval(&parsed, env);
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
@ -398,9 +389,15 @@ int repl(struct Environment *env)
|
|||
int main(int argc, const char* argv[])
|
||||
{
|
||||
struct Environment env = defaultEnv();
|
||||
if(argc == 2) {
|
||||
Object r = parseEval(argv[1], &env);
|
||||
printAndClean(&r);
|
||||
if(argc >= 2) {
|
||||
Object r = numberObject(0);
|
||||
for(int i = 1; i < argc; i++) {
|
||||
// cleanObject(&r);
|
||||
r = parseEval(argv[i], &env);
|
||||
}
|
||||
printObj(&r);
|
||||
// Object r = parseEval(argv[1], &env);
|
||||
// printAndClean(&r);
|
||||
} else {
|
||||
#ifndef NO_REPL
|
||||
repl(&env);
|
||||
|
@ -411,6 +408,6 @@ int main(int argc, const char* argv[])
|
|||
printAndClean(&r);
|
||||
#endif
|
||||
}
|
||||
deleteEnv(&env);
|
||||
// deleteEnv(&env);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -54,6 +54,9 @@ check "WideSpac" "( + 1093 102852 )" "103945"
|
|||
check "VWidwSpc" " ( + 1093 102852 ) " "103945"
|
||||
echo ""
|
||||
check "DemoFunc" "(spent 68)" "Tip: \$13.60"
|
||||
echo ""
|
||||
check "MultStmt" "(def yee (fn (a) (* 10 a))) (yee 5)" "50"
|
||||
check "DefinMap" "(def yee (fn (a) (* 10 a))) (map yee (5 10 2 (+ 12 0)))" "( 50 100 20 120 )"
|
||||
|
||||
echo ""
|
||||
|
||||
|
|
Loading…
Reference in New Issue