|
MXVM 1.8.1
Virtual Machine, Compiler, and Pascal Frontend
|
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 |
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.
|
explicit |
Construct a parser from MXVM source text.
| source | The 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().
|
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.
|
private |
Definition at line 842 of file parser.cpp.
References collectObjectNames().
Referenced by collectObjectNames().
| 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().
| 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().
Walk the AST and populate a Program with instructions and variables.
| m | Execution mode (interpret or compile) |
| program | Output program to populate |
Definition at line 737 of file parser.cpp.
References mxvm::Base::base, mx::Color::BRIGHT_GREEN, mxvm::SectionNode::CODE, Col(), mxvm::SectionNode::DATA, generateDebugHTML(), generateObjectAssemblyFile(), mxvm::html_mode, mxvm::MODE_COMPILE, mxvm::SectionNode::MODULE, mxvm::SectionNode::OBJECT, object_name, parseAST(), parser_mode, platform, processCodeSection(), processDataSection(), processModuleSection(), processObjectSection(), registerObjectExterns(), and validator.
Referenced by action_interpret(), and translate_x64().
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.
| 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().
| void mxvm::Parser::parse | ( | ) |
Parse all tokens into the internal AST.
Definition at line 730 of file parser.cpp.
References parseAST().
| std::unique_ptr< ProgramNode > mxvm::Parser::parseAST | ( | ) |
Build the full AST from tokens.
Definition at line 201 of file parser.cpp.
References object_name, operator[](), parseProgramOrObject(), and scanner.
Referenced by generateProgramCode(), and parse().
|
private |
Definition at line 579 of file parser.cpp.
References ADD, ALLOC, AND, CALL, CMP, DIV, DONE, EXIT, FCMP, FREE, GETLINE, INVOKE, JA, JAE, JB, JBE, JC, JE, JG, JGE, JL, JLE, JMP, JNC, JNE, JNO, JNP, JNS, JNZ, JO, JP, JS, JZ, mxvm::Operand::label, LEA, LOAD, MOD, MOV, MUL, NEG, NOT, mxvm::Operand::object, mxvm::Operand::op, mxvm::OP_CONSTANT, mxvm::Operand::op_value, mxvm::OP_VARIABLE, operator[](), OR, POP, PRINT, PUSH, REALLOC, RET, RETURN, scanner, STACK_LOAD, STACK_STORE, STACK_SUB, STORE, STRING_PRINT, SUB, TO_FLOAT, TO_INT, types::TT_HEX, types::TT_ID, types::TT_NUM, types::TT_STR, types::TT_SYM, mxvm::Operand::type, and XOR.
Referenced by parseSection().
|
private |
Definition at line 688 of file parser.cpp.
References operator[](), and scanner.
Referenced by parseSection().
|
private |
Definition at line 461 of file parser.cpp.
References operator[](), scanner, types::TT_HEX, types::TT_ID, types::TT_NUM, types::TT_STR, types::TT_SYM, mxvm::VAR_ARRAY, mxvm::VAR_BYTE, mxvm::VAR_FLOAT, mxvm::VAR_INTEGER, mxvm::VAR_POINTER, and mxvm::VAR_STRING.
Referenced by parseSection().
|
private |
Definition at line 709 of file parser.cpp.
References operator[](), scanner, and types::TT_ID.
Referenced by parseSection().
|
private |
Definition at line 449 of file parser.cpp.
References operator[](), and scanner.
|
private |
Definition at line 245 of file parser.cpp.
References operator[](), and scanner.
Referenced by parseSection().
| std::unique_ptr< ProgramNode > mxvm::Parser::parseProgramOrObject | ( | uint64_t & | index | ) |
Parse a top-level program or object node.
| index | Token index (advanced past consumed tokens) |
Definition at line 1353 of file parser.cpp.
References mxvm::VAR_ARRAY, mxvm::VAR_BYTE, and mxvm::VAR_EXTERN.
Referenced by parseAST().
|
private |
Definition at line 347 of file parser.cpp.
References mxvm::SectionNode::CODE, mxvm::SectionNode::DATA, mxvm::SectionNode::MODULE, mxvm::SectionNode::OBJECT, operator[](), parseCodeInstruction(), parseComment(), parseDataVariable(), parseLabel(), parseObject(), scanner, and types::TT_ID.
|
private |
Definition at line 854 of file parser.cpp.
References mxvm::Program::escapeNewLines(), mxvm::VAR_ARRAY, mxvm::VAR_BYTE, mxvm::VAR_EXTERN, mxvm::VAR_FLOAT, mxvm::VAR_INTEGER, mxvm::VAR_LABEL, mxvm::VAR_POINTER, and mxvm::VAR_STRING.
|
private |
Definition at line 1228 of file parser.cpp.
Referenced by generateProgramCode().
|
private |
Definition at line 1140 of file parser.cpp.
Referenced by generateProgramCode().
|
private |
Definition at line 1170 of file parser.cpp.
|
private |
Definition at line 1160 of file parser.cpp.
Referenced by generateProgramCode().
|
private |
Definition at line 267 of file parser.cpp.
References Parser(), mxvm::Base::base, mxvm::SectionNode::CODE, mxvm::SectionNode::DATA, mxvm::SectionNode::MODULE, module_path, mxvm::SectionNode::OBJECT, object_path, parser_mode, platform, registerObjectExterns(), and mxvm::Validator::validate().
Referenced by processObjectSection().
|
private |
Definition at line 257 of file parser.cpp.
References processObjectFile(), and mxvm::SectionNode::statements.
Referenced by generateProgramCode().
| 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().
|
private |
Definition at line 1344 of file parser.cpp.
References mxvm::VAR_LABEL, mxvm::VAR_POINTER, and mxvm::VAR_STRING.
| 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().
Definition at line 1311 of file parser.cpp.
References mxvm::VAR_FLOAT, and mxvm::VAR_INTEGER.
|
private |
Definition at line 1269 of file parser.cpp.
|
friend |
| 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().
| 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().
| 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=().
| std::string mxvm::Parser::object_name |
Definition at line 136 of file parser.hpp.
Referenced by Parser(), generateProgramCode(), operator=(), and parseAST().
| 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().
| Mode mxvm::Parser::parser_mode = Mode::MODE_INTERPRET |
Definition at line 131 of file parser.hpp.
Referenced by Parser(), generateProgramCode(), operator=(), and processObjectFile().
| Platform mxvm::Parser::platform |
Definition at line 137 of file parser.hpp.
Referenced by Parser(), generateProgramCode(), operator=(), processObjectFile(), and translate_x64().
| scan::Scanner mxvm::Parser::scanner |
Definition at line 129 of file parser.hpp.
Referenced by Parser(), Parser(), operator=(), operator[](), parseAST(), parseCodeInstruction(), parseComment(), parseDataVariable(), parseLabel(), parseModule(), parseObject(), parseSection(), and scan().
| std::string mxvm::Parser::source_file |
Definition at line 128 of file parser.hpp.
Referenced by Parser(), Parser(), and operator=().
| Validator mxvm::Parser::validator |
Definition at line 130 of file parser.hpp.
Referenced by Parser(), Parser(), generateProgramCode(), and operator=().