# domingues/updigitalscript architecture

> Architecture diagram of the GitHub repository domingues/updigitalscript, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/domingues/updigitalscript
- Repository: https://github.com/domingues/updigitalscript

## Overview

##### Main Components

A. Source Code Processing Layer
- PL/SQL Grammar Components (from grammar directory)
- Lexer and Parser Components (from lib directory)
- Compiler System (src/Compiler.js)

B. Web Interface Layer
- Editor Component (docs/editor.ups)
- Code Examples (fibonacci.ups, mandelbrot_set.ups)
- Web UI (docs/index.html, css, js)

C. Build and Generation System
- Grammar Generation Scripts
- Bundle Generation (rollup.config.js)

**Level 1: Input Layer**
**[PL/SQL Code Input] --> [ACE Editor Integration]**

**Level 2: Processing Layer**
**[PlSqlLexer] --> [PlSqlParser] --> [Compiler]**

- v
**Level 3: Output Layer**
**[UPdigitalScript Bundle] --> [JavaScript Runtime]**

##### Component Details

A. Grammar Processing:
- Relationship between PlSqlLexer.g4 and PlSqlParser.g4
- Generation of JavaScript/TypeScript files from grammar

B. Compilation Pipeline:
- Transformation stages from PL/SQL to JavaScript
- How the Compiler.js interfaces with the parser components

C. Web Interface:
- Demonstrate the integration of the ACE editor
- How the compiled code is executed in the browser

##### Important Technical Elements

- ANTLR4-based grammar system
- TypeScript compilation process
- Bundling process using Rollup
- Browser runtime environment

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        CodeInput[PL/SQL Code Input]:::input
        Editor["ACE Editor"]:::input
        click Editor "https://github.com/domingues/updigitalscript/blob/master/docs/js/ace/ace.js"
        PLSQLMode["PL/SQL Mode"]:::input
        click PLSQLMode "https://github.com/domingues/updigitalscript/blob/master/docs/js/ace/mode-plsql.js"
    end

    subgraph Grammar
        LexerGrammar["PlSqlLexer Grammar"]:::grammar
        click LexerGrammar "https://github.com/domingues/updigitalscript/blob/master/grammar/PlSqlLexer.g4"
        ParserGrammar["PlSqlParser Grammar"]:::grammar
        click ParserGrammar "https://github.com/domingues/updigitalscript/blob/master/grammar/PlSqlParser.g4"
    end

    subgraph "Processing Pipeline"
        Lexer["PlSqlLexer"]:::processor
        click Lexer "https://github.com/domingues/updigitalscript/blob/master/lib/PlSqlLexer.ts"
        Parser["PlSqlParser"]:::processor
        click Parser "https://github.com/domingues/updigitalscript/blob/master/lib/PlSqlParser.ts"
        ParserVisitor["PlSqlParserVisitor"]:::processor
        click ParserVisitor "https://github.com/domingues/updigitalscript/blob/master/lib/PlSqlParserVisitor.ts"
        Compiler["Compiler"]:::processor
        click Compiler "https://github.com/domingues/updigitalscript/blob/master/src/Compiler.js"
        UPScript["UPdigitalScript Core"]:::processor
        click UPScript "https://github.com/domingues/updigitalscript/blob/master/src/UPdigitalScript.js"
    end

    subgraph "Build System"
        GenGrammar["Grammar Generator"]:::build
        click GenGrammar "https://github.com/domingues/updigitalscript/blob/master/scripts/gen-js-grammar.sh"
        Bundler["Rollup Bundler"]:::build
        click Bundler "https://github.com/domingues/updigitalscript/blob/master/rollup.config.js"
        Bundle["UPdigitalScript Bundle"]:::output
        click Bundle "https://github.com/domingues/updigitalscript/blob/master/docs/js/UPdigitalScript-bundle.js"
    end

    subgraph "Web Interface"
        WebUI["Web UI"]:::ui
        click WebUI "https://github.com/domingues/updigitalscript/blob/master/docs/index.html"
        Examples["Code Examples"]:::ui
        Styles["CSS Styles"]:::ui
        click Styles "https://github.com/domingues/updigitalscript/blob/master/docs/css/css.css"
    end

    subgraph "Runtime"
        JSRuntime["JavaScript Runtime"]:::runtime
    end

    %% Relationships
    CodeInput --> Editor
    Editor --> PLSQLMode
    
    LexerGrammar --> GenGrammar
    ParserGrammar --> GenGrammar
    
    GenGrammar --> Lexer
    GenGrammar --> Parser
    GenGrammar --> ParserVisitor
    
    Lexer --> Compiler
    Parser --> Compiler
    ParserVisitor --> Compiler
    
    Compiler --> UPScript
    UPScript --> Bundler
    Bundler --> Bundle
    
    Bundle --> JSRuntime
    WebUI --> Bundle
    Examples --> Editor

    %% Styles
    classDef input fill:#a8d1f0,stroke:#333
    classDef grammar fill:#f9d79b,stroke:#333
    classDef processor fill:#a8e6cf,stroke:#333
    classDef build fill:#ffd3b6,stroke:#333
    classDef output fill:#ff8b94,stroke:#333
    classDef ui fill:#dcedc1,stroke:#333
    classDef runtime fill:#d1b3c4,stroke:#333

    %% Legend
    subgraph Legend
        L1[Input Components]:::input
        L2[Grammar Definitions]:::grammar
        L3[Processing Components]:::processor
        L4[Build Tools]:::build
        L5[Output Components]:::output
        L6[UI Components]:::ui
        L7[Runtime Environment]:::runtime
    end
```
