nsbaci 1.0
Loading...
Searching...
No Matches
nsbaci::compiler::NsbaciCompiler Class Referencefinal

nsbaci compiler implementation using flex and bison. More...

#include <nsbaciCompiler.h>

Inheritance diagram for nsbaci::compiler::NsbaciCompiler:
Collaboration diagram for nsbaci::compiler::NsbaciCompiler:

Public Member Functions

 NsbaciCompiler ()=default
 Default constructor.
 ~NsbaciCompiler () override=default
 Destructor.
CompilerResult compile (const std::string &source) override
 Compiles nsbaci source code from a string.
CompilerResult compile (std::istream &input) override
 Compiles nsbaci source code from an input stream.
Public Member Functions inherited from nsbaci::compiler::Compiler
 Compiler ()=default
 Default constructor.
virtual ~Compiler ()=default
 Virtual destructor.

Detailed Description

nsbaci compiler implementation using flex and bison.

Usage example:

auto result = compiler.compile("int x = 5; cout << x << endl;");
if (result.ok) {
// result.instructions contains the p-code
// result.symbols contains variable information
} else {
// Handle compilation errors
}
NsbaciCompiler()=default
Default constructor.
Compiler namespace containing all compilation-related stuff.

Member Function Documentation

◆ compile() [1/2]

CompilerResult nsbaci::compiler::NsbaciCompiler::compile ( const std::string & source)
overridevirtual

Compiles nsbaci source code from a string.

Creates a string stream from the source and delegates to the stream compile method.

Parameters
sourceThe nsbaci source code to compile.
Returns
CompilerResult with instructions and symbols on success, or detailed error information on failure.

Implements nsbaci::compiler::Compiler.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compile() [2/2]

CompilerResult nsbaci::compiler::NsbaciCompiler::compile ( std::istream & input)
overridevirtual

Compiles nsbaci source code from an input stream.

Performs the actual compilation by:

  1. Creating a Lexer to tokenize the input
  2. Creating a Parser with the lexer
  3. Running the parser to generate instructions
  4. Collecting any errors that occurred
Parameters
inputThe input stream containing nsbaci source code.
Returns
CompilerResult with instructions and symbols on success, or detailed error information on failure.

Implements nsbaci::compiler::Compiler.


The documentation for this class was generated from the following files: