MXVM 1.8.1
Virtual Machine, Compiler, and Pascal Frontend
Loading...
Searching...
No Matches
mxvm::Parser Class Reference

Main MXVM parser — tokenizes source, builds AST, and generates intermediate code. More...

#include <parser.hpp>

Public Member Functions

 Parser (const std::string &source)
 Construct a parser from MXVM source text.
 Parser (const Parser &other)
 Copy constructor.
Parser & operator= (const Parser &other)
 Copy assignment.
uint64_t scan ()
 Tokenize the source and return the token count.
void parse ()
 Parse all tokens into the internal AST.
auto operator[] (size_t pos)
 Access a token by position.
std::unique_ptr< ProgramNode > parseProgramOrObject (uint64_t &index)
 Parse a top-level program or object node.
std::unique_ptr< ProgramNode > parseAST ()
 Build the full AST from tokens.
bool generateProgramCode (const Mode &m, std::unique_ptr< Program > &program)
 Walk the AST and populate a Program with instructions and variables.
bool generateDebugHTML (std::ostream &out, std::unique_ptr< Program > &program)
 Generate debug HTML output for the program.
void generateObjectAssemblyFile (std::unique_ptr< Program > &objProgram)
 Generate a native assembly file for an object.
void registerObjectExterns (std::unique_ptr< Program > &mainProgram, const std::unique_ptr< Program > &objProgram)
 Register external functions from an object into the main program.

Public Attributes

std::string source_file
scan::Scanner scanner
Validator validator
Mode parser_mode = Mode::MODE_INTERPRET
std::string module_path = "."
 search path for .mxvm module files
std::string object_path = "."
 search path for .mxvm object files
std::string include_path = "/usr/local/include/mxvm/modules"
 system module include path
bool object_mode = false
 true when parsing an object definition
std::string object_name
Platform platform

Private Member Functions

std::unique_ptr< SectionNode > parseSection (uint64_t &index)
std::unique_ptr< VariableNode > parseDataVariable (uint64_t &index)
std::unique_ptr< InstructionNode > parseCodeInstruction (uint64_t &index)
std::unique_ptr< CommentNode > parseComment (uint64_t &index)
std::unique_ptr< LabelNode > parseLabel (uint64_t &index)
std::unique_ptr< ModuleNode > parseModule (uint64_t &index)
std::unique_ptr< ObjectNode > parseObject (uint64_t &index)
void processDataSection (SectionNode *sectionNode, std::unique_ptr< Program > &program)
void processCodeSection (SectionNode *sectionNode, std::unique_ptr< Program > &program)
void processModuleSection (SectionNode *sectionNode, std::unique_ptr< Program > &program)
void processObjectSection (SectionNode *sectionNode, std::unique_ptr< Program > &program)
void processModuleFile (const std::string &src, std::unique_ptr< Program > &program)
void processObjectFile (const std::string &src, std::unique_ptr< Program > &program)
void setVariableValue (Variable &var, VarType type, const std::string &value, size_t buf_size=0)
void setDefaultVariableValue (Variable &var, VarType type)
void resolveLabelReference (Operand &operand, const std::unordered_map< std::string, size_t > &labelMap)
void collectObjectNames (std::vector< std::pair< std::string, std::string > > &names, const std::unique_ptr< Program > &program)
void printObjectHTML (std::ostream &out, const std::unique_ptr< Program > &objPtr)

Friends

class ModuleParser

Detailed Description

Main MXVM parser — tokenizes source, builds AST, and generates intermediate code.

Handles the full pipeline from source text to a populated Program: scanning tokens, parsing sections (data/code/module/object), resolving modules and objects, and dispatching to the code generator.

Definition at line 57 of file parser.hpp.

Constructor & Destructor Documentation

◆ Parser() [1/2]

mxvm::Parser::Parser ( const std::string & source)
explicit

Construct a parser from MXVM source text.

Parameters
sourceThe MXVM source code to parse

Definition at line 181 of file parser.cpp.

References scanner, source_file, and validator.

Referenced by Parser(), operator=(), and processObjectFile().

◆ Parser() [2/2]

mxvm::Parser::Parser ( const Parser & other)
inline

Copy constructor.

Definition at line 67 of file parser.hpp.

References Parser(), include_path, module_path, object_mode, object_name, object_path, parser_mode, platform, scanner, source_file, and validator.

Member Function Documentation

◆ collectObjectNames()

void mxvm::Parser::collectObjectNames ( std::vector< std::pair< std::string, std::string > > & names,
const std::unique_ptr< Program > & program )
private

Definition at line 842 of file parser.cpp.

References collectObjectNames().

Referenced by collectObjectNames().

◆ generateDebugHTML()

bool mxvm::Parser::generateDebugHTML ( std::ostream & out,
std::unique_ptr< Program > & program )

Generate debug HTML output for the program.

Definition at line 987 of file parser.cpp.

Referenced by action_interpret(), generateProgramCode(), and translate_x64().

◆ generateObjectAssemblyFile()

void mxvm::Parser::generateObjectAssemblyFile ( std::unique_ptr< Program > & objProgram)

Generate a native assembly file for an object.

Definition at line 1394 of file parser.cpp.

Referenced by generateProgramCode().

◆ generateProgramCode()

bool mxvm::Parser::generateProgramCode ( const Mode & m,
std::unique_ptr< Program > & program )

◆ operator=()

Parser & mxvm::Parser::operator= ( const Parser & other)
inline

Copy assignment.

Definition at line 80 of file parser.hpp.

References Parser(), include_path, module_path, object_mode, object_name, object_path, parser_mode, platform, scanner, source_file, and validator.

◆ operator[]()

auto mxvm::Parser::operator[] ( size_t pos)

Access a token by position.

Definition at line 193 of file parser.cpp.

References pos(), and scanner.

Referenced by parseAST(), parseCodeInstruction(), parseComment(), parseDataVariable(), parseLabel(), parseModule(), parseObject(), and parseSection().

◆ parse()

void mxvm::Parser::parse ( )

Parse all tokens into the internal AST.

Definition at line 730 of file parser.cpp.

References parseAST().

◆ parseAST()

std::unique_ptr< ProgramNode > mxvm::Parser::parseAST ( )

Build the full AST from tokens.

Returns
Root ProgramNode of the AST

Definition at line 201 of file parser.cpp.

References object_name, operator[](), parseProgramOrObject(), and scanner.

Referenced by generateProgramCode(), and parse().

◆ parseCodeInstruction()

◆ parseComment()

std::unique_ptr< CommentNode > mxvm::Parser::parseComment ( uint64_t & index)
private

Definition at line 688 of file parser.cpp.

References operator[](), and scanner.

Referenced by parseSection().

◆ parseDataVariable()

std::unique_ptr< VariableNode > mxvm::Parser::parseDataVariable ( uint64_t & index)
private

◆ parseLabel()

std::unique_ptr< LabelNode > mxvm::Parser::parseLabel ( uint64_t & index)
private

Definition at line 709 of file parser.cpp.

References operator[](), scanner, and types::TT_ID.

Referenced by parseSection().

◆ parseModule()

std::unique_ptr< ModuleNode > mxvm::Parser::parseModule ( uint64_t & index)
private

Definition at line 449 of file parser.cpp.

References operator[](), and scanner.

◆ parseObject()

std::unique_ptr< ObjectNode > mxvm::Parser::parseObject ( uint64_t & index)
private

Definition at line 245 of file parser.cpp.

References operator[](), and scanner.

Referenced by parseSection().

◆ parseProgramOrObject()

std::unique_ptr< ProgramNode > mxvm::Parser::parseProgramOrObject ( uint64_t & index)

Parse a top-level program or object node.

Parameters
indexToken index (advanced past consumed tokens)
Returns
Parsed ProgramNode

Definition at line 1353 of file parser.cpp.

References mxvm::VAR_ARRAY, mxvm::VAR_BYTE, and mxvm::VAR_EXTERN.

Referenced by parseAST().

◆ parseSection()

◆ printObjectHTML()

void mxvm::Parser::printObjectHTML ( std::ostream & out,
const std::unique_ptr< Program > & objPtr )
private

◆ processCodeSection()

void mxvm::Parser::processCodeSection ( SectionNode * sectionNode,
std::unique_ptr< Program > & program )
private

Definition at line 1228 of file parser.cpp.

Referenced by generateProgramCode().

◆ processDataSection()

void mxvm::Parser::processDataSection ( SectionNode * sectionNode,
std::unique_ptr< Program > & program )
private

Definition at line 1140 of file parser.cpp.

Referenced by generateProgramCode().

◆ processModuleFile()

void mxvm::Parser::processModuleFile ( const std::string & src,
std::unique_ptr< Program > & program )
private

Definition at line 1170 of file parser.cpp.

◆ processModuleSection()

void mxvm::Parser::processModuleSection ( SectionNode * sectionNode,
std::unique_ptr< Program > & program )
private

Definition at line 1160 of file parser.cpp.

Referenced by generateProgramCode().

◆ processObjectFile()

void mxvm::Parser::processObjectFile ( const std::string & src,
std::unique_ptr< Program > & program )
private

◆ processObjectSection()

void mxvm::Parser::processObjectSection ( SectionNode * sectionNode,
std::unique_ptr< Program > & program )
private

Definition at line 257 of file parser.cpp.

References processObjectFile(), and mxvm::SectionNode::statements.

Referenced by generateProgramCode().

◆ registerObjectExterns()

void mxvm::Parser::registerObjectExterns ( std::unique_ptr< Program > & mainProgram,
const std::unique_ptr< Program > & objProgram )

Register external functions from an object into the main program.

Definition at line 1415 of file parser.cpp.

Referenced by generateProgramCode(), and processObjectFile().

◆ resolveLabelReference()

void mxvm::Parser::resolveLabelReference ( Operand & operand,
const std::unordered_map< std::string, size_t > & labelMap )
private

Definition at line 1344 of file parser.cpp.

References mxvm::VAR_LABEL, mxvm::VAR_POINTER, and mxvm::VAR_STRING.

◆ scan()

uint64_t mxvm::Parser::scan ( )

Tokenize the source and return the token count.

Definition at line 184 of file parser.cpp.

References scanner, and scan::ScanExcept::why().

Referenced by action_interpret(), and translate_x64().

◆ setDefaultVariableValue()

void mxvm::Parser::setDefaultVariableValue ( Variable & var,
VarType type )
private

Definition at line 1311 of file parser.cpp.

References mxvm::VAR_FLOAT, and mxvm::VAR_INTEGER.

◆ setVariableValue()

void mxvm::Parser::setVariableValue ( Variable & var,
VarType type,
const std::string & value,
size_t buf_size = 0 )
private

Definition at line 1269 of file parser.cpp.

◆ ModuleParser

friend class ModuleParser
friend

Definition at line 60 of file parser.hpp.

References ModuleParser.

Referenced by ModuleParser.

Member Data Documentation

◆ include_path

std::string mxvm::Parser::include_path = "/usr/local/include/mxvm/modules"

system module include path

Definition at line 134 of file parser.hpp.

Referenced by Parser(), action_interpret(), operator=(), and translate_x64().

◆ module_path

std::string mxvm::Parser::module_path = "."

search path for .mxvm module files

Definition at line 132 of file parser.hpp.

Referenced by Parser(), action_interpret(), operator=(), processObjectFile(), and translate_x64().

◆ object_mode

bool mxvm::Parser::object_mode = false

true when parsing an object definition

Definition at line 135 of file parser.hpp.

Referenced by Parser(), and operator=().

◆ object_name

std::string mxvm::Parser::object_name

Definition at line 136 of file parser.hpp.

Referenced by Parser(), generateProgramCode(), operator=(), and parseAST().

◆ object_path

std::string mxvm::Parser::object_path = "."

search path for .mxvm object files

Definition at line 133 of file parser.hpp.

Referenced by Parser(), action_interpret(), operator=(), processObjectFile(), and translate_x64().

◆ parser_mode

Mode mxvm::Parser::parser_mode = Mode::MODE_INTERPRET

Definition at line 131 of file parser.hpp.

Referenced by Parser(), generateProgramCode(), operator=(), and processObjectFile().

◆ platform

Platform mxvm::Parser::platform

Definition at line 137 of file parser.hpp.

Referenced by Parser(), generateProgramCode(), operator=(), processObjectFile(), and translate_x64().

◆ scanner

◆ source_file

std::string mxvm::Parser::source_file

Definition at line 128 of file parser.hpp.

Referenced by Parser(), Parser(), and operator=().

◆ validator

Validator mxvm::Parser::validator

Definition at line 130 of file parser.hpp.

Referenced by Parser(), Parser(), generateProgramCode(), and operator=().


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