UNPKG

mowascript

Version:

MowaScript language implementation

110 lines (83 loc) β€’ 2.58 kB
[[πŸŒ€ Interslavic](../../04_compiler.md) Β· [🌲 East Slavic](../east/04_compiler.md)] # πŸ› οΈ MowaJS Compiler Architecture The MowaJS compiler (or transpiler) converts code written in clear, Slavic-based syntax into valid JavaScript. It supports multilingual keywords, flexible configuration, syntax transformation, and can be run as a CLI tool or library. --- ## βš™οΈ Compiler Workflow ```text β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Input β”‚ (.mowa source code) β”‚ Code β”‚ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Lexer β”‚ (tokenizes input) β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Parser β”‚ (builds AST) β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Translator/Transformer β”‚ (transforms AST to JS AST) β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Generator β”‚ (outputs .js file) β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` The compiler is based on language-specific dictionaries: - Ukrainian (`ua.js`) - Belarusian (`by.js`) - Russian (`ru.js`) - Interslavic (`isv.js`) - ... and more During parsing, it compares words from the code against these dictionaries and automatically maps them to JS keywords or methods. ```json { "якщо": "if", "ΠΏΠΎΠΊΠΈ": "while", "додайДоРядка": { "target": "concat", "type": "string" } } ``` --- ## 🌲 Abstract Syntax Tree (AST) MowaJS builds an abstract syntax tree while respecting translations: ```js якщо (Π²Ρ–ΠΊ >= 18) { ΠΊΠ°ΠΆΠΈ("Дорослий"); } ``` Transforms to: ```js if (Π²Ρ–ΠΊ >= 18) { console.log("Дорослий"); } ``` --- ## πŸ”„ Transformation Steps Key stages: - Aliases β†’ JS keywords: `функція` β†’ `function` - Methods β†’ APIs: `govori()` β†’ `console.log()` - Logic β†’ Symbols: `Ρ–` β†’ `&&`, `Π°Π±ΠΎ` β†’ `||` - Dialect support: handled automatically via dictionary --- ## πŸ’‘ Features - βœ… Multi-syntax support - βœ… Custom dictionaries - βœ… CLI support: `mowa build`, `mowa run` - ⏳ Linting + syntax highlighting (planned) - ⏳ Web playground (in development) --- ## πŸš€ Future Plans - AST-based linting and autocomplete - Live in-browser editor - Integration with editors (VSCode, WebStorm) - Template preprocessor - Full TypeScript type support in Mowa