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
|
#endif
|
||||||
// int statements = 0;
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int parens = 0;
|
int parens = 0;
|
||||||
Object obj;
|
Object obj;
|
||||||
struct Slice *tok = tokens;
|
struct Slice *tok = tokens;
|
||||||
while(tok[i].text != NULL) {
|
while(tok[i].text != NULL) {
|
||||||
//printf("tok[%d].text[0]: '%c'\n", i, tok[i].text[0]);
|
|
||||||
if(tok[i].text[0] == '(') {
|
if(tok[i].text[0] == '(') {
|
||||||
parens++;
|
parens++;
|
||||||
} else if(tok[i].text[0] == ')') {
|
} else if(tok[i].text[0] == ')') {
|
||||||
|
@ -366,18 +364,11 @@ Object parseEval(const char *input, struct Environment *env)
|
||||||
tok = &tok[i + 1];
|
tok = &tok[i + 1];
|
||||||
i = -1;
|
i = -1;
|
||||||
obj = eval(&parsed, env);
|
obj = eval(&parsed, env);
|
||||||
//printf("End statement:\n");
|
|
||||||
//printObj(&obj);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
// for(int i = 0; i < statements; i++) {
|
|
||||||
// Object parsed = parse(tokens).obj;
|
|
||||||
// }
|
|
||||||
// Object parsed = parse(tokens).obj;
|
|
||||||
free(tokens);
|
free(tokens);
|
||||||
// return eval(&parsed, env);
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,9 +389,15 @@ int repl(struct Environment *env)
|
||||||
int main(int argc, const char* argv[])
|
int main(int argc, const char* argv[])
|
||||||
{
|
{
|
||||||
struct Environment env = defaultEnv();
|
struct Environment env = defaultEnv();
|
||||||
if(argc == 2) {
|
if(argc >= 2) {
|
||||||
Object r = parseEval(argv[1], &env);
|
Object r = numberObject(0);
|
||||||
printAndClean(&r);
|
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 {
|
} else {
|
||||||
#ifndef NO_REPL
|
#ifndef NO_REPL
|
||||||
repl(&env);
|
repl(&env);
|
||||||
|
@ -411,6 +408,6 @@ int main(int argc, const char* argv[])
|
||||||
printAndClean(&r);
|
printAndClean(&r);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
deleteEnv(&env);
|
// deleteEnv(&env);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -54,6 +54,9 @@ check "WideSpac" "( + 1093 102852 )" "103945"
|
||||||
check "VWidwSpc" " ( + 1093 102852 ) " "103945"
|
check "VWidwSpc" " ( + 1093 102852 ) " "103945"
|
||||||
echo ""
|
echo ""
|
||||||
check "DemoFunc" "(spent 68)" "Tip: \$13.60"
|
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 ""
|
echo ""
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue