1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
#ifndef Parser_h_included
#define Parser_h_included
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include "../rulevalue/_rulevalue.h"
// $insert baseclass
#include "parserbase.h"
// $insert scanner.h
#include "../scanner/scanner.h"
#undef Parser
class Parser: public ParserBase
{
public:
using FunctionMap = std::map<std::string, RuleValue::Function>;
using DoubleMap = std::map<std::string, double>;
private:
enum AngleType
{
RADIANS,
DEG360,
DEG400
};
using SymbolMap = std::map<std::string, size_t>;
struct ShowVar
{
std::vector<RuleValue> &d_value;
ShowVar(std::vector<RuleValue> &value);
void operator()(SymbolMap::value_type &v);
};
// $insert scannerobject
Scanner d_scanner;
std::string d_lastIdent;
AngleType d_angleType;
bool d_error;
SymbolMap d_symtab;
std::vector<RuleValue> d_value;
static FunctionMap s_functions;
static DoubleMap s_doubles;
public:
Parser();
int parse();
private:
RuleValue call(RuleValue const &funName, RuleValue &argv);
void error(); // called on (syntax) errors
// called on semantic errors
void error(bool ifTrue, char const *msg);
int lex(); // returns the next token from the
// lexical scanner.
void print(); // use, e.g., d_token, d_loc
RuleValue &addArg(RuleValue &argv, RuleValue &arg);
double angle(double radians);
RuleValue &assign(RuleValue &lvalue, int operation,
RuleValue const &rvalue);
RuleValue binary(RuleValue lvalue, int operation,
RuleValue const &rvalue);
void display(RuleValue const &e);
void div0(RuleValue const &vl, RuleValue const &vr);
RuleValue firstArg(RuleValue &rv);
RuleValue function(RuleValue const &fun, RuleValue const &e);
RuleValue function(RuleValue const &fun,
RuleValue const &arg1, RuleValue const &arg2);
void integral(RuleValue const &v1);
void help();
void integral(RuleValue const &v1, RuleValue const &v2);
void list();
RuleValue &lvalue(RuleValue &e);
RuleValue mathConst();
void prompt();
double radians(double angle);
RuleValue const &rvalue(RuleValue const &e) const;
void setAngleType();
RuleValue setDataType();
RuleValue setFunction();
void storeIdent();
RuleValue unary(int operation, RuleValue const &e);
RuleValue newValue(int typeToken);
RuleValue variable();
RuleValue identValue();
// support functions for parse():
void executeAction_(int ruleNr);
void errorRecovery_();
void nextCycle_();
void nextToken_();
void print_();
void exceptionHandler(std::exception const &exc);
};
inline Parser::Parser()
:
d_value(1)
{}
#endif
|