NewLang Project
Yet another programm language
Loading...
Searching...
No Matches
lexer.h
Go to the documentation of this file.
1#ifndef NEWLANG_LEXER_H_INCLUDED_
2#define NEWLANG_LEXER_H_INCLUDED_
3
4
5
6
7//#define YY_FATAL_ERROR(msg) newlang::Scanner::FatalError(msg, lineno(), yyleng, *source_string)
8// Flex expects the signature of yylex to be defined in the macro YY_DECL, and
9// the C++ parser expects it to be declared. We can factor both as follows.
10
11#define YY_USER_INIT m_loc = yylloc
12
13#define YY_DECL \
14 newlang::parser::token_type \
15 newlang::Scanner::lex( \
16 TermPtr * yylval, \
17 newlang::parser::location_type* yylloc \
18 )
19
20#ifndef __FLEX_LEXER_H
21#define yyFlexLexer NewLangFlexLexer
22#include "FlexLexer.h"
23#undef yyFlexLexer
24#endif
25
26#include "term.h"
27#include "parser.h"
28
29namespace newlang {
30
36 class Scanner : public NewLangFlexLexer {
37 public:
41 Scanner(std::istream* arg_yyin = &std::cin,
42 std::ostream* arg_yyout = &std::cout,
43 SourceType source = nullptr);
44
46 virtual ~Scanner();
47
50 parser::location_type* m_loc;
51 std::string buffer;
52
53 // struct BufferDataType {
54 // SourceType data;
55 // std::istringstream *iss;
56 // parser::location_type loc;
57 // };
58 // std::vector<BufferDataType> m_data;
59
61 std::istringstream *m_macro_iss;
62 parser::location_type m_macro_loc;
63
67
68 static BlockType ParseLexem(const std::string str);
69
70 void ApplyDiags(DiagPtr diag = nullptr);
71
77
81 virtual parser::token_type lex(
83 parser::location_type* yylloc
84 );
85
87 void set_debug(bool b);
88
89 void LexerError(const char* msg) override {
90 LOG_RUNTIME("%s", newlang::ParserMessage(buffer, m_loc->begin.line, m_loc->begin.column, "%s", msg).c_str());
91 // LOG_RUNTIME("%s near \'%s\' at line %d", msg, position, line);
92 }
93 };
94
95}
96
97#endif // NEWLANG_LEXER_H_INCLUDED_
Scanner(std::istream *arg_yyin=&std::cin, std::ostream *arg_yyout=&std::cout, SourceType source=nullptr)
Definition lexer.cpp:6
void ApplyDiags(DiagPtr diag=nullptr)
Definition lexer.cpp:33
size_t m_macro_del
Definition lexer.h:65
virtual ~Scanner()
Definition lexer.cpp:15
SourceType source_base
Definition lexer.h:48
void set_debug(bool b)
SourceType m_macro_data
Definition lexer.h:60
SourceType source_string
Definition lexer.h:49
int m_bracket_depth
Definition lexer.h:76
bool m_ignore_indent
Definition lexer.h:73
bool m_ignore_crlf
Definition lexer.h:75
void LexerError(const char *msg) override
Definition lexer.h:89
std::istringstream * m_macro_iss
Definition lexer.h:61
parser::location_type m_macro_loc
Definition lexer.h:62
TermPtr m_macro_body
Definition lexer.h:66
std::string buffer
Definition lexer.h:51
bool m_ignore_space
Definition lexer.h:72
size_t m_macro_count
Definition lexer.h:64
bool m_ignore_comment
Definition lexer.h:74
parser::location_type * m_loc
Definition lexer.h:50
virtual parser::token_type lex(TermPtr *yylval, parser::location_type *yylloc)
static BlockType ParseLexem(const std::string str)
Definition lexer.cpp:18
* yylval
Definition lexer.l:131
#define LOG_RUNTIME(format,...)
Definition logger.h:26
Definition nlc.h:59
std::string ParserMessage(std::string &buffer, int row, int col, const char *format,...)
Definition parser.cpp:525
std::shared_ptr< std::string > SourceType
Definition types.h:254
std::shared_ptr< Term > TermPtr
Definition variable.h:33
std::vector< TermPtr > BlockType
Definition types.h:239
std::shared_ptr< Diag > DiagPtr
Definition types.h:243