Lexicon is an interpreter for Sprout, a small programming language written in Go. It implements a full pipeline — lexer, parser, AST, and evaluator — and includes an interactive REPL for exploring expressions, variables, and control flow. The project is designed to teach core concepts of language design and interpreter implementation.
./run.sh./sprout./sprun filename.spr./sprun --trace filename.spr./sprun --debug filename.sprsprout> sprout x = 10;
sprout> sprout y = 20;
sprout> echo x + y;
30
sprout> trace on
Trace mode enabled!
sprout> help
- Lexer - Tokenizes Sprout source code with line/column tracking
- Parser - Builds Abstract Syntax Tree (AST) with error collection
- Interpreter - Executes Sprout programs with full error handling
- REPL - Interactive command-line interface with environment inspection
- Error Reporting - Detailed errors with line and column numbers
- Trace Execution - Step-by-step debugging mode
- Logging System - Internal state logging for debugging
- Documentation - Comprehensive guides for usage
sprout x = 10 # Integer
sprout pi = 3.14 # Float
sprout name = "Sprout" # String
sprout flag = true # Boolean
# With type annotations
sprout age int = 25
sprout price float = 19.99
- Arithmetic:
+-*/%** - Comparison:
<><=>===!= - Logical:
&&||!(orandornot)
if (x > 5) {
echo "Greater";
} else {
echo "Smaller";
}
# This is a comment
sprout x = 10; # Inline comment
help- Show help and language featuresenv- Show all variablesclear- Clear environmenttrace on- Enable trace executiontrace off- Disable trace executionexit- Quit REPL
Sprout provides detailed error messages with line and column information:
[Line 5:10] Expected next token to be =, got ; instead
ERROR [Line 3:5]: identifier not found: myVariable
ERROR: division by zero
ERROR: type mismatch: INTEGER + STRING
See step-by-step execution of your code:
./sprun --trace examples/examples.sprOutput:
[TRACE] Eval: *ast.Program
[TRACE] Eval: *ast.VariableDeclaration
[TRACE] VariableDeclaration: x
[TRACE] IntegerLiteral: 10
[TRACE] Set variable x = 10
In REPL, use env to see all variables:
sprout> env
Current environment variables:
x = 10
y = 20
Comprehensive documentation is available in the /docs directory:
- User Guide - Complete language docs
- Syntax - Sprout language syntax guide
- REPL - Guide for REPL
Lexicon/
├── cmd/
│ ├── repl/ # Interactive REPL
│ └── demo/ # File executor
├── src/
│ ├── token/ # Token definitions
│ ├── lexer/ # Lexical analyzer
│ ├── parser/ # Parser and AST
│ ├── ast/ # AST node definitions
│ ├── evaluator/ # Interpreter
│ └── logger/ # Logging system
├── docs/ # Documentation
├── examples/ # Example programs
go test ./src/lexer # Lexer tests
go test ./src/parser # Parser tests
go test ./src/evaluator # Evaluator tests
go test ./... # All tests- Saijyoti - @sxijyoti
- Yashmitha - @yashmithaa