Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %{
- #include <iostream>
- using namespace std;
- typedef struct {
- int row;
- int col;
- } POS;
- POS pos = {0,0};
- %}
- %option noyywrap
- %%
- ([0-9]*\.[0-9]*) { pos.col += yyleng;
- cout << "[line: " << pos.row << " column: " << pos.col
- << " length: " << strlen(yytext) << "] "
- << "Float = " << yytext
- << endl;
- }
- [0-9]* { pos.col += yyleng;
- cout << "[line: " << pos.row << " column: " << pos.col
- << " length: " << strlen(yytext) << "] "
- << "Integer = " << yytext
- << endl;
- }
- \'[a-zA-z]\' {
- pos.col += yyleng;
- cout << "[line: " << pos.row << " column: " << pos.col
- << " length: " << strlen(yytext) << "] "
- << "Char = " << yytext
- << endl;
- }
- "Int:" { pos.col += yyleng;
- cout << "[line: " << pos.row << " column: " << pos.col
- << " length: " << strlen(yytext) << "] "
- << "DECLARATION (Integer)"
- << endl;
- }
- "Float:" { pos.col += yyleng;
- cout << "[line: " << pos.row << " column: " << pos.col
- << " length: " << strlen(yytext) << "] "
- << "DECLARATION (Float)"
- << endl;
- }
- "Char:" { pos.col += yyleng;
- cout << "[line: " << pos.row << " column: " << pos.col
- << " length: " << strlen(yytext) << "] "
- << "DECLARATION (Char)"
- << endl;
- }
- ">>>" { pos.col += yyleng;
- cout << "[line: " << yylineno << " column: " << "?"
- << " length: " << strlen(yytext) << "] "
- << "READ" << endl;
- }
- "<<<" { pos.col += yyleng;
- cout << "[line: " << pos.row << " column: " << pos.col
- << " length: " << strlen(yytext) << "] "
- << "PRINT" << endl;
- }
- "=" { pos.col += yyleng;
- cout << "[line: " << pos.row << " column: " << pos.col
- << " length: " << strlen(yytext) << "] "
- << "ASSIGN VALUE"
- << endl;
- }
- "+" { pos.col += yyleng;
- cout << "[line: " << pos.row << " column: " << pos.col
- << " length: " << strlen(yytext) << "] "
- << "PLUS" << endl;
- }
- "-" { pos.col += yyleng;
- cout << "[line: " << pos.row << " column: " << pos.col
- << " length: " << strlen(yytext) << "] "
- << "MINUS" << endl;
- }
- "*" { pos.col += yyleng;
- cout << "[line: " << pos.row << " column: " << pos.col
- << " length: " << strlen(yytext) << "] "
- << "MULTIPLY" << endl;
- }
- "and" { pos.col += yyleng;
- cout << "[line: " << pos.row << " column: " << pos.col
- << " length: " << strlen(yytext) << "] "
- << "LOGICAL AND" << endl;
- }
- "or" { pos.col += yyleng;
- cout << "[line: " << pos.row << " column: " << pos.col
- << " length: " << strlen(yytext) << "] "
- << "LOGICAL OR" << endl;
- }
- "!" { pos.col += yyleng;
- cout << "[line: " << pos.row << " column: " << pos.col
- << " length: " << strlen(yytext) << "] "
- << "LOGICAL NOT" << endl;
- }
- "==" { pos.col += yyleng;
- cout << "[line: " << pos.row << " column: " << pos.col
- << " length: " << strlen(yytext) << "] "
- << "EQUAL" << endl;
- }
- "!=" { pos.col += yyleng;
- cout << "[line: " << pos.row << " column: " << pos.col
- << " length: " << strlen(yytext) << "] "
- << "NOT EQUAL" << endl;
- }
- \n {pos.row++; pos.col = 0;}
- [ \t\r] {pos.col += yyleng;}
- . {
- cout << "error: " << yytext << "\n";
- }
- %%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement