%option noyywrap %option nounput %{ #include #include #include using namespace std; #include #include "naredba.hpp" #include "izraz.hpp" #include #include "parser.tab.hpp" /* void smanji_slova(string &s) { for (unsigned i = 0; i < s.size(); i++) if (isupper(s[i])) s[i] = tolower(s[i]); } */ void smanji_slova(string &s) { for (auto &c: s) c = tolower(c); } %} %% pocetak return pocetak_token; kraj return kraj_token; ispisi return ispisi_token; mod return mod_token; ako_je return ako_je_token; onda return onda_token; inace return inace_token; unesi return unesi_token; ["][^"]*["] { string tmp(yytext); yylval.s = new string(tmp.substr(1, tmp.size() - 2)); return string_token; /* " */ } [0-9]+ { yylval.x = atoi(yytext); return broj_token; } 0[xX][0-9a-fA-F]+ { yylval.x = atoi(yytext); return broj_token; } [a-zA-Z_][a-zA-Z_0-9]* { yylval.s = new string(yytext); smanji_slova(*(yylval.s)); return id_token; } [<>().;+*/:=-] return *yytext; [ \n\t] { } . { cerr << "Leksicka greska: Neprepoznat karakter " << *yytext << endl; exit(EXIT_FAILURE); } %%