clilexer.l 1.56 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/**
 * command line parser
 * @author Tobias Weber <tweber@ill.fr>
 * @date 28-may-18
 * @license see 'LICENSE' file
 */

%option noyywrap
%option yyclass = "CliLexer"


%{
	#include "cliparser.h"
%}


Tobias WEBER's avatar
Tobias WEBER committed
17
18
sign 	[-+]
integer {sign}?[0-9]+
Tobias WEBER's avatar
Tobias WEBER committed
19
20
uinteger [0-9]+
real 	{uinteger}(\.[0-9]*)?|\.[0-9]+
21
22
23
24
25


%%


Tobias WEBER's avatar
Tobias WEBER committed
26
27
[;\n] { return yy::CliParser::make_TOK_NEWLINE(); }
[ \t]		/* eps */
28
29
30

"(" { return yy::CliParser::make_TOK_BRACKET_OPEN(); }
")" { return yy::CliParser::make_TOK_BRACKET_CLOSE(); }
Tobias WEBER's avatar
Tobias WEBER committed
31
32
"[" { return yy::CliParser::make_TOK_SQBRACKET_OPEN(); }
"]" { return yy::CliParser::make_TOK_SQBRACKET_CLOSE(); }
33
34
"{" { return yy::CliParser::make_TOK_CURLBRACKET_OPEN(); }
"}" { return yy::CliParser::make_TOK_CURLBRACKET_CLOSE(); }
35
36
37
38
39
40
41
"+" { return yy::CliParser::make_TOK_PLUS(); }
"-" { return yy::CliParser::make_TOK_MINUS(); }
"*" { return yy::CliParser::make_TOK_MULT(); }
"/" { return yy::CliParser::make_TOK_DIV(); }
"%" { return yy::CliParser::make_TOK_MOD(); }
"^" { return yy::CliParser::make_TOK_POW(); }
"=" { return yy::CliParser::make_TOK_ASSIGN(); }
Tobias WEBER's avatar
Tobias WEBER committed
42
"." { return yy::CliParser::make_TOK_MEMBER_ACCESS(); }
Tobias WEBER's avatar
Tobias WEBER committed
43
"," { return yy::CliParser::make_TOK_COMMA(); }
44

Tobias WEBER's avatar
Tobias WEBER committed
45
46
47
48
49
50
51
52
53
54
55

{real}([eE]{integer})? {
	//std::cerr << "matched: " << yytext << std::endl;
	return yy::CliParser::make_TOK_REAL(str_to_real<t_real_cli>(yytext));
}

["'][^"'\n]*["'] {
	auto str = std::string(yytext+1, yytext+yyleng-1);
	return yy::CliParser::make_TOK_STRING(str);
}

Tobias WEBER's avatar
Tobias WEBER committed
56
[A-Za-z_][A-Za-z0-9_]* {
Tobias WEBER's avatar
Tobias WEBER committed
57
58
59
	return yy::CliParser::make_TOK_IDENT(yytext);
}

60
61
62
63
64
65
66

. {
	context.PrintError(std::string("Lexer error: Unknown token: \"") + yytext + std::string("\""));
} 


%%