-
Notifications
You must be signed in to change notification settings - Fork 0
/
row_sum.lex
60 lines (43 loc) · 1.08 KB
/
row_sum.lex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
%option noyywrap
%{
#include "structs.hpp"
#include <iostream>
#include "y.tab.h"
int yyparse();
//---- Zmienne globalne
bool end = false;
extern unsigned int codeLine;
extern unsigned int column;
//---- Funkcje
inline void assign_yyval_str(const char* text);
%}
fixed ([0]|[1-9][0-9]*)[.][0-9]+
float ([0]|[1-9][0-9]*)[.][0-9]+[E]([+]|[-])[0-9]+
int [0]|[1-9][0-9]*
hex [1-9A-Fa-f][0-9A-Fa-f]*
%%
\r\n|\n|\r { return ENDLINE; }
[ ] { column++; }
[\t] { column += 5; }
{fixed} { assign_yyval_str(yytext); return FIXED; }
{float} { assign_yyval_str(yytext); return FLOAT; }
{int} {
assign_yyval_str(yytext);
return INT;
}
{hex} { assign_yyval_str(yytext); return HEX; }
<<EOF>> {
if(!end) { end = true; return ENDLINE; }
else { return 0; }
}
. { return UNK; }
%%
int main(void) { return yyparse(); }
int yyerror(const char* str) {
std::cerr << codeLine << ':' << column << ": error: " << str << '\n';
return 1;
}
void assign_yyval_str(const char* text){
yylval.str = new std::string(text);
column += yylval.str->length();
}