How zsivadi/szakmai-gyakorlat works
Purpose and Entry Points
This is a .NET SQL-to-C# LINQ transpiler prototype. It accepts SQL, parses it into a SQL-oriented AST, converts that representation to a LINQ AST/code form, and exposes the flow through a command-line executable. The main runtime entry point is SqlToLinq.Cli/Program.cs; shared compiler logic is in SqlToLinq.Core/.
Solution Structure
The solution is split into three material projects:
• CLI host: SqlToLinq.Cli/SqlToLinq.Cli.csproj
• Compiler/transpiler core: SqlToLinq.Core/SqlToLinq.Core.csproj
• Verification suite: SqlToLinq.Tests/SqlToLinq.Tests.csproj
SqlToLinq.slnx composes these projects. This is a local .NET application/library architecture, not a web or service deployment.
Parsing Boundary: SQL Text to Parse Tree
ANTLR 4 is the parser boundary. SqlToLinq.Core/SqlParser.g4 defines the supported SQL grammar and drives generated parser artifacts during the .NET build. Invalid parse input is routed through SqlToLinq.Core/ThrowingErrorListener.cs, making syntax failures explicit rather than silently recovered.
SQL Semantic Model Construction
SqlToLinq.Core/SqlVisitor.cs traverses the ANTLR parse tree and constructs the project’s internal SQL representation. This separates grammar-specific parser contexts from subsequent translation logic, allowing the converter to operate on a stable semantic/AST layer rather than directly on ANTLR types.
The resulting SQL AST is represented or coordinated through:
• SqlToLinq.Core/SqlVisitor.cs
• SqlToLinq.Core/LinqAst.cs
• SqlToLinq.Core/AstVisualizer.cs
AstVisualizer.cs is an observability boundary for inspecting intermediate structure during compiler development.
Translation and LINQ Representation
SqlToLinq.Core/SqlToLinqConverter.cs is the primary orchestration/translation stage: SQL input and/or its parsed representation are transformed into LINQ output. SqlToLinq.Core/LinqAst.cs models LINQ-oriented constructs used during generation, keeping SQL semantics and target-language expression construction distinct.
The essential control flow is:
SQL source → ANTLR grammar/parser → SqlVisitor SQL AST → SqlToLinqConverter / LINQ AST → generated LINQ expression or C# text.
Runtime and External Dependencies
The implementation targets C#/.NET and uses ANTLR 4 for language recognition. The intended target is LINQ, with Roslyn identified by the project documentation as the C# syntax/code-generation platform. There are no indicated network services, databases, queues, or deployed infrastructure in the production path.
Correctness Strategy
Tests validate both textual transpilation and behavioral equivalence. SqlToLinq.Tests/TranspilerTests.cs covers expected input/output mappings backed by SqlToLinq.Tests/IOPairs.json. SqlToLinq.Tests/SemanticEquivalenceTests.cs and SqlToLinq.Tests/TestDbContext.cs establish a database/LINQ execution boundary for comparing query meaning. Fuzz coverage is supplied by SqlToLinq.Tests/FuzzTests.cs and SqlToLinq.Tests/RandomSqlGenerator.cs, exercising parser and conversion robustness across generated SQL.
Main entry points: SqlToLinqConverter.cs SQL-to-LINQ converter · FuzzTests.cs Fuzz tests · Program.cs CLI host · SemanticEquivalenceTests.cs Semantic equivalence tests
Components 18
Transpiler runtime
CLI and compiler pipeline.
- CLI host · Accepts SQL and exposes transpilation.
SqlToLinq.Cli/Program.cs - Compiler core · Shared parsing and translation implementation.
SqlToLinq.Core/SqlToLinq.Core.csproj - SQL grammar · Defines supported SQL syntax and generated parser input.
SqlToLinq.Core/SqlParser.g4 - ANTLR parser · Produces parse trees from SQL text.
- Throwing error listener · Turns invalid SQL syntax into explicit failures.
SqlToLinq.Core/ThrowingErrorListener.cs - SQL visitor · Converts ANTLR contexts into the internal SQL representation.
SqlToLinq.Core/SqlVisitor.cs - SQL AST · Grammar-independent SQL representation.
- AST visualizer · Inspects intermediate compiler structure.
SqlToLinq.Core/AstVisualizer.cs - SQL-to-LINQ converter · Transforms SQL semantics into LINQ-oriented output.
SqlToLinq.Core/SqlToLinqConverter.cs - LINQ AST · Models LINQ-oriented constructs for generation.
SqlToLinq.Core/LinqAst.cs - LINQ / C# output · Generated LINQ expression or C# text.
- Roslyn · Intended C# syntax and code-generation platform.
Verification
Textual, semantic, and fuzz validation.
- Transpiler tests · Checks expected SQL-to-LINQ output mappings.
SqlToLinq.Tests/TranspilerTests.cs - I/O fixtures · Expected transpilation input/output pairs.
SqlToLinq.Tests/IOPairs.json - Semantic equivalence tests · Compares query meaning through database and LINQ execution.
SqlToLinq.Tests/SemanticEquivalenceTests.cs - Test DbContext · Database/LINQ execution context for semantic checks.
SqlToLinq.Tests/TestDbContext.cs - Fuzz tests · Exercises parser and converter with generated SQL.
SqlToLinq.Tests/FuzzTests.cs - Random SQL generator · Generates SQL inputs for robustness coverage.
SqlToLinq.Tests/RandomSqlGenerator.cs
Connections 18
- CLI host → Compiler core: uses
- SQL grammar → ANTLR parser: generates
- CLI host → ANTLR parser: SQL input
- ANTLR parser → Throwing error listener: syntax failures
- ANTLR parser → SQL visitor: parse tree
- SQL visitor → SQL AST: builds
- SQL AST → AST visualizer: inspect
- SQL AST → SQL-to-LINQ converter: translate
- SQL-to-LINQ converter → LINQ AST: builds
- LINQ AST → LINQ / C# output: generates
- SQL-to-LINQ converter → Roslyn: C# generation
- I/O fixtures → Transpiler tests: fixtures
- Transpiler tests → SQL-to-LINQ converter: validates output
- Semantic equivalence tests → Test DbContext: executes queries
- Semantic equivalence tests → SQL-to-LINQ converter: compares meaning
- Random SQL generator → Fuzz tests: generated inputs
- Fuzz tests → ANTLR parser: exercises parsing
- Fuzz tests → SQL-to-LINQ converter: exercises conversion