Fixed some things.

This commit is contained in:
Jacob Signorovitch 2025-01-25 10:12:15 -05:00
parent 8b01407374
commit 27e61471a8
3 changed files with 17 additions and 0 deletions

View File

@ -27,6 +27,8 @@
%token RGROUP %token RGROUP
%token SEP %token SEP
%token EXPSEP
%token<strval> WORD %token<strval> WORD
%token<fval> NUM %token<fval> NUM
@ -50,6 +52,7 @@
input: input:
%empty %empty
| exp { root = $1; } | exp { root = $1; }
| input EXPSEP exp { root = $3; }
; ;

View File

@ -112,6 +112,7 @@ int yylex() {
case '(': return LGROUP; case '(': return LGROUP;
case ')': return RGROUP; case ')': return RGROUP;
case ',': return SEP; case ',': return SEP;
case ';': return EXPSEP;
default: fprintf(stderr, "Unexpected character: %c\n", c); default: fprintf(stderr, "Unexpected character: %c\n", c);
} }

View File

@ -82,3 +82,16 @@ bin() { ./scl.out $1 | tail -n1; }
run bin "-(-(1+2)*3)" run bin "-(-(1+2)*3)"
[ "$output" = "= 9.000000" ] [ "$output" = "= 9.000000" ]
} }
@test "multiple expressions per line" {
run bin "1+1;2"
[ "$output" = "= 2.000000" ]
}
@test "variable definition" {
run bin "x = 1"
[ "$output" = "= 1.000000" ]
run bin "x = 1; x + 1"
[ "$output" = "= 2.000000" ]
}