NewLang Project
Yet another programm language
Loading...
Searching...
No Matches
lexer.cpp
Go to the documentation of this file.
1
2#include "lexer.h"
3
4namespace newlang {
5
6 Scanner::Scanner(std::istream* in, std::ostream* out, std::shared_ptr<std::string> source)
7 : NewLangFlexLexer(in, out),
8 source_base(source), source_string(source),
9 m_macro_iss(nullptr), m_macro_count(0), m_macro_del(0),
10 m_ignore_space(true), m_ignore_indent(true), m_ignore_comment(true), m_ignore_crlf(true),
12 // yy_flex_debug = true;
13 }
14
17
18 BlockType Scanner::ParseLexem(const std::string str) {
19
21 std::istringstream strstr(str);
22
23 Scanner lexer(&strstr);
24
25 TermPtr tok;
26 parser::location_type loc;
27 while (lexer.lex(&tok, &loc) != parser::token::END) {
28 result.push_back(tok);
29 }
30 return result;
31 }
32
34 if (diag) {
35 //@todo Need implement ApplyDiags
36#ifdef BUILD_UNITTEST
37 // LOG_WARNING("ApplyDiags not implemenetd!");
38#endif
39 } else {
40 m_ignore_space = true;
41 m_ignore_indent = true;
42 m_ignore_comment = true;
43 m_ignore_crlf = true;
44 }
45 }
46
47}
48
49#ifdef yylex
50#undef yylex
51#endif
52
53int NewLangFlexLexer::yylex() {
54 std::cerr << "in NewLangFlexLexer::yylex() !" << std::endl;
55 return 0;
56}
57
58/* When the scanner receives an end-of-file indication from YY_INPUT, it then
59 * checks the yywrap() function. If yywrap() returns false (zero), then it is
60 * assumed that the function has gone ahead and set up `yyin' to point to
61 * another input file, and scanning continues. If it returns true (non-zero),
62 * then the scanner terminates, returning 0 to its caller. */
63
64int NewLangFlexLexer::yywrap() {
65 return 1;
66}
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
virtual ~Scanner()
Definition lexer.cpp:15
bool m_ignore_indent
Definition lexer.h:73
bool m_ignore_crlf
Definition lexer.h:75
bool m_ignore_space
Definition lexer.h:72
bool m_ignore_comment
Definition lexer.h:74
virtual parser::token_type lex(TermPtr *yylval, parser::location_type *yylloc)
static BlockType ParseLexem(const std::string str)
Definition lexer.cpp:18
m_bracket_depth
Definition lexer.l:714
m_macro_count
Definition lexer.l:271
int result
Definition lexer.l:367
m_macro_del
Definition lexer.l:260
Definition nlc.h:59
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