teditor  1.8.0@@fee5e94
Terminal based editor written in C++
calc/parser.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "core/parser/scanner.h"
4 #include "core/parser/lexer.h"
5 #include <unordered_map>
6 #include "number.h"
7 #include <string>
8 #include <stack>
9 #include <vector>
10 #include <memory>
11 
12 namespace teditor {
13 namespace calc {
14 
15 typedef std::unordered_map<std::string, Num64> VarMap;
16 typedef std::stack<Num64> NumStack;
17 
19 struct Parser {
20  void evaluate(const std::string& expr, VarMap& vars);
21 
22  private:
23  bool lexingDone(const parser::Token& tok);
24  Num64 computeBinaryOp(const Num64& a, const Num64& b, uint32_t op);
25  Num64 computeUnaryFunc(const Num64& a, const std::string& func);
26  bool isBinaryOp(uint32_t id);
27  bool isUnaryFunc(uint32_t id);
28  void evaluateExpr(parser::Scanner *sc, VarMap& vars, NumStack& stack);
29 }; // struct Parser
30 
31 } // namespace calc
32 } // namespace teditor
teditor::todo::CalendarItem::end
TimePoint end
Definition: todo/objects.h:23
teditor::ledger::Space
@ Space
Definition: ledger/parser.cpp:20
teditor::calc::Parser::evaluate
void evaluate(const std::string &expr, VarMap &vars)
Definition: calc/parser.cpp:57
teditor::ledger::Parser::topAccounts
Accounts topAccounts(bool sort=true) const
Computes balances of only the top-level accounts. Top-level account is the account name that preceeds...
Definition: ledger/parser.cpp:134
teditor::todo::CalendarItem::start
TimePoint start
Definition: todo/objects.h:21
teditor::parser::Regexs::Integer
static const std::string Integer
integer
Definition: regexs.h:13
teditor::Buffer::load
virtual void load(const std::string &file, int line=0)
Definition: buffer.cpp:333
teditor::todo::RepeatType
RepeatType
Definition: todo/objects.h:10
teditor::split
Strings split(const std::string &str, char delim)
Definition: utils.cpp:48
teditor::parser::Regexs::Newline
static const std::string Newline
newline (windows as well as unix)
Definition: regexs.h:16
teditor::ledger::Tokens
Tokens
Definition: ledger/parser.cpp:14
teditor::calc::Plus
@ Plus
Definition: calc/parser.cpp:19
teditor::calc::getLexer
parser::Lexer & getLexer()
Definition: calc/parser.cpp:29
teditor::todo::CalendarItem::hasStart
bool hasStart
Definition: todo/objects.h:22
teditor::calc::VarMap
std::unordered_map< std::string, Num64 > VarMap
Definition: extensions/calc/mode.h:9
std::sq
T sq(T in)
Definition: number.h:9
teditor::calc::IVal
@ IVal
Definition: calc/parser.cpp:13
teditor::ledger::Account
Definition: ledger/objects.h:18
teditor::todo::CalendarItem::description
std::string description
Definition: todo/objects.h:26
teditor::calc::FVal
@ FVal
Definition: calc/parser.cpp:14
teditor::calc::Number
Core number used for computing in the calculator.
Definition: number.h:76
teditor::parser::Token::isEof
bool isEof() const
Definition: parse_tree.h:25
teditor::calc::toFloat
Number< I, F > toFloat(const Number< I, F > &a)
Definition: number.h:256
std::cube
T cube(T in)
Definition: number.h:10
teditor::calc::SemiColon
@ SemiColon
Definition: calc/parser.cpp:26
teditor::parser::Token::type
uint32_t type
Definition: parse_tree.h:19
teditor::todo::Date
@ Date
Definition: todo/parser.cpp:18
regexs.h
teditor::ledger::AccountDescription
@ AccountDescription
Definition: ledger/parser.cpp:22
teditor::todo::getLexer
parser::Lexer & getLexer()
Definition: todo/parser.cpp:25
teditor::todo::Tokens
Tokens
Definition: todo/parser.cpp:15
teditor::ledger::Parser::minmaxDates
void minmaxDates(TimePoint &min, TimePoint &max) const
Definition: ledger/parser.cpp:177
teditor::str2double
double str2double(const std::string &str)
Definition: utils.cpp:87
teditor::calc::Mul
@ Mul
Definition: calc/parser.cpp:21
teditor::todo::Keywords
@ Keywords
Definition: todo/parser.cpp:17
teditor::ledger::Date
@ Date
Definition: ledger/parser.cpp:17
teditor::todo::Space
@ Space
Definition: todo/parser.cpp:22
teditor::calc::toInt
Number< I, F > toInt(const Number< I, F > &a)
Definition: number.h:254
parser.h
teditor::join
std::string join(const Strings &s, char delim, int start, int end)
Definition: utils.cpp:56
teditor::calc::Div
@ Div
Definition: calc/parser.cpp:22
teditor::todo::strToRepeatType
RepeatType strToRepeatType(const std::string &str)
Definition: objects.cpp:11
teditor::parser::Token::end
Point end
Definition: parse_tree.h:23
teditor::parser::Regexs::DateTime
static const std::string DateTime
date/time regex
Definition: regexs.h:19
teditor::todo::String
@ String
Definition: todo/parser.cpp:19
teditor::calc::Space
@ Space
Definition: calc/parser.cpp:25
teditor::parser::Lexer
Definition: lexer.h:28
teditor::ledger::Parser::reload
void reload()
Definition: ledger/parser.cpp:128
teditor::parser::StringScanner
Definition: scanner.h:21
teditor::ledger::Newline
@ Newline
Definition: ledger/parser.cpp:19
teditor::parser::Token
Definition: parse_tree.h:13
teditor::calc::Equals
@ Equals
Definition: calc/parser.cpp:18
teditor::parser::Token::Unknown
static const uint32_t Unknown
Definition: parse_tree.h:30
teditor::parser::Token::End
static const uint32_t End
Definition: parse_tree.h:28
ASSERT
#define ASSERT(check, fmt,...)
Macro to assert with runtime_error exception if the check fails.
Definition: utils.h:35
teditor::ledger::Accounts::find
Account & find(const std::string &a)
Definition: ledger/objects.h:54
teditor::calc::NumStack
std::stack< Num64 > NumStack
Definition: calc/parser.h:16
teditor::todo::CalendarItem::clear
void clear()
Definition: objects.cpp:31
teditor::isAbs
bool isAbs(const std::string &file)
Definition: file_utils.cpp:116
teditor::TimePoint
std::chrono::system_clock::time_point TimePoint
Definition: time_utils.h:7
teditor::calc::Parser
Definition: calc/parser.h:19
buffer.h
teditor::parser::Regexs::FloatingPt
static const std::string FloatingPt
floating point number
Definition: regexs.h:12
teditor::todo::CalendarItem::repeat
RepeatType repeat
Definition: todo/objects.h:25
teditor::ledger::getLexer
parser::Lexer & getLexer()
Definition: ledger/parser.cpp:26
teditor::parser::BufferScanner
Definition: scanner.h:36
teditor::ledger::Accounts
Definition: ledger/objects.h:52
lexer.h
teditor::parser::Scanner
Definition: scanner.h:11
time_utils.h
teditor::calc::BrktClose
@ BrktClose
Definition: calc/parser.cpp:16
teditor::timeFromStr
TimePoint timeFromStr(const std::string &dt)
Definition: time_utils.cpp:50
teditor::ledger::Parser::allAccounts
Accounts allAccounts(bool sort=true) const
Computes balances of the top-level accounts as well as all accounts.
Definition: ledger/parser.cpp:149
parser.h
teditor::rel2abs
std::string rel2abs(const std::string &pwd, const std::string &rel)
Definition: file_utils.cpp:118
teditor::calc::Var
@ Var
Definition: calc/parser.cpp:17
teditor::calc::Tokens
Tokens
Definition: calc/parser.cpp:12
teditor::calc::Exp
@ Exp
Definition: calc/parser.cpp:23
teditor::todo::Newline
@ Newline
Definition: todo/parser.cpp:21
teditor::ledger::Name
@ Name
Definition: ledger/parser.cpp:16
teditor::ledger::Aliases
std::set< std::string > Aliases
Definition: ledger/objects.h:15
teditor::ledger::Comment
@ Comment
Definition: ledger/parser.cpp:15
teditor::ledger::Account::rawBalance
int64_t rawBalance() const
Definition: ledger/objects.h:31
parser.h
teditor::calc::vars
VarMap & vars()
Definition: extensions/calc/mode.cpp:11
teditor::todo::Comment
@ Comment
Definition: todo/parser.cpp:16
teditor::calc::Func
@ Func
Definition: calc/parser.cpp:24
scanner.h
teditor::parser::Regexs::Variable
static const std::string Variable
variable names in a program
Definition: regexs.h:15
teditor::calc::Minus
@ Minus
Definition: calc/parser.cpp:20
teditor::todo::CalendarItem::hasEnd
bool hasEnd
Definition: todo/objects.h:24
teditor::getpwd
std::string getpwd()
Definition: file_utils.cpp:107
teditor::calc::BrktOpen
@ BrktOpen
Definition: calc/parser.cpp:15
teditor::ledger::Number
@ Number
Definition: ledger/parser.cpp:18
teditor::ledger::AccountAlias
@ AccountAlias
Definition: ledger/parser.cpp:23
teditor::calc::Num64
Number< int64_t, double > Num64
Definition: number.h:272
number.h
teditor::parser::Token::start
Point start
Definition: parse_tree.h:21
teditor::Buffer
Definition: buffer.h:25
teditor::ledger::AccountStart
@ AccountStart
Definition: ledger/parser.cpp:21
teditor
Definition: any.hpp:10
teditor::ledger::Parser::Parser
Parser(const std::string &f)
Definition: ledger/parser.cpp:42