Skip to content

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

  • MPNumeral
  • UnicodeNumeral
  • RomanNumeral
  • ComplexNumeral
  • FractionNumeral
  • NumeralConverter

Key capabilities:

  • arithmetic across numeral scripts
  • conversion across scripts
  • Unicode fraction handling
  • scientific notation helpers

Keyword and Concept Model

  • KeywordRegistry
  • KeywordValidator

Key capabilities:

  • concept -> keyword lookup (COND_IF -> if, si, etc.)
  • keyword -> concept reverse lookup
  • supported-language discovery
  • ambiguity/completeness checks

Date and Time

  • MPDate
  • MPTime
  • MPDatetime

Key capabilities:

  • multilingual parsing and formatting
  • script-aware numeric rendering

Frontend (Lexing, Parsing, Semantic Analysis)

  • Lexer
  • Parser
  • AST node model in multilingualprogramming/parser/ast_nodes.py
  • SemanticAnalyzer
  • ASTPrinter

Key capabilities:

  • Unicode-aware tokenization
  • AST generation from multilingual source
  • scope and symbol checks
  • multilingual semantic error messages

Runtime and Execution

  • PythonCodeGenerator
  • RuntimeBuiltins
  • ProgramExecutor
  • REPL

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 with as)
  • assertions
  • exception handling (try, except, else, finally)
  • chained assignment
  • slices (a[1:3], a[::-1])
  • comprehensions (list, dict, generator), including nested for clauses
  • default parameters, *args, **kwargs
  • tuple unpacking
  • decorators
  • f-strings
  • triple-quoted strings

Example (nested comprehension):

let rows = [[1, 2], [3, 4]]
let flat = [x for row in rows for x in row]
print(flat)  # [1, 2, 3, 4]

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):

<LET> x = 2
<LET> y = 3
<PRINT>(x + y)

Snippet B (for loop):

<LET> total = 0
<FOR> i <IN> <RANGE_ALIAS>(4):
    total = total + i
<PRINT>(total)

Built-in aliases are also available for selected universal functions. Both the universal name and localized alias work. Example (French):

afficher(intervalle(4))
afficher(longueur([10, 20, 30]))
afficher(somme([1, 2, 3]))

Language-specific forms:

English (en)

let x = 2
let y = 3
print(x + y)

let total = 0
for i in range(4):
    total = total + i
print(total)

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)

sea x = 2
sea y = 3
imprimir(x + y)

sea suma = 0
para i en rango(4):
    suma = suma + i
imprimir(suma)

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)

मान x = 2
मान y = 3
छापो(x + y)

मान योग = 0
के_लिए i में परास(4):
    योग = योग + i
छापो(योग)

Arabic (ar)

ليكن x = 2
ليكن y = 3
اطبع(x + y)

ليكن المجموع = 0
لكل i في مدى(4):
    المجموع = المجموع + i
اطبع(المجموع)

Bengali (bn)

ধরি x = 2
ধরি y = 3
ছাপাও(x + y)

ধরি মোট = 0
জন্য i মধ্যে পরিসর(4):
    মোট = মোট + i
ছাপাও(মোট)

Tamil (ta)

இருக்கட்டும் x = 2
இருக்கட்டும் y = 3
அச்சிடு(x + y)

இருக்கட்டும் மொத்தம் = 0
ஒவ்வொரு i இல் வரம்பு(4):
    மொத்தம் = மொத்தம் + i
அச்சிடு(மொத்தம்)

Chinese (zh)

令 x = 2
令 y = 3
打印(x + y)

令 总计 = 0
对于 i 里 范围(4):
    总计 = 总计 + i
打印(总计)

Japanese (ja)

変数 x = 2
変数 y = 3
表示(x + y)

変数 合計 = 0
毎 i 中 範囲(4):
    合計 = 合計 + i
表示(合計)

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

python -m pytest -q
python -m pylint $(git ls-files '*.py')

License

  • Code: GPLv3+
  • Documentation/content: CC BY-SA 4.0