39 explicit XParser(
const std::string &source)
62 if (!
token)
return false;
63 const auto &v =
token->getTokenValue();
64 if (v.size() != s.size())
return false;
65 for (
size_t i = 0; i < v.size(); ++i)
66 if (std::tolower(
static_cast<unsigned char>(v[i])) !=
67 std::tolower(
static_cast<unsigned char>(s[i])))
141 void error(
const std::string &message);
147 bool match(
const std::string &s);
Semantic validator for Pascal programs.
Base parser providing token-stream navigation.
std::string filename
source filename for error messages
scan::TToken * token
current token pointer
bool peekIs(const types::TokenType &t)
Check if the current token's type matches.
scan::Scanner scanner
underlying scanner
bool peekIs(const std::string &s)
Check if the current token's value matches a string (case-insensitive).
XParser(const std::string &source)
Construct and scan the source text.
size_t index
current token index
bool next()
Advance to the next token; returns false at end of stream.
static std::string tokenTypeToString(types::TokenType t)
Convert a TokenType to a human-readable string.
OpType
Binary operator kinds.
ParseException(const std::string &msg)
Construct with an error message.
bool isBuiltinProcedure(const std::string &name)
Check if a name is a built-in procedure.
bool isAddOperator()
Check if current token is an additive operator.
std::unique_ptr< ASTNode > parseWithStatement()
Parse a with statement.
bool isType(const std::string &token)
Check if a string is a known type name.
PascalParser(const std::string &source)
Construct and prepare the parser.
bool match(const std::string &s)
Try to match and consume a token by value.
std::unique_ptr< ASTNode > parseTypeDeclaration()
Parse a type declaration section.
std::vector< std::unique_ptr< ASTNode > > parseStatementList()
Parse a list of statements (separated by semicolons).
void error(const std::string &message)
Report a parse error with the given message.
std::unique_ptr< ASTNode > parseVarDeclaration()
Parse a var declaration section.
std::unique_ptr< ASTNode > parseExpression()
Parse a full expression (simple expression with optional relational op).
std::unique_ptr< ASTNode > parseGotoStatement()
Parse a goto statement.
std::unique_ptr< ASTNode > parseProcedureDeclaration()
Parse a procedure declaration.
std::unique_ptr< ASTNode > parseParameter()
Parse a single formal parameter.
std::unique_ptr< ASTNode > parseTypeSpec()
Parse a type specifier.
void expectToken(const std::string &expected)
Consume a token matching the expected string, or throw.
void parseLabelDeclaration()
Parse a label declaration section (label 100, 200;).
std::unique_ptr< ProgramNode > parseProgram()
Parse a complete Pascal program and return the root AST node.
bool isKeyword(const std::string &s)
Check if a string is a reserved keyword.
std::string getAddOp()
Consume and return an additive operator string.
std::unique_ptr< ASTNode > parseRecordType()
Parse a record type definition.
std::string getUnaryOp()
Consume and return a unary operator string.
std::unique_ptr< ASTNode > parseForStatement()
Parse a for-to/downto-do statement.
BinaryOpNode::OpType getLogicalOperator(const std::string &op)
Map a logical operator string to BinaryOpNode::OpType.
std::unique_ptr< ASTNode > parseIfStatement()
Parse an if-then-else statement.
std::unique_ptr< ASTNode > parseSimpleExpression()
Parse a simple expression (terms combined by +, -, or).
bool isBuiltinFunction(const std::string &name)
Check if a name is a built-in function.
std::unique_ptr< ASTNode > parseConstDeclaration()
Parse a const declaration section.
std::vector< std::unique_ptr< ASTNode > > parseParameterList()
Parse a formal parameter list.
std::unique_ptr< ASTNode > parseAssignmentOrProcCall()
Parse an assignment or procedure call starting with an identifier.
std::unique_ptr< BlockNode > parseBlock()
Parse a block (declarations + compound statement).
std::unique_ptr< UnitNode > parseUnit()
Parse a Pascal unit and return the root AST node.
std::unique_ptr< ASTNode > parseProcedureForwardDecl()
Parse a procedure forward declaration (signature only, no body).
std::unordered_set< std::string > declaredLabels
Set of user-declared goto labels.
std::vector< std::unique_ptr< ASTNode > > parseArgumentList()
Parse a comma-separated argument list.
bool isUnitSource() const
Check if the source starts with a 'unit' keyword.
std::unique_ptr< ASTNode > parseArrayDeclaration(const std::string &varName)
Parse an array variable declaration.
bool isMulOperator()
Check if current token is a multiplicative operator.
std::vector< std::unique_ptr< ASTNode > > parseInterfaceDeclarations()
Parse interface forward declarations (procedure/function signatures only).
std::string tokenTypeToString(types::TokenType type)
Convert a TokenType to its display string.
std::unique_ptr< ASTNode > parseFunctionDeclaration()
Parse a function declaration.
std::vector< std::unique_ptr< ASTNode > > parseDeclarations()
Parse the declarations section.
std::unique_ptr< ASTNode > parseFunctionForwardDecl()
Parse a function forward declaration (signature only, no body).
std::unique_ptr< ASTNode > parseFunctionCall(const std::string &name)
Parse a function call given its already-parsed name.
void removeBraceComments()
Remove {brace} comments from the token stream.
std::unique_ptr< ASTNode > parseArrayType()
Parse an array type specification.
std::unique_ptr< ASTNode > parseCaseStatement()
Parse a case statement.
std::unique_ptr< ASTNode > parseLValue()
Parse an lvalue (variable, array access, pointer deref, field access).
std::string getMulOp()
Consume and return a multiplicative operator string.
BinaryOpNode::OpType getComparisonOperator(const std::string &op)
Map a comparison operator string to BinaryOpNode::OpType.
std::unique_ptr< ASTNode > parseProcedureCall(const std::string &name)
Parse a procedure call given its already-parsed name.
std::unique_ptr< ASTNode > parseFactor()
Parse a factor (literal, variable, function call, sub-expression).
std::unique_ptr< ASTNode > parseWhileStatement()
Parse a while-do statement.
mxx::TPValidator validator
semantic validator
BinaryOpNode::OpType getArithmeticOperator(const std::string &op)
Map an arithmetic operator string to BinaryOpNode::OpType.
std::unique_ptr< ASTNode > parseTerm()
Parse a term (factors combined by *, /, div, mod, and).
std::unique_ptr< ASTNode > parseRepeatStatement()
Parse a repeat-until statement.
std::string getRelationalOp()
Consume and return a relational operator string.
bool isArrayAccess()
Check if the current context is an array access.
std::unique_ptr< CompoundStmtNode > parseCompoundStatement()
Parse a compound statement (begin..end).
std::unique_ptr< ASTNode > parseStatement()
Parse a single statement.
bool isRelationalOperator()
Check if current token is a relational operator.
Lexical scanner that tokenizes source text.
token::Token< char > TToken
Default token type.
TokenType
Classification of scanned tokens.
@ TT_SYM
symbol / operator token
@ TT_ID
identifier or keyword
@ TT_NUM
decimal numeric literal
Lexical scanner that tokenizes source text into typed tokens.
AST node hierarchy for the Pascal-to-MXVM frontend parser.
Semantic validator for Pascal programs — scope, type, and declaration checking.