How prasad25904/javascript_code_analyzer works
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.