No description
  • C 97.6%
  • Makefile 2.4%
Find a file
2026-10-17 15:24:25 +08:00
include initial commit 2026-10-17 15:24:25 +08:00
src initial commit 2026-10-17 15:24:25 +08:00
tests initial commit 2026-10-17 15:24:25 +08:00
.gitignore initial commit 2026-10-17 15:24:25 +08:00
Makefile initial commit 2026-10-17 15:24:25 +08:00
README.md initial commit 2026-10-17 15:24:25 +08:00

Samp

Samp is a deliberately small arithmetic language in C. The implementation is split by responsibility so language features do not become coupled to the CLI.

source -> lexer -> parser -> AST -> evaluator -> output
                           \-> environment

Layout

  • src/lexer.c: converts source text into tokens.
  • src/parser.c: recursive-descent parser that produces an AST.
  • src/ast.c: AST construction, ownership, and cleanup.
  • src/evaluator.c: executes AST nodes without parser dependencies.
  • src/environment.c: dynamically growing hash table for variables.
  • src/interpreter.c: small facade that composes parsing and evaluation.
  • src/main.c: file/REPL user interface only.
  • tests/: automated interpreter-level tests.

Build, test, run

make -C samp
make -C samp test
./samp/bin/samp

Run a source file with ./samp/bin/samp program.samp.

// program.samp
let price = 19.95;
let quantity = 3;
print(price * quantity);
print((2 + 3) * 4);

Statements end in ;. Supported expressions use numbers, variables, parentheses, and +, -, *, / operators.

Adding a feature

For a new construct such as if, add its token(s), AST node type, parser branch, and evaluator branch. This keeps syntax, representation, and runtime behavior separately testable.