A robust Java implementation of the Pangea programming language interpreter featuring an innovative annotation-driven architecture.
- ✅ Core interpreter functionality: Working and stable
- ✅ Reflection-based architecture: 80% robustness score
- ✅ Comprehensive error handling: Input validation and bounds checking
- ✅ Maven build system: JDK 17 ready
- ✅ Clean codebase: Well-organized and documented
- Java 17 or higher
- Maven 3.6+
# Clone and build
git clone <repository-url>
cd jova
mvn compile
# Run examples
java -cp target/classes pangea.PangeaMain examples/hello.pangea
java -cp target/classes pangea.PangeaMain examples/factorial_simple.pangea
# Or use Maven
mvn exec:java -Dexec.args="examples/hello.pangea"// Traditional manual registration (old way)
namespace.put("add", new FunctionEntry(2, "infix", this::addFunction));
namespace.put("print", new FunctionEntry(1, "prefix", this::printFunction));
// ... dozens more lines
// New annotation-driven approach
@PangeaFunction(names = {"add", "+"}, arity = 2, type = "infix")
private Value addFunc(List<Integer> params, Interpreter interp) {
// Implementation
}
@PangeaFunction(names = {"print"}, arity = 1)
private Value printFunc(List<Integer> params, Interpreter interp) {
// Implementation
}- 🎯 90% less registration code - Functions auto-register via annotations
- 🔍 Better discoverability - Function metadata co-located with implementation
- 🛡️ Type safety - Compile-time validation of function signatures
- 📚 Self-documenting - Annotation parameters describe function behavior
Pangea is a stack-based functional programming language with unique syntax:
- Function definitions with explicit arity declarations
- Infix, prefix, and postfix operators
- Block-based control structures
- Arrays and objects
- Recursive functions
- Iterator constructs
- Dynamic typing: Supports numbers, strings, booleans, arrays, and objects
- Function definitions:
def function_name#arity ( body ) - Conditional logic:
if condition then-branch else-branch - Loops:
times count ( block ),each iterable ( block ) - Operators: Arithmetic, comparison, and logical operators
- Comments: Lines starting with
#are comments
- All code must be wrapped in parentheses:
( ... ) - Strings use + for spaces:
"Hello+World!"becomes "Hello World!" - Function arity is explicit:
def factorial#1means 1 parameter - Arguments are 1-based:
arg 1,arg 2, etc. - No commas or semicolons: Space-separated tokens
- Postfix operators:
5 squared→ 25 - Infix operators:
3 + 4,5 > 2
print value- Output valuesarg index- Access function arguments (1-based indexing)times count block- Execute block count timeseach iterable block- Iterate over arrays/objectswhen condition value- Conditional executionunless condition block- Negative conditionaltimes_count depth- Get current iteration counteach_item- Get current item in each loopeach_key- Get current key in each loop
- Arithmetic:
+,-,*,%,**(exponentiation) - Comparison:
==,<,>,<= - Special:
squared(postfix),when(infix) - Logical: Truthy/falsy evaluation
- Java 11 or later
Use the provided build and run scripts:
# Build the project
./build.sh
# Run the main demo
./run.sh
# Run tests
./run.sh test
# Run a specific Pangea program
./run.sh examples/factorial.pangeaIf you have Maven installed, you can also use standard Maven commands:
# Compile the project
mvn compile
# Run the main program
mvn exec:java
# Run with arguments (example file)
mvn exec:java -Dexec.args="examples/factorial.pangea"
# Run tests
mvn test
# Create a JAR file
mvn package# Compile all sources
javac -d target/classes src/main/java/pangea/*.java
# Compile tests
javac -cp target/classes -d target/classes src/test/java/pangea/*.java
# Run main program
java -cp target/classes pangea.PangeaMain
# Run tests
java -cp target/classes pangea.SimpleTestjova/
├── src/
│ ├── main/java/pangea/ # Core interpreter source files
│ │ ├── Value.java # Value representation and operations
│ │ ├── Interpreter.java # Main interpreter logic
│ │ ├── FunctionEntry.java # Function definitions
│ │ ├── NativeFunction.java # Built-in functions
│ │ ├── StackFrame.java # Function call frames
│ │ ├── IterationFrame.java # Loop iteration context
│ │ └── PangeaMain.java # Main demo program
│ └── test/java/pangea/ # Test files
│ └── SimpleTest.java # Basic functionality tests
├── examples/ # Example Pangea programs
│ ├── factorial.pangea
│ ├── fizzbuzz.pangea
│ └── arrays_objects.pangea
├── target/classes/ # Compiled class files
├── build.sh # Build script
├── run.sh # Run script
├── pom.xml # Maven configuration
├── README.md
├── MIGRATION_SUMMARY.md
└── .gitignore
( print "Hello+from+file!" )
( def factorial#1
if ( arg 1 ) == 0
1
( arg 1 ) * factorial ( ( arg 1 ) - 1 )
print "Computing+factorial+of+5:"
print factorial 5 )
( def fizzbuzz#1
( arg 1 ) times (
print if ( times_count 1 ) % 15 == 0 "FizzBuzz"
if ( times_count 1 ) % 3 == 0 "Fizz"
if ( times_count 1 ) % 5 == 0 "Buzz"
times_count 1 )
print "FizzBuzz+from+1+to+20:"
fizzbuzz 20 )
( def greet#1
print "Hello+" + arg 1 + "!"
greet "World"
print "Basic+arithmetic:"
print 5 + 3
print 10 * 2
print "Array+example:"
print [ 1 2 3 4 5 ] )
( print "Array+iteration:"
[ "apple" "banana" "cherry" ] each (
print each_item
)
print "Object+example:"
print { "name" "Alice" "age" 30 "city" "New+York" }
print "Times+loop:"
5 times (
print times_count 1
) )
The examples/ directory contains several complete Pangea programs:
hello.pangea- Simple hello worldbasics.pangea- Basic operations and function definitionfactorial_simple.pangea- Recursive factorial functionfizzbuzz.pangea- Classic FizzBuzz implementationarrays_objects.pangea- Array and object manipulationadvanced.pangea- Complex functions and expressions
Run any example with:
./run.sh examples/filename.pangea
[ "apple" "banana" "cherry" ] each (
print each_item
)The Java implementation consists of:
- Value: Represents all Pangea data types using enums and type-safe accessors
- Interpreter: Main interpreter class with execution engine
- FunctionEntry: Function metadata and implementation storage
- StackFrame: Function call stack management
- IterationFrame: Iteration context management
- Parser: Converts source code into tokenized words
- Executor: Interprets and executes tokenized programs
- Namespace: Function and operator registry using HashMap
- Stack Management: Call stack for function parameters and iteration contexts
- Uses Java's automatic garbage collection
- ArrayList and HashMap for dynamic collections
- Stack-based execution model with proper cleanup
- Type Safety: Strong typing with compile-time checks
- Memory Management: Automatic garbage collection vs. manual management
- Performance: JVM optimization vs. interpreted execution
- Error Handling: Exception-based error handling
- Collections: Java Collections Framework vs. native JS arrays/objects
def function_name#arity ( body )
function_name arg1 arg2 ... argN
( expression1 expression2 ... ) # Parentheses block
[ item1 item2 ... ] # Array literal
{ "key1" value1 "key2" value2 } # Object literal
Spaces in strings are represented with +:
"hello+world" # Represents "hello world"
Special sequence (+) represents literal +:
"1(+)2=3" # Represents "1+2=3"
The Pangea interpreter features intelligent parsing that handles the dual use of the # symbol:
-
Function Arity Declaration:
functionName#arityfactorial#1- function named "factorial" with 1 parametergreet#2- function named "greet" with 2 parameters- The
#is part of the function identifier, NOT a comment
-
Comment Marker:
# comment text# This is a comment- entire line is a commentprint 42 # inline comment- everything after#is a comment
Critical Rule: If # is preceded by non-whitespace, it's part of a function name (NOT a comment).
# Examples of # usage:
def factorial#1 # ✓ factorial#1 = function name, # comment = comment
print arg 1 # ✓ Only this part is a comment
func#3 arg 1 arg 2 # ✓ func#3 = function name, rest = comment
The interpreter displays a words array showing all parsed tokens. This array contains ONLY meaningful code tokens - no whitespace characters (spaces, tabs, newlines) are included.
Example:
# Input file with comments and formatting:
# Factorial function example
(
def factorial#1 # Define function
if ( arg 1 ) == 0
1 # Base case
)
# Output tokens (words array):
[(, def, factorial#1, if, (, arg, 1, ), ==, 0, 1, )]
Key Points:
- Comments are completely stripped
- Indentation and formatting removed
- Function names like
factorial#1preserved as single tokens - Only meaningful code elements remain