How anaru03/cps-analyzer works
Purpose and entry points
Cps-analyzer is a Java 17 compiler-front-end exercise for Compiscript: it performs lexical and syntactic analysis, reports structured errors, and exposes both CLI and HTTP-facing entry points. Maven builds the project and invokes ANTLR 4 code generation from src/main/antlr4/gt/edu/uvg/compiscript/Compiscript.g4.
Primary launch classes are src/main/java/gt/edu/uvg/compiscript/CompiscriptApplication.java for the application/API runtime and src/main/java/gt/edu/uvg/compiscript/cli/Main.java for file-oriented command-line analysis.
Language definition and generated parser boundary
The Compiscript grammar is the authoritative language contract: src/main/antlr4/gt/edu/uvg/compiscript/Compiscript.g4. ANTLR-generated lexer/parser artifacts are an implementation boundary between grammar specification and handwritten analysis adapters.
A duplicate top-level grammar, Gramática de Compiscript.g4, and language definition document, Definición de Compiscript.md, provide source/reference context, but the Maven-standard grammar path is the likely build input.
Lexical analysis stage
src/main/java/gt/edu/uvg/compiscript/lexer/AnalizadorLexico.java wraps the ANTLR lexer into a domain API. It consumes source text and produces recognized-token and lexical-error results through ResultadoLexico.java and TokenReconocido.java.
ANTLR failures are captured rather than leaked directly through EscuchadorErroresLexicos.java and represented as ErrorLexico.java. This isolates parser/API/CLI callers from ANTLR listener types and provides a stable diagnostic model.
Syntactic analysis stage
src/main/java/gt/edu/uvg/compiscript/parser/AnalizadorSintactico.java drives parsing over the token stream produced from Compiscript input. It returns ResultadoSintactico.java and captures parser diagnostics as ErrorSintactico.java.
EscuchadorErroresSintacticos.java and EstrategiaErroresSintacticos.java define the parser error-handling boundary: custom listening and recovery behavior can collect multiple useful errors rather than relying on default ANTLR console output or fail-fast semantics.
Analysis orchestration and HTTP boundary
src/main/java/gt/edu/uvg/compiscript/api/AnalisisService.java is the application-level coordinator: it should sequence lexical and syntactic analysis and consolidate outcomes. src/main/java/gt/edu/uvg/compiscript/api/AnalisisController.java adapts that capability to an HTTP API.
The API contract is isolated in DTOs: request input in dto/SolicitudAnalisis.java, aggregate response in dto/RespuestaAnalisis.java, and externally serializable diagnostics in dto/ErrorAnalisis.java. This keeps transport payloads independent of lexer/parser domain classes.
Input/output flow
Source reaches the system either as a .cps file through cli/Main.java or as request content through api/AnalisisController.java. Both routes converge on analysis logic, then pass through lexer tokenization and parser validation. Results return recognized tokens and/or diagnostics, with error location/category information translated into domain or API DTOs.
Example inputs establish expected success and failure modes: ejemplos/archivo_correcto.cps, ejemplos/error_lexico1.cps, and ejemplos/error_parser1.cps.
Runtime and infrastructure
The backend runtime is Java 17 with Maven and ANTLR 4, configured by pom.xml. The presence of CompiscriptApplication.java, controller, and service indicates a Spring-style HTTP application layer.
A separate Vite/Vue frontend exists under frontend/src/App.vue and frontend/src/main.js. Its integration contract is the backend analysis API, though no deployment or proxy configuration is evident from the supplied tree.
Main entry points: AnalisisService.java Analysis Service · AnalizadorLexico.java Lexical Analyzer · AnalizadorSintactico.java Syntactic Analyzer · AnalisisController.java Analysis Controller
Components 16
Language Toolchain
- Compiscript Grammar · Authoritative language contract and Maven generation input.
src/main/antlr4/gt/edu/uvg/compiscript/Compiscript.g4 - Generated Lexer & Parser · Generated boundary consumed by handwritten adapters.
- Maven Build · Configures ANTLR generation and backend build.
pom.xml
Java Analysis Backend
- Lexical Analyzer
src/main/java/gt/edu/uvg/compiscript/lexer/AnalizadorLexico.java - Lexical Result · Recognized tokens and lexical diagnostics.
src/main/java/gt/edu/uvg/compiscript/lexer/ResultadoLexico.java - Lexical Error Boundary · Captures ANTLR lexer failures as domain errors.
src/main/java/gt/edu/uvg/compiscript/lexer/EscuchadorErroresLexicos.java - Syntactic Analyzer
src/main/java/gt/edu/uvg/compiscript/parser/AnalizadorSintactico.java - Syntactic Result · Parsing outcome and syntax diagnostics.
src/main/java/gt/edu/uvg/compiscript/parser/ResultadoSintactico.java - Syntax Error Boundary · Collects multiple parser errors with custom recovery.
src/main/java/gt/edu/uvg/compiscript/parser/EscuchadorErroresSintacticos.java
HTTP API
- Analysis Service · Sequences lexical and syntactic analysis and consolidates outcomes.
src/main/java/gt/edu/uvg/compiscript/api/AnalisisService.java - Analysis Controller
src/main/java/gt/edu/uvg/compiscript/api/AnalisisController.java - Analysis DTOs · Request, aggregate response, and serializable diagnostics.
src/main/java/gt/edu/uvg/compiscript/api/dto/SolicitudAnalisis.java - Application Runtime
src/main/java/gt/edu/uvg/compiscript/CompiscriptApplication.java
Clients
- CLI · Analyzes .cps files.
src/main/java/gt/edu/uvg/compiscript/cli/Main.java - Vue Frontend · Consumes the backend analysis API.
frontend/src/App.vue - Example .cps Inputs · Success and lexical or parser failure cases.
ejemplos/archivo_correcto.cps
Connections 20
- Maven Build → Compiscript Grammar: generates from
- Compiscript Grammar → Generated Lexer & Parser: defines
- Generated Lexer & Parser → Lexical Analyzer: lexer runtime
- Generated Lexer & Parser → Syntactic Analyzer: parser runtime
- Lexical Analyzer → Lexical Error Boundary: captures failures
- Lexical Analyzer → Lexical Result: returns
- Lexical Analyzer → Syntactic Analyzer: token stream
- Syntactic Analyzer → Syntax Error Boundary: captures and recovers
- Syntactic Analyzer → Syntactic Result: returns
- Analysis Service → Lexical Analyzer: runs first
- Analysis Service → Syntactic Analyzer: runs validation
- Analysis Controller → Analysis Service: delegates
- Analysis Controller → Analysis DTOs: maps transport
- Application Runtime → Analysis Controller: hosts
- CLI → Analysis Service: submits file source
- Vue Frontend → Analysis Controller: analysis requests
- Example .cps Inputs → CLI: input cases
- Lexical Result → Analysis Service: consolidated
- Syntactic Result → Analysis Service: consolidated
- Analysis Service → Analysis DTOs: response diagnostics