Advertisement
GerexD

lol

Nov 29th, 2022
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.11 KB | None | 0 0
  1. %{
  2. #include <iostream>
  3. using namespace std;
  4. typedef struct {
  5. int row;
  6. int col;
  7. } POS;
  8. POS pos = {0,0};
  9.  
  10. %}
  11.  
  12. %option noyywrap
  13.  
  14. %%
  15.  
  16.  
  17. ([0-9]*\.[0-9]*) { pos.col += yyleng;
  18. cout << "[line: " << pos.row << " column: " << pos.col
  19. << " length: " << strlen(yytext) << "] "
  20. << "Float = " << yytext
  21. << endl;
  22. }
  23.  
  24. [0-9]* { pos.col += yyleng;
  25. cout << "[line: " << pos.row << " column: " << pos.col
  26. << " length: " << strlen(yytext) << "] "
  27. << "Integer = " << yytext
  28. << endl;
  29. }
  30. \'[a-zA-z]\' {
  31. pos.col += yyleng;
  32. cout << "[line: " << pos.row << " column: " << pos.col
  33. << " length: " << strlen(yytext) << "] "
  34. << "Char = " << yytext
  35. << endl;
  36. }
  37. "Int:" { pos.col += yyleng;
  38. cout << "[line: " << pos.row << " column: " << pos.col
  39. << " length: " << strlen(yytext) << "] "
  40. << "DECLARATION (Integer)"
  41. << endl;
  42. }
  43.  
  44. "Float:" { pos.col += yyleng;
  45. cout << "[line: " << pos.row << " column: " << pos.col
  46. << " length: " << strlen(yytext) << "] "
  47. << "DECLARATION (Float)"
  48. << endl;
  49. }
  50. "Char:" { pos.col += yyleng;
  51. cout << "[line: " << pos.row << " column: " << pos.col
  52. << " length: " << strlen(yytext) << "] "
  53. << "DECLARATION (Char)"
  54. << endl;
  55. }
  56. ">>>" { pos.col += yyleng;
  57. cout << "[line: " << yylineno << " column: " << "?"
  58. << " length: " << strlen(yytext) << "] "
  59. << "READ" << endl;
  60. }
  61. "<<<" { pos.col += yyleng;
  62. cout << "[line: " << pos.row << " column: " << pos.col
  63. << " length: " << strlen(yytext) << "] "
  64. << "PRINT" << endl;
  65. }
  66. "=" { pos.col += yyleng;
  67. cout << "[line: " << pos.row << " column: " << pos.col
  68. << " length: " << strlen(yytext) << "] "
  69. << "ASSIGN VALUE"
  70. << endl;
  71. }
  72.  
  73. "+" { pos.col += yyleng;
  74. cout << "[line: " << pos.row << " column: " << pos.col
  75. << " length: " << strlen(yytext) << "] "
  76. << "PLUS" << endl;
  77. }
  78. "-" { pos.col += yyleng;
  79. cout << "[line: " << pos.row << " column: " << pos.col
  80. << " length: " << strlen(yytext) << "] "
  81. << "MINUS" << endl;
  82. }
  83. "*" { pos.col += yyleng;
  84. cout << "[line: " << pos.row << " column: " << pos.col
  85. << " length: " << strlen(yytext) << "] "
  86. << "MULTIPLY" << endl;
  87. }
  88. "and" { pos.col += yyleng;
  89. cout << "[line: " << pos.row << " column: " << pos.col
  90. << " length: " << strlen(yytext) << "] "
  91. << "LOGICAL AND" << endl;
  92. }
  93. "or" { pos.col += yyleng;
  94. cout << "[line: " << pos.row << " column: " << pos.col
  95. << " length: " << strlen(yytext) << "] "
  96. << "LOGICAL OR" << endl;
  97. }
  98. "!" { pos.col += yyleng;
  99. cout << "[line: " << pos.row << " column: " << pos.col
  100. << " length: " << strlen(yytext) << "] "
  101. << "LOGICAL NOT" << endl;
  102. }
  103. "==" { pos.col += yyleng;
  104. cout << "[line: " << pos.row << " column: " << pos.col
  105. << " length: " << strlen(yytext) << "] "
  106. << "EQUAL" << endl;
  107. }
  108. "!=" { pos.col += yyleng;
  109. cout << "[line: " << pos.row << " column: " << pos.col
  110. << " length: " << strlen(yytext) << "] "
  111. << "NOT EQUAL" << endl;
  112. }
  113. \n {pos.row++; pos.col = 0;}
  114. [ \t\r] {pos.col += yyleng;}
  115. . {
  116. cout << "error: " << yytext << "\n";
  117. }
  118.  
  119. %%
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement