amath
1.8.5
Simple command line calculator
|
Encapsulates a recursive descent parser. More...
#include <parser.h>
Public Member Functions | |
Parser (const char *input) | |
~Parser () | |
SyntaxNode * | Parse () |
Parses the input into a syntax tree. More... | |
Private Member Functions | |
SyntaxNode * | ParseDefault () |
SyntaxNode * | TryParseStatement () |
SyntaxNode * | ParseStatement () |
SyntaxNode * | ParseEvaluation () |
ExpressionNode * | ParseExpression () |
ExpressionNode * | ParseAddSubstract () |
ExpressionNode * | ParseFactor () |
ExpressionNode * | ParsePower () |
ExpressionNode * | ParseUnary () |
ExpressionNode * | ParseAtomic () |
ExpressionNode * | ParseIdent () |
ExpressionNode * | ParseNumber () |
SyntaxNode * | ParseFunctionDef () |
SyntaxNode * | ParseHelpStatement () |
SyntaxNode * | ParseDeleteStatement () |
SyntaxNode * | ParseListStatement () |
SyntaxNode * | ParseFileStatement () |
SyntaxNode * | ParseNumeralStatement () |
SyntaxNode * | ParseDigistStatement () |
SyntaxNode * | ParseDrawStatement () |
SyntaxNode * | ParsePromptStatement () |
SyntaxNode * | ParsePrefsStatement () |
void | GetToken () |
void | PutToken () |
bool | Expect (Symbol symbol) |
Token * | Peek () const |
Private Attributes | |
Lexer * | lexer |
Token * | token |
int | syntaxError |
ErrorNode * | errorNode |
Encapsulates a recursive descent parser.
More info on recursive descent parsers is available at Wikipedia: https://wikipedia.org/wiki/Recursive_descent_parser
|
explicit |
Definition at line 43 of file parser.cpp.
References errorNode, Lexer::Lexer(), lexer, syntaxError, and token.
Referenced by Evaluator::Evaluate(), ExecuteStatement::Execute(), LoadStatement::Execute(), and PreferencesBase::SetPrefs().
Parser::~Parser | ( | ) |
Definition at line 51 of file parser.cpp.
References lexer.
Definition at line 519 of file parser.cpp.
References Token::GetPos(), GetToken(), Token::symbol, syntaxError, and token.
Referenced by ParseAtomic(), ParseDefault(), ParseDeleteStatement(), ParseDrawStatement(), ParseFileStatement(), ParseFunctionDef(), and ParseIdent().
|
private |
Definition at line 494 of file parser.cpp.
References Lexer::GetFirstToken(), Token::GetNextToken(), lexer, and token.
Referenced by Expect(), Parse(), ParseAddSubstract(), ParseAtomic(), ParseDeleteStatement(), ParseDigistStatement(), ParseFactor(), ParseHelpStatement(), ParseIdent(), ParseListStatement(), ParseNumber(), ParseNumeralStatement(), ParsePower(), ParsePrefsStatement(), ParsePromptStatement(), ParseStatement(), ParseUnary(), and TryParseStatement().
SyntaxNode * Parser::Parse | ( | ) |
Parses the input into a syntax tree.
Definition at line 56 of file parser.cpp.
References StatementBlockNode::Add(), EmptyStatement::EmptyStatement(), ErrorNode::ErrorNode(), Lexer::GetInput(), Token::GetPos(), GetToken(), lexer, PutToken(), StatementBlockNode::StatementBlockNode(), Token::symbol, symdelimiter, symend, token, Lexer::Tokenize(), and TryParseStatement().
Referenced by Evaluator::Evaluate(), ExecuteStatement::Execute(), LoadStatement::Execute(), and PreferencesBase::SetPrefs().
|
private |
Definition at line 283 of file parser.cpp.
References AdditionNode::AdditionNode(), GetToken(), ParseFactor(), PutToken(), SubtractionNode::SubtractionNode(), Token::symbol, symminus, symplus, and token.
Referenced by ParseExpression().
|
private |
Definition at line 362 of file parser.cpp.
References AbsoluteNode::AbsoluteNode(), ComplexiNode::ComplexiNode(), EulersNumberNode::EulersNumberNode(), Expect(), FactorialNode::FactorialNode(), Token::GetPos(), GetToken(), InsVariableNode::InsVariableNode(), NumericValueNode::NumericValueNode(), ParseExpression(), ParseIdent(), ParseNumber(), Peek(), PiNode::PiNode(), symabsolute, Token::symbol, syme, symfactorial, symi, symident, symins, symlparen, symnumber, sympi, symrparen, syntaxError, and token.
Referenced by ParseUnary().
|
private |
Definition at line 237 of file parser.cpp.
References errorNode, Expect(), ParseEvaluation(), ParseFunctionDef(), symassign, symident, symlparen, symrparen, syntaxError, and token.
Referenced by ParseStatement().
|
private |
Definition at line 582 of file parser.cpp.
References DeleteStatement::DeleteStatement(), Expect(), Token::GetPos(), Token::GetText(), GetToken(), PutToken(), Token::symbol, symfunction, symident, symlparen, symrparen, symvariable, syntaxError, and token.
Referenced by ParseStatement().
|
private |
Definition at line 713 of file parser.cpp.
References DecimalSystem::DecimalSystem(), DigitsStatement::DigitsStatement(), errorNode, ErrorNode::ErrorNode(), Lexer::GetInput(), Number::GetIntegerValue(), Token::GetPos(), Token::GetText(), GetToken(), lexer, NumeralSystem::Parse(), PutToken(), Token::symbol, symdelimiter, symend, symnumber, syntaxError, and token.
Referenced by ParseStatement().
|
private |
Definition at line 772 of file parser.cpp.
References DrawStatement::DrawStatement(), Expect(), Token::GetText(), PlotStatement::PlotStatement(), Token::symbol, symident, symlparen, symplot, symrparen, and token.
Referenced by ParseStatement().
|
private |
Definition at line 261 of file parser.cpp.
References EvalStatement::EvalStatement(), ExpressionNode::IsSilent(), ParseExpression(), and SilentStatement::SilentStatement().
Referenced by ParseDefault().
|
private |
Definition at line 278 of file parser.cpp.
References ParseAddSubstract().
Referenced by ParseAtomic(), ParseEvaluation(), ParseFunctionDef(), ParseIdent(), and ParseStatement().
|
private |
Definition at line 306 of file parser.cpp.
References DivisionNode::DivisionNode(), GetToken(), MultiplicationNode::MultiplicationNode(), ParsePower(), PutToken(), Token::symbol, symslash, symtimes, and token.
Referenced by ParseAddSubstract().
|
private |
Definition at line 627 of file parser.cpp.
References ErrorNode::ErrorNode(), ExecuteStatement::ExecuteStatement(), Expect(), Lexer::GetInput(), Token::GetPos(), Token::GetText(), lexer, LoadStatement::LoadStatement(), SaveStatement::SaveStatement(), ShowStatement::ShowStatement(), Token::symbol, symexecute, symload, symqident, symsave, symshow, and token.
Referenced by ParseStatement().
|
private |
Definition at line 535 of file parser.cpp.
References UserFunction::CreateVariable(), errorNode, ErrorNode::ErrorNode(), Expect(), FunctionDefinitionNode::FunctionDefinitionNode(), Program::Functions, FunctionList::GetFunctionDef(), Lexer::GetInput(), Token::GetPos(), Token::GetText(), VariableList::InsertTemporaryVariable(), FunctionList::IsSystemFunction(), lexer, ParseExpression(), VariableList::RemoveTemporaryVariable(), UserFunction::SetExpression(), symassign, symident, symlparen, symrparen, token, and Program::Variables.
Referenced by ParseDefault(), and ParseStatement().
|
private |
Definition at line 566 of file parser.cpp.
References Token::GetText(), GetToken(), HelpStatement::HelpStatement(), PutToken(), Token::symbol, symdelimiter, symend, symident, and token.
Referenced by ParseStatement().
|
private |
Definition at line 416 of file parser.cpp.
References AssignmentNode::AssignmentNode(), VariableList::CreateVariable(), errorNode, ErrorNode::ErrorNode(), Expect(), Program::Functions, FunctionList::GetFunctionCall(), Lexer::GetInput(), Token::GetPos(), Token::GetText(), GetToken(), VariableList::GetVariable(), lexer, NumericValueNode::NumericValueNode(), ParseExpression(), PutToken(), symassign, Token::symbol, symlparen, symrparen, token, VariableNode::VariableNode(), and Program::Variables.
Referenced by ParseAtomic().
|
private |
Definition at line 611 of file parser.cpp.
References Token::GetPos(), Token::GetText(), GetToken(), ListStatement::ListStatement(), PutToken(), Token::symbol, symdelimiter, symend, symqident, syntaxError, and token.
Referenced by ParseStatement().
|
private |
Definition at line 469 of file parser.cpp.
References ComplexNumber::ComplexNumber(), Number::GetRealValue(), Token::GetText(), GetToken(), Program::Input, NumericValueNode::NumericValueNode(), NumeralSystem::Parse(), PutToken(), Token::symbol, symi, and token.
Referenced by ParseAtomic().
|
private |
Definition at line 652 of file parser.cpp.
References DecimalSystem::DecimalSystem(), errorNode, ErrorNode::ErrorNode(), Lexer::GetInput(), Number::GetIntegerValue(), Token::GetPos(), Token::GetText(), GetToken(), InputStatement::InputStatement(), lexer, OutputStatement::OutputStatement(), NumeralSystem::Parse(), PutToken(), symbin, Token::symbol, symdec, symdelimiter, symend, symhex, syminput, symnumber, symoct, syntaxError, and token.
Referenced by ParseStatement().
|
private |
Definition at line 329 of file parser.cpp.
References GetToken(), ParseUnary(), PowerNode::PowerNode(), PutToken(), Token::symbol, sympower, and token.
Referenced by ParseFactor().
|
private |
Definition at line 760 of file parser.cpp.
References GetToken(), PrefsStatement::PrefsStatement(), PutToken(), Token::symbol, symload, symsave, and token.
Referenced by ParseStatement().
|
private |
Definition at line 748 of file parser.cpp.
References Token::GetText(), GetToken(), PromptStatement::PromptStatement(), PutToken(), Token::symbol, symqident, and token.
Referenced by ParseStatement().
|
private |
Definition at line 156 of file parser.cpp.
References AboutStatement::AboutStatement(), ClearStatement::ClearStatement(), EvalStatement::EvalStatement(), ExitStatement::ExitStatement(), GetToken(), LicenseStatement::LicenseStatement(), ListFunctionsStatement::ListFunctionsStatement(), ListVariablesStatement::ListVariablesStatement(), MemoryStatement::MemoryStatement(), ParseDefault(), ParseDeleteStatement(), ParseDigistStatement(), ParseDrawStatement(), ParseExpression(), ParseFileStatement(), ParseFunctionDef(), ParseHelpStatement(), ParseListStatement(), ParseNumeralStatement(), ParsePrefsStatement(), ParsePromptStatement(), PutToken(), symabout, Token::symbol, symclear, symdef, symdelete, symdigits, symdraw, symeval, symexecute, symexit, symfunction, symhelp, syminput, symlicense, symlist, symload, symmem, symoutput, symplot, symprefs, symprompt, symsave, symshow, symvariable, symversion, token, and VersionStatement::VersionStatement().
Referenced by TryParseStatement().
|
private |
Definition at line 344 of file parser.cpp.
References GetToken(), ParseAtomic(), PutToken(), Token::symbol, symminus, token, and UnaryNode::UnaryNode().
Referenced by ParsePower().
|
private |
Definition at line 506 of file parser.cpp.
References Lexer::GetFirstToken(), Token::GetNextToken(), lexer, and token.
Referenced by ParseAtomic().
|
private |
Definition at line 514 of file parser.cpp.
References Token::GetLastToken(), and token.
Referenced by Parse(), ParseAddSubstract(), ParseDeleteStatement(), ParseDigistStatement(), ParseFactor(), ParseHelpStatement(), ParseIdent(), ParseListStatement(), ParseNumber(), ParseNumeralStatement(), ParsePower(), ParsePrefsStatement(), ParsePromptStatement(), ParseStatement(), ParseUnary(), and TryParseStatement().
|
private |
Definition at line 124 of file parser.cpp.
References errorNode, ErrorNode::ErrorNode(), Lexer::GetInput(), GetToken(), lexer, ParseStatement(), PutToken(), Token::symbol, symdelimiter, symend, syntaxError, and token.
Referenced by Parse().
|
private |
Definition at line 69 of file parser.h.
Referenced by ParseDefault(), ParseDigistStatement(), ParseFunctionDef(), ParseIdent(), ParseNumeralStatement(), Parser(), and TryParseStatement().
|
private |
Definition at line 65 of file parser.h.
Referenced by GetToken(), Parse(), ParseDigistStatement(), ParseFileStatement(), ParseFunctionDef(), ParseIdent(), ParseNumeralStatement(), Parser(), Peek(), TryParseStatement(), and ~Parser().
|
private |
Definition at line 68 of file parser.h.
Referenced by Expect(), ParseAtomic(), ParseDefault(), ParseDeleteStatement(), ParseDigistStatement(), ParseListStatement(), ParseNumeralStatement(), Parser(), and TryParseStatement().
|
private |
Definition at line 66 of file parser.h.
Referenced by Expect(), GetToken(), Parse(), ParseAddSubstract(), ParseAtomic(), ParseDefault(), ParseDeleteStatement(), ParseDigistStatement(), ParseDrawStatement(), ParseFactor(), ParseFileStatement(), ParseFunctionDef(), ParseHelpStatement(), ParseIdent(), ParseListStatement(), ParseNumber(), ParseNumeralStatement(), ParsePower(), ParsePrefsStatement(), ParsePromptStatement(), Parser(), ParseStatement(), ParseUnary(), Peek(), PutToken(), and TryParseStatement().