multilingualprogramming Reference¶
This document is the detailed reference for the project.
Overview¶
multilingualprogramming is a Python framework for multilingual programming. It supports writing source code with keywords, numerals, and literals from multiple human languages while mapping everything to a shared semantic model.
Python compatibility baseline: - compatibility_matrix.md - compatibility_roadmap.md
Version and release status:
- Package version: multilingualprogramming/version.py
- Release notes: CHANGELOG.md
Supported Languages¶
- English
- French
- Spanish
- German
- Italian
- Portuguese
- Polish
- Dutch
- Swedish
- Danish
- Finnish
- Hindi
- Arabic
- Bengali
- Tamil
- Chinese (Simplified)
- Japanese
Core Components¶
Numeral System¶
MPNumeralUnicodeNumeralRomanNumeralComplexNumeralFractionNumeralNumeralConverter
Key capabilities:
- arithmetic across numeral scripts
- conversion across scripts
- Unicode fraction handling
- scientific notation helpers
Keyword and Concept Model¶
KeywordRegistryKeywordValidator
Key capabilities:
- concept -> keyword lookup (
COND_IF->if,si, etc.) - keyword -> concept reverse lookup
- supported-language discovery
- ambiguity/completeness checks
Date and Time¶
MPDateMPTimeMPDatetime
Key capabilities:
- multilingual parsing and formatting
- script-aware numeric rendering
Frontend (Lexing, Parsing, Semantic Analysis)¶
LexerParser- AST node model in
multilingualprogramming/parser/ast_nodes.py SemanticAnalyzerASTPrinter
Key capabilities:
- Unicode-aware tokenization
- AST generation from multilingual source
- scope and symbol checks
- multilingual semantic error messages
Runtime and Execution¶
PythonCodeGeneratorRuntimeBuiltinsProgramExecutorREPL
Key capabilities:
- transpile multilingual AST to Python source
- execute full pipeline: source -> tokens -> AST -> checks -> Python -> runtime
- inject multilingual runtime builtins
- interactive REPL with language switching and Python-preview mode
Language Features¶
The implementation includes support for:
- variable declarations and assignment
- booleans and
None, including identity checks (is,is not) - control flow (
if/else,for,while) - async constructs (
async def,await,async for,async with) - functions and classes
- imports (
import,from ... import ..., aliases withas) - assertions
- exception handling (
try,except,else,finally) - chained assignment
- slices (
a[1:3],a[::-1]) - comprehensions (list, dict, generator), including nested
forclauses - default parameters,
*args,**kwargs - tuple unpacking
- decorators
- f-strings
- triple-quoted strings
Example (nested comprehension):
Example (async for / async with):
import asyncio
class AsyncCtx:
async def __aenter__(self):
return 1
async def __aexit__(self, exc_type, exc, tb):
return False
async def main(xs):
let total = 0
async with AsyncCtx() as base:
async for i in xs:
total = total + i + base
return total
print(asyncio.run(main([1, 2, 3])))
API Entry Points¶
Most commonly used imports:
from multilingualprogramming import (
MPNumeral,
KeywordRegistry,
MPDate,
Lexer,
Parser,
SemanticAnalyzer,
ASTPrinter,
PythonCodeGenerator,
ProgramExecutor,
REPL,
)
CLI and REPL¶
Run interactive mode:
python -m multilingualprogramming repl
python -m multilingualprogramming repl --lang fr
python -m multilingualprogramming repl --show-python
python -m multilingualprogramming repl --show-wat
python -m multilingualprogramming repl --show-rust
REPL commands:
:help:language <code>:python— toggle generated Python display:wat— toggle generated WAT (WebAssembly Text) display:rust— toggle generated Rust/Wasmtime bridge code display:reset:kw [XX]:ops [XX]:q
REPL Language Smoke Tests¶
Use these two snippets to quickly validate each language in REPL.
Snippet A (variables + print):
Snippet B (for loop):
Built-in aliases are also available for selected universal functions. Both the universal name and localized alias work. Example (French):
Language-specific forms:
English (en)¶
French (fr)¶
soit x = 2
soit y = 3
afficher(x + y)
soit somme = 0
pour i dans intervalle(4):
somme = somme + i
afficher(somme)
Spanish (es)¶
German (de)¶
sei x = 2
sei y = 3
ausgeben(x + y)
sei summe = 0
für i in bereich(4):
summe = summe + i
ausgeben(summe)
Italian (it)¶
sia x = 2
sia y = 3
stampa(x + y)
sia totale = 0
per i in intervallo(4):
totale = totale + i
stampa(totale)
Portuguese (pt)¶
seja x = 2
seja y = 3
imprimir(x + y)
seja soma = 0
para i em intervalo(4):
soma = soma + i
imprimir(soma)
Hindi (hi)¶
Arabic (ar)¶
ليكن x = 2
ليكن y = 3
اطبع(x + y)
ليكن المجموع = 0
لكل i في مدى(4):
المجموع = المجموع + i
اطبع(المجموع)
Bengali (bn)¶
Tamil (ta)¶
இருக்கட்டும் x = 2
இருக்கட்டும் y = 3
அச்சிடு(x + y)
இருக்கட்டும் மொத்தம் = 0
ஒவ்வொரு i இல் வரம்பு(4):
மொத்தம் = மொத்தம் + i
அச்சிடு(மொத்தம்)
Chinese (zh)¶
Japanese (ja)¶
Examples¶
Runnable examples are documented in:
Complete feature coverage examples:
examples/complete_features_*.ml(one file per supported language)
Run:
python -m multilingualprogramming run examples/complete_features_en.ml --lang en
python -m multilingualprogramming run examples/complete_features_fr.ml --lang fr
python -m multilingualprogramming run examples/complete_features_es.ml --lang es
Run all examples from repository root:
python -m examples.arithmetic
python -m examples.numeral_extended
python -m examples.keywords
python -m examples.datetime_example
python -m examples.lexer_example
python -m examples.parser_example
python -m examples.ast_example
python -m examples.multilingual_parser_example
python -m examples.codegen_example
python -m examples.multilingual_codegen_example
python -m examples.semantic_example
python -m examples.executor_example
Development¶
Related Docs¶
- Project quick start: README.md
- Design overview: design.md
- Core formal specification: core_spec.md
- Frontend translation contracts: frontend_contracts.md
- Related work and differentiation: related_work.md
- Controlled language scope: cnl_scope.md
- Evaluation plan: evaluation_plan.md
- Word order and syntax naturalness: word_order_and_naturalness.md
- Standard library localization strategy: stdlib_localization.md
- Translation governance: translation_guidelines.md
- Development and debugging guide: development.md
- Python compatibility matrix: compatibility_matrix.md
- Python 3.12 compatibility roadmap: compatibility_roadmap.md
- Usage snippets: USAGE.md
- Examples guide: examples/README.md
- French programming guide: fr/programmation.md
- Language onboarding: language_onboarding.md
License¶
- Code: GPLv3+
- Documentation/content: CC BY-SA 4.0