# prasad25904/javascript_code_analyzer architecture

> Architecture diagram of the GitHub repository prasad25904/javascript_code_analyzer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/prasad25904/javascript_code_analyzer
- Repository: https://github.com/prasad25904/javascript_code_analyzer

## Overview

##### Project type and purpose
- This is a compiler-like, static analysis tool for JavaScript source code. It performs lexing, parsing, AST generation, symbol‐table construction, and semantic checks, then emits a Graphviz DOT file for AST visualization.

##### File structure
- Top level:
- js_lexer.l         – Flex specification for lexical analysis
- js_parser.y        – Bison grammar for parsing
- lex.yy.c           – Generated lexer code
- js_parser.tab.c/.h – Generated parser code
- symbol_table.c/.h  – Symbol table implementation
- semantic.c/.h      – Semantic analysis routines
- ast.h (and likely ast.c) – AST node definitions & utilities
- analyzer           – Final compiled executable
- *.js (input files) – Sample JavaScript programs
- ast.dot/.png       – AST output and visualization
- Makefile (Commands.txt) – Build instructions
- Pattern: A linear compiler-front-end pipeline.

##### README for additional insights
- Describes the use of Flex & Bison, supported JS features, output format (.dot) and Graphviz for AST rendering.

a. Main components:
1. CLI Front-end (“analyzer” executable)
2. Input Reader (fetches .js file)
3. Lexer (Flex)
4. Parser (Bison)
5. AST Generator (in-memory AST data structures)
6. Symbol Table Manager
7. Semantic Analyzer
8. DOT Generator (AST → ast.dot)
9. Graphviz (external) → ast.png
10. Build System (Makefile invoking gcc, flex, bison)
b. Relationships & data flow:
- Source .js → CLI → Lexer → Parser → AST → Symbol Table & Semantic Analyzer → DOT file → Graphviz → PNG.
- Build system orchestrates code generation (lex.yy.c, js_parser.tab.*) and compilation of all .c/.h files into the “analyzer” binary.
c. Architectural patterns:
- Pipeline / staged processing (lexer → parser → AST → semantics).
- Modular separation: each stage in its own source file.
- Clear separation of concerns (lexing, parsing, symbol management, semantic validation, visualization).
d. Technologies & frameworks:
- C language, GCC
- Flex (js_lexer.l → lex.yy.c)
- Bison (js_parser.y → js_parser.tab.c/.h)
- Graphviz for AST visualization

##### Detail
- Every stage: from raw JS input to visual output.
- How data structures evolve (tokens → parse tree → AST → semantic info).
- Where error reporting or extensibility hooks might live.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Source Input
    subgraph "Source Files"
        direction TB
        input_js["JavaScript Files (.js)"]:::doc
    end

    %% CLI Front-end
    cli["CLI Front-end<br/>(analyzer executable)"]:::process

    %% Lexing Stage
    subgraph "Lexing Stage"
        direction TB
        lexer_spec["js_lexer.l"]:::source
        lexer_gen["lex.yy.c"]:::generated
    end

    %% Parsing Stage
    subgraph "Parsing Stage"
        direction TB
        parser_spec["js_parser.y"]:::source
        parser_gen_c["js_parser.tab.c"]:::generated
        parser_gen_h["js_parser.tab.h"]:::generated
    end

    %% AST & Analysis Stage
    subgraph "AST & Analysis Stage"
        direction TB
        ast_gen["AST Generator (ast.h)"]:::process
        sym_c["symbol_table.c"]:::source
        sym_h["symbol_table.h"]:::source
        semantic_c["semantic.c"]:::source
        semantic_h["semantic.h"]:::source
        dot_out["DOT Generator (ast.dot)"]:::doc
    end

    %% External Visualization
    graphviz["Graphviz<br/>(ast.png)"]:::cloud

    %% Build System
    build["Build System<br/>(Makefile / Commands.txt)"]:::folder

    %% Pipeline Flow
    input_js --> cli
    cli --> lexer_spec
    lexer_spec --> lexer_gen
    lexer_gen --> parser_spec
    parser_spec --> parser_gen_c
    parser_gen_c --> parser_gen_h
    parser_gen_h --> ast_gen
    ast_gen --> sym_c
    sym_c --> sym_h
    sym_h --> semantic_c
    semantic_c --> semantic_h
    semantic_h --> dot_out
    dot_out --> graphviz

    %% Build Orchestration
    build --> lexer_spec
    build --> parser_spec
    build --> sym_c
    build --> semantic_c
    build --> ast_gen
    build --> cli

    %% Click Events
    click cli "https://github.com/prasad25904/javascript_code_analyzer/tree/main/analyzer"
    click input_js "https://github.com/prasad25904/javascript_code_analyzer/blob/main/input.js"
    click lexer_spec "https://github.com/prasad25904/javascript_code_analyzer/blob/main/js_lexer.l"
    click lexer_gen "https://github.com/prasad25904/javascript_code_analyzer/blob/main/lex.yy.c"
    click parser_spec "https://github.com/prasad25904/javascript_code_analyzer/blob/main/js_parser.y"
    click parser_gen_c "https://github.com/prasad25904/javascript_code_analyzer/blob/main/js_parser.tab.c"
    click parser_gen_h "https://github.com/prasad25904/javascript_code_analyzer/blob/main/js_parser.tab.h"
    click ast_gen "https://github.com/prasad25904/javascript_code_analyzer/blob/main/ast.h"
    click sym_c "https://github.com/prasad25904/javascript_code_analyzer/blob/main/symbol_table.c"
    click sym_h "https://github.com/prasad25904/javascript_code_analyzer/blob/main/symbol_table.h"
    click semantic_c "https://github.com/prasad25904/javascript_code_analyzer/blob/main/semantic.c"
    click semantic_h "https://github.com/prasad25904/javascript_code_analyzer/blob/main/semantic.h"
    click dot_out "https://github.com/prasad25904/javascript_code_analyzer/blob/main/ast.dot"
    click build "https://github.com/prasad25904/javascript_code_analyzer/blob/main/Commands.txt"

    %% Styles
    classDef process fill:#AED6F1,stroke:#21618C,color:#1B4F72;
    classDef source fill:#F9E79F,stroke:#B7950B,color:#7D6608;
    classDef generated fill:#D5F5E3,stroke:#27AE60,color:#1D8348;
    classDef doc fill:#FADBD8,stroke:#C0392B,color:#78281F,stroke-dasharray: 5 5;
    classDef cloud fill:#D6EAF8,stroke:#2980B9,color:#1B4F72,stroke-dasharray: 5 5;
    classDef folder fill:#E8DAEF,stroke:#8E44AD,color:#512E5F;
```
