compiler-poop
v1.0.0
Published
A simple compiler for the AJJScript language that translates source code to JavaScript.
Downloads
12
Readme
AJJScript Compiler
A simple compiler for the AJJScript language that translates source code to JavaScript.
Components
The compiler consists of three main components:
- Lexer: Tokenizes the source code into a stream of tokens
- Parser: Converts tokens into an Abstract Syntax Tree (AST)
- Code Generator: Translates the AST into executable JavaScript code
Code Generator
The code generator is responsible for translating the AST (Intermediate Representation) into JavaScript code. It handles:
- Class definitions with inheritance
- Control flow constructs (if, while)
- Function calls
- Variable bindings
- Basic arithmetic and logical operations
Usage
const { compile } = require('./src');
// Example AJJScript code
const sourceCode = `
class Person {
string name;
init(string name) {
this.name = name;
}
method sayHello() void {
println("Hello, " + this.name);
}
}
Person p = new Person("World");
p.sayHello();
`;
// Compile to JavaScript
const jsCode = compile(sourceCode);
console.log(jsCode);
// Execute the generated code
eval(jsCode);Running Tests
npm testProject Structure
src/lexer/: Contains tokenizer and token definitionsparser/: Contains parser and AST node definitionscodeGenerator/: Contains code generation logictests/: Contains unit testsindex.js: Main entry point
License
ISC License
