EMath++
Classes for mathematical concepts
Loading...
Searching...
No Matches
eparser.h
Go to the documentation of this file.
1
9#ifndef EPARSER_H
10#define EPARSER_H
11#include <string>
12#include "emath.h"
13#pragma once
19namespace emthp {
24 enum TokenType {
48 T_EOF
49 };
54 struct Token {
55 public:
63 double value;
64 };
70 class Lexer {
71 public:
76 Lexer(const std::string& input) noexcept;
82 Lexer& operator =(const Lexer& ogn) noexcept;
87 Token next() noexcept;
91 void back() noexcept;
92 private:
96 std::string _input;
100 long unsigned int _pos;
105 double read_number() noexcept;
111 static std::string clean(const std::string& input) noexcept;
118 static constexpr inline bool is_digit(const char& c) noexcept {return ((c >= '0' && c <= '9') || c == '.');}
119 };
125 class Parser {
126 public:
131 Parser(const std::string& input) noexcept;
137 Parser& operator =(const Parser& ogn) noexcept;
148 private:
152 Lexer _lexer;
157 double parse_number() noexcept;
158 };
159}
160#endif
Class for representing and operating monomials.
Definition: emath.h:187
Class for representing and operating polynomials.
Definition: emath.h:392
Class that works as a token supplier for the Parser class.
Definition: eparser.h:70
void back() noexcept
Backtrack function that moves the cursor's position one position backwards.
Definition: eparser.cpp:52
Lexer & operator=(const Lexer &ogn) noexcept
Assigment operator for when called with an lvalue.
Definition: eparser.cpp:20
Token next() noexcept
Function that returns the next Token in the input provided in the constructor.
Definition: eparser.cpp:29
Class that wraps a std::string and parses it as a Monomial or as a Polynomial.
Definition: eparser.h:125
emth::Monomial parse_monomial() noexcept
Function that parses the next Monomial in the input.
Definition: eparser.cpp:113
emth::Polynomial parse_polynomial() noexcept
Function that parses the input as a Polynomial.
Definition: eparser.cpp:105
Parser & operator=(const Parser &ogn) noexcept
Assigment operator for when called with an lvalue.
Definition: eparser.cpp:100
This is the main header file for the emath library.
Englobes all the classes and functions of the parser.
TokenType
Enum with all the possible Token types.
Definition: eparser.h:24
@ T_EOF
EOF type.
Definition: eparser.h:48
@ T_MINUS
Minus sign type.
Definition: eparser.h:32
@ T_VARIABLE
X type.
Definition: eparser.h:40
@ T_EXPONENT
Exponent sign type.
Definition: eparser.h:44
@ T_PLUS
Plus sign type.
Definition: eparser.h:28
@ T_NUMBER
Number type.
Definition: eparser.h:36
Struct for representing a token as a type and a value.
Definition: eparser.h:54
double value
The token's numerical value as a double.
Definition: eparser.h:63
TokenType type
The token's type as a TokenType.
Definition: eparser.h:59