From 27e61471a89ca98021d9e0b6c9d92afacfd0025b Mon Sep 17 00:00:00 2001 From: Jacob Date: Sat, 25 Jan 2025 10:12:15 -0500 Subject: [PATCH] Fixed some things. --- src/grammar.y | 3 +++ src/lexer.c | 1 + test/validation/test.bats | 13 +++++++++++++ 3 files changed, 17 insertions(+) diff --git a/src/grammar.y b/src/grammar.y index df7ddcc..f3f6890 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -27,6 +27,8 @@ %token RGROUP %token SEP +%token EXPSEP + %token WORD %token NUM @@ -50,6 +52,7 @@ input: %empty | exp { root = $1; } + | input EXPSEP exp { root = $3; } ; diff --git a/src/lexer.c b/src/lexer.c index 6ac70cb..874a22d 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -112,6 +112,7 @@ int yylex() { case '(': return LGROUP; case ')': return RGROUP; case ',': return SEP; + case ';': return EXPSEP; default: fprintf(stderr, "Unexpected character: %c\n", c); } diff --git a/test/validation/test.bats b/test/validation/test.bats index 24ae0a0..313d21c 100644 --- a/test/validation/test.bats +++ b/test/validation/test.bats @@ -82,3 +82,16 @@ bin() { ./scl.out $1 | tail -n1; } run bin "-(-(1+2)*3)" [ "$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" ] +}