Alia 编译解释器(JS版本)
- JavaScript 99.8%
- C 0.2%
| Analyzer | ||
| ASTifier | ||
| Checker | ||
| Compiler | ||
| Debug | ||
| ErrorHandler | ||
| Formatter | ||
| Interpreter | ||
| Language | ||
| Shell | ||
| Tests | ||
| .gitignore | ||
| index.js | ||
| package.json | ||
| README.md | ||
| TEST_MODE_GUIDE.md | ||
Alia Language System
This is a refactored implementation of the Alia programming language, organized into clear modules for AST parsing, interpretation, compilation, and formatting.
Architecture
The system is divided into four main components:
ASTifier
- Tokenize: Lexical analysis, converting source code to tokens.
- ExpressionParser: Parsing expressions into AST nodes.
- Types: AST node definitions (Program, Statement, Expression, etc.).
- Aliases: Utilities for handling alias definitions and pattern matching.
Interpreter
- Runtime: Execution engine that interprets the AST.
- CoreExts: Built-in methods and extensions for core types.
Compiler
- Translates Alia AST to target languages.
Formatter
- Pretty-prints Alia code from AST.
Key Design Decisions
-
Clear AST Structure: The parser builds a comprehensive AST that includes all language constructs. Alias definitions are registered during parsing but stored in the AST for the interpreter to execute.
-
Separation of Concerns:
- Parser (ASTifier): Only parses and builds AST, registers aliases in a parsing-time registry.
- Interpreter: Executes AST nodes directly, no pattern matching for aliases.
- Compiler: Generates code from AST.
- Formatter: Formats AST back to code.
-
Stack-Based Execution: The core execution model is based on executing Stack objects, which contain sequences of statements.
Usage
const Alia = require('./index.js');
const alia = new Alia();
// Parse code to AST
const ast = alia.parse('let x = 5; x = x + 1;');
// Interpret AST
alia.interpret('let x = 5; x = x + 1;');
// Compile to JavaScript
const jsCode = alia.compile('let x = 5;', 'js');
// Format AST
const formatted = alia.format('let x=5;');
Directory Structure
bootstrap/Uildod(JS)/
├── Astify/
│ ├── Tokenize/index.js
│ ├── ExpressionParser/index.js
│ ├── Types/index.js
│ └── Aliases/index.js
├── Interpreter/
│ ├── Runtime/index.js
│ └── CoreExts/index.js
├── Compiler/index.js
├── Formatter/index.js
└── index.js