botanist  v0.1.0
Loading...
Searching...
No Matches
tokenizer.hpp
Go to the documentation of this file.
1
4
5#ifndef BOTANIST_TOKENIZER_H
6#define BOTANIST_TOKENIZER_H
7
8#include <ctype.h>
9#include <stddef.h>
10#include <stdint.h>
11#include <string.h>
12
13#include <collection2/list.hpp>
14
15#include "token.hpp"
16
17namespace botanist {
18
20class Tokenizer final {
21 private:
23 collection2::List<Token>& tokenList;
24
26 bool isLastTokenizationSucceeded = false;
27
33 void initialize();
34
44 bool tryParse(char const* str, Token::Kind& kind, size_t& length) const;
45
55 size_t tryParseAsNumber(char const* str) const;
56
66 size_t tryParseAsOperator(char const* str) const;
67
76 size_t tryParseAsBracket(char const* str) const;
77
78 public:
79 explicit Tokenizer(collection2::List<Token>& tokenList) : tokenList(tokenList){};
80
88 size_t tokenize(const char* formula);
89
90#ifndef HEADLESS
91
97 void dumpTokenList(bool colorlized = true) const;
98
99#else
100 void dumpTokenList(bool colorlized = true) const = delete;
101#endif
102};
103
104} // namespace botanist
105
106#endif /* BOTANIST_TOKENIZER_H */
数式を項や演算子、括弧など意味のある単位に分割する
Definition: tokenizer.hpp:20
size_t tokenize(const char *formula)
与えられた数式を、数値や演算子、括弧等のトークンに分割する
void dumpTokenList(bool colorlized=true) const
トークンリストのダンプ
Kind
トークンの種類
Definition: token.hpp:16
数式トークン