GSC Interpreter
A Turing-complete interpreter developed for a compiler course
|
Parser module for the GSC programming language. More...
#include <parser.hpp>
Classes | |
struct | ParseError |
Public Member Functions | |
Parser (const std::vector< Token > &tokens) | |
Constructs a Parser object. | |
std::vector< std::shared_ptr< Stmt > > | parse () |
Parses the tokens and returns a vector of statements. | |
Private Member Functions | |
std::vector< std::shared_ptr< Stmt > > | block () |
std::shared_ptr< Stmt > | declaration () |
std::shared_ptr< Stmt > | statement () |
std::shared_ptr< Stmt > | printStatement () |
std::shared_ptr< Stmt > | ifStatement () |
std::shared_ptr< Stmt > | whileStatement () |
std::shared_ptr< Stmt > | forStatement () |
std::shared_ptr< Stmt > | varDeclaration () |
std::shared_ptr< Stmt > | expressionStatement () |
std::shared_ptr< Expr > | assignment () |
std::shared_ptr< Expr > | orLogical () |
std::shared_ptr< Expr > | andLogical () |
std::shared_ptr< Expr > | expression () |
std::shared_ptr< Expr > | equality () |
std::shared_ptr< Expr > | comparison () |
std::shared_ptr< Expr > | term () |
std::shared_ptr< Expr > | factor () |
std::shared_ptr< Expr > | unary () |
std::shared_ptr< Expr > | primary () |
template<class... T> | |
bool | match (T... types) |
bool | check (TokenType type) const |
bool | isAtEnd () const |
Token | consume (TokenType type, std::string_view message) |
Token | advance () |
Token | peek () const |
Token | previous () const |
ParseError | error (const Token &token, std::string_view message) |
void | synchronize () |
Private Attributes | |
const std::vector< Token > & | tokens |
int | current = 0 |
Parser module for the GSC programming language.
Parser is responsible for parsing the tokens generated by the Scanner and constructing an abstract syntax tree (AST) from them.
Definition at line 16 of file parser.hpp.
Parser::Parser | ( | const std::vector< Token > & | tokens | ) |
Constructs a Parser object.
tokens | The vector of tokens to parse. |
Definition at line 5 of file parser.cpp.
|
private |
Definition at line 286 of file parser.cpp.
|
private |
Definition at line 163 of file parser.cpp.
|
private |
Definition at line 133 of file parser.cpp.
|
private |
Definition at line 122 of file parser.cpp.
|
private |
Definition at line 269 of file parser.cpp.
|
private |
Definition at line 189 of file parser.cpp.
Definition at line 279 of file parser.cpp.
|
private |
Definition at line 16 of file parser.cpp.
|
private |
Definition at line 177 of file parser.cpp.
|
private |
Definition at line 299 of file parser.cpp.
|
private |
Definition at line 175 of file parser.cpp.
|
private |
Definition at line 116 of file parser.cpp.
|
private |
Definition at line 214 of file parser.cpp.
|
private |
Definition at line 69 of file parser.cpp.
|
private |
Definition at line 48 of file parser.cpp.
|
private |
Definition at line 275 of file parser.cpp.
|
private |
Definition at line 257 of file parser.cpp.
|
private |
Definition at line 151 of file parser.cpp.
std::vector< std::shared_ptr< Stmt > > Parser::parse | ( | ) |
Parses the tokens and returns a vector of statements.
This function processes the tokens and constructs an abstract syntax tree (AST) represented as a vector of statements.
Definition at line 7 of file parser.cpp.
|
private |
Definition at line 292 of file parser.cpp.
|
private |
Definition at line 294 of file parser.cpp.
|
private |
Definition at line 236 of file parser.cpp.
|
private |
Definition at line 42 of file parser.cpp.
|
private |
Definition at line 27 of file parser.cpp.
|
private |
Definition at line 304 of file parser.cpp.
|
private |
Definition at line 202 of file parser.cpp.
|
private |
Definition at line 226 of file parser.cpp.
|
private |
Definition at line 104 of file parser.cpp.
|
private |
Definition at line 60 of file parser.cpp.
|
private |
Definition at line 32 of file parser.hpp.
|
private |
Definition at line 31 of file parser.hpp.