म
MarathiCodeby Sprout Tech
Documentation topicsArchitecture
MarathiCode v0.2.0

Architecture

भाषा प्रक्रिया रचना

MarathiCode is a formal programming language with an AST-based interpreter. A program passes through these stages:

pipeline.txt
Marathi source (.mr, UTF-8)
        ↓
      Lexer        → tokens
        ↓
      Parser       → abstract syntax tree (AST)
        ↓
    Interpreter    → walks the tree, using scope environments
        ↓
      Output
StageWhat it does
LexerMatches keywords, Devanagari/ASCII identifiers, numbers (both digit sets), strings, operators and comments; reports invalid characters with line and column.
ParserApplies the grammar and operator precedence, builds the AST, and reports syntax errors with a ^ marker.
ASTA tree of nodes such as Assignment, Print, If, While, For, FunctionDef, FunctionCall, Return, BinaryOp, ListIndex and ListAssign.
InterpreterExecutes statements in order, evaluates expressions, keeps a chain of scope environments (global → function → block) and a function table, and raises runtime errors.

Example

The statement चल x = 10 + 20 * 3 is turned into this tree, with multiplication nested below addition:

ast.txt
Assign(var x,
  BinaryOp(+,
    Number(10),
    BinaryOp(*, Number(20), Number(3))))

Two implementations, one language

The command-line interpreter is written in Python, with an LALR(1) parser built using the PLY library. The Playground uses a TypeScript implementation of the same lexer, parser and interpreter that runs directly in the browser. Both are checked against the same set of MarathiCode test programs, which compare output and error messages.

Design choices

  • Marathi keywords and Devanagari identifiers, so programs can be written entirely in Marathi.
  • Conventional structure: variables, if/else, while and for loops, functions, recursion and lists work as in widely used languages.
  • Brace-delimited blocks give explicit, unambiguous block boundaries without relying on indentation.
  • AST-based interpretation keeps execution inspectable: each stage has a clear input and output.
  • Localized errors report problems in Marathi with the exact line.