# ArnoldC

> Programming language based on the one-liners of Arnold Schwarzenegger.

**Showcase URL:** https://shipdocs.sh/showcase/1a5330cf-72e7-43f1-a8f6-2d3dcf4ce623
**Repository:** https://github.com/lhartikk/ArnoldC
**Docs count:** 4

## Overview

# Project Overview

This project implements a programming language inspired by the one-liners of Arnold Schwarzenegger. It parses code written in this language and generates Java bytecode that can be executed.

## Tech Stack

*   **Scala**: The primary programming language.
*   **ASM**: A Java bytecode manipulation framework used for generating `.class` files.
*   **Parboiled-scala**: A library for writing parsers.
*   **ScalaTest**: A testing framework.
*   **FreeTTS**: A speech synthesis library, likely for the `-declaim` option.

## High-Level Architecture

The project follows a typical compiler structure:

1.  **Parser (`ArnoldParser`)**: Takes the ArnoldC source code as input and transforms it into an Abstract Syntax Tree (AST). The AST is composed of various `AstNode` implementations, such as `StatementNode`, `ExpressionNode`, and `OperandNode`.
2.  **AST (`org.arnoldc.ast.*`)**: Represents the structure of the parsed ArnoldC code. Nodes like `PrintNode`, `AssignVariableNode`, `MethodNode`, and `MainMethodNode` define the language's constructs.
3.  **Code Generator (`ArnoldGenerator`, `ArnoldParser`)**: Traverses the AST and generates Java bytecode using the ASM library. The `generate` methods within each `AstNode` are responsible for emitting the appropriate bytecode instructions.
4.  **Class Loader (`ArnoldGenerator`, `ByteCodeExecutor`)**: Loads the generated bytecode as a Java class.
5.  **Executor (`Executor`)**: Runs the compiled Java class, specifically executing its `main` method.
6.  **Declaimer (`Declaimer` - not fully shown, but referenced)**: Likely processes the AST to produce a human-readable representation or perform some analysis.

## Entry Points

*   **`org.arnoldc.ArnoldC.main(args: Array[String])`**: This is the main entry point for the command-line interface. It handles parsing command-line arguments (like `-run` or `-declaim`), reading the ArnoldC source file, invoking the `ArnoldGenerator` to produce bytecode, writing the `.class` file, and then either executing the compiled code via `Executor` or processing it with `Declaimer`.
*   **`org.arnoldc.ArnoldGenerator.generate(arnoldCode: String, filename: String)`**: This method orchestrates the parsing and bytecode generation process. It creates an `ArnoldParser` instance, parses the code into an `RootNode` (the root of the AST), and then calls the `generateByteCode` method on the `RootNode`.
*   **`org.arnoldc.Executor.execute(className: String)`**: This method is responsible for loading and running the generated Java bytecode. It uses a custom `ClassLoader` to load the class and then invokes its `main` method.

The typical flow for running an ArnoldC program is: `ArnoldC` reads the source file -> `ArnoldParser` builds AST -> `ArnoldGenerator` generates bytecode -> `FileOutputStream` writes `.class` file -> `Executor` loads and runs the `.class` file.

## Key Concepts

1.  **Abstract Syntax Tree (AST)**: The core data structure representing the parsed ArnoldC code. Developers need to understand how different language constructs are mapped to `AstNode` subclasses (e.g., `PrintNode` for `TALK TO THE HAND`, `AssignVariableNode` for `GET TO THE CHOPPER`).
    *   Refer to: `src/main/scala/org/arnoldc/ast/AstNode.scala` and its subclasses.
2.  **Bytecode Generation**: The process of translating AST nodes into Java bytecode instructions using the ASM library. Each `AstNode` has a `generate` method responsible for this.
    *   Refer to: `src/main/scala/org/arnoldc/ArnoldGenerator.scala` and the `generate` methods in AST nodes like `src/main/scala/org/arnoldc/ast/PrintNode.scala`.
3.  **Symbol Table (`org.arnoldc.SymbolTable`)**: Used to keep track of variables, their scopes, and method information during parsing and code generation. It's crucial for managing variable addresses and method signatures.
    *   Refer to: `src/main/scala/org/arnoldc/SymbolTable.scala` (not provided, but its usage is evident in AST nodes).
4.  **Main Method Structure**: ArnoldC programs have a defined entry point, `IT'S SHOWTIME` and `YOU HAVE BEEN TERMINATED`, which corresponds to the `MainMethodNode`.
    *   Refer to: `src/main/scala/org/arnoldc/ast/MainMethodNode.scala` and `src/main/scala/org/arnoldc/ArnoldC.scala`.
5.  **Keywords and Mappings**: The project maps Arnold Schwarzenegger's catchphrases to programming language constructs. Understanding these mappings is key to writing ArnoldC code.
    *   Refer to: `README.md` for the keyword list.

## All docs

- **ArnoldC** (overview)
- **Build Configuration** (module)
- **Unit Tests** (module)
- **ArnoldC Compiler and Interpreter** (module)

Browse the interactive showcase: https://shipdocs.sh/showcase/1a5330cf-72e7-43f1-a8f6-2d3dcf4ce623
