# gikaellero/mario-compiler architecture

> Architecture diagram of the GitHub repository gikaellero/mario-compiler, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gikaellero/mario-compiler
- Repository: https://github.com/gikaellero/mario-compiler

## Overview

This is a small ANTLR-based translator for a Mario-themed programming language. The principal workflow reads source from standard input, parses it, selects a Java or C++ listener from the command-line argument, and emits translated code. The listeners also validate declarations, assignments, types, and scope while translating constructs such as conditionals, loops, input, and output. The grammar is present in the tree, but generated lexer/parser sources are not. Edges reflect the shown compiler calls, listener behavior, and README usage; unsampled grammar details are not inferred.

Main entry points: [`Compilador.java`](https://github.com/gikaellero/mario-compiler/blob/main/Compilador.java) (Compiler entry), [`Tradutor.java`](https://github.com/gikaellero/mario-compiler/blob/main/Tradutor.java) (Java translator), [`TradutorC.java`](https://github.com/gikaellero/mario-compiler/blob/main/TradutorC.java) (C++ translator), [`atribuicao.g4`](https://github.com/gikaellero/mario-compiler/blob/main/atribuicao.g4) (Language grammar)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_front["Parsing and dispatch"]
  node_compiler["Compiler entry<br/>[Compilador.java]"]
  node_grammar["Language grammar<br/>[atribuicao.g4]"]
  node_antlr["ANTLR runtime"]
end

subgraph group_translation["Target translation"]
  node_java["Java translator<br/>[Tradutor.java]"]
  node_cpp["C++ translator<br/>[TradutorC.java]"]
end

subgraph group_validation["Semantic checks"]
  node_java_checks["Java semantic checks<br/>[Tradutor.java]"]
  node_cpp_checks["C++ semantic checks<br/>[TradutorC.java]"]
end

node_user(("Source author"))
node_stdout["Generated code"]

node_user -->|"provides source"| node_compiler
node_compiler -->|"creates lexer parser"| node_antlr
node_compiler -.->|"parses language"| node_grammar
node_compiler -->|"selects Java"| node_java
node_compiler -->|"selects C++"| node_cpp
node_java -->|"checks types"| node_java_checks
node_cpp -->|"checks types"| node_cpp_checks
node_java -->|"prints Java code"| node_stdout
node_cpp -->|"prints C++ code"| node_stdout

click node_compiler "https://github.com/gikaellero/mario-compiler/blob/main/Compilador.java"
click node_grammar "https://github.com/gikaellero/mario-compiler/blob/main/atribuicao.g4"
click node_java "https://github.com/gikaellero/mario-compiler/blob/main/Tradutor.java"
click node_cpp "https://github.com/gikaellero/mario-compiler/blob/main/TradutorC.java"
click node_java_checks "https://github.com/gikaellero/mario-compiler/blob/main/Tradutor.java"
click node_cpp_checks "https://github.com/gikaellero/mario-compiler/blob/main/TradutorC.java"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_compiler,node_grammar,node_antlr toneBlue
class node_java,node_cpp toneAmber
class node_java_checks,node_cpp_checks toneMint
class node_user,node_stdout toneIndigo
```

## Components

### Parsing and dispatch

- [Compiler entry](https://github.com/gikaellero/mario-compiler/blob/main/Compilador.java): `Compilador.java`
- [Language grammar](https://github.com/gikaellero/mario-compiler/blob/main/atribuicao.g4): `atribuicao.g4`
- **ANTLR runtime**

### Target translation

- [Java translator](https://github.com/gikaellero/mario-compiler/blob/main/Tradutor.java): `Tradutor.java`
- [C++ translator](https://github.com/gikaellero/mario-compiler/blob/main/TradutorC.java): `TradutorC.java`

### Semantic checks

- [Java semantic checks](https://github.com/gikaellero/mario-compiler/blob/main/Tradutor.java): `Tradutor.java`
- [C++ semantic checks](https://github.com/gikaellero/mario-compiler/blob/main/TradutorC.java): `TradutorC.java`

### Other components

- **Source author**
- **Generated code**

## Connections

- Source author → Compiler entry: provides source (evidence: `readme.txt`)
- Compiler entry → ANTLR runtime: creates lexer parser (evidence: `Compilador.java`)
- Compiler entry → Language grammar: parses language
- Compiler entry → Java translator: selects Java (evidence: `Compilador.java`)
- Compiler entry → C++ translator: selects C++ (evidence: `Compilador.java`)
- Java translator → Java semantic checks: checks types (evidence: `Tradutor.java`)
- C++ translator → C++ semantic checks: checks types (evidence: `TradutorC.java`)
- Java translator → Generated code: prints Java code (evidence: `Tradutor.java`)
- C++ translator → Generated code: prints C++ code (evidence: `TradutorC.java`)
