Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. %{
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int no_lines = 0;
  6. int no_cases = 0;
  7. %}
  8.  
  9. %option noyywrap
  10. DIGIT [0-9]
  11. LCHAR [a-z]
  12. UCHAR [A-Z]
  13. HEX [A|B|C|D|E|F]
  14.  
  15. %%
  16.  
  17. [ \t] ;
  18.  
  19. \n { no_lines++; }
  20.  
  21. \s { no_cases++; }
  22.  
  23. '#' ;
  24.  
  25. [+|-]?{DIGIT}+ { cout << "INTCONST" << yytext << endl; }
  26.  
  27. [+|-]?{DIGIT}+\.{DIGIT}+ { cout << "DECCONST" << yytext << endl; }
  28.  
  29. [+|-]?{DIGIT}+\.{DIGIT}+\E-?{DIGIT}+ { cout << "SCICONST" << yytext << endl; }
  30.  
  31. [{HEX}|{DIGIT}]+\H { cout << "HEXCONST" << yytext << endl; }
  32.  
  33. [0|1]+\B { cout << "BINCONST" << yytext << endl; }
  34.  
  35. [{DIGIT}]{3}\.[{DIGIT}]{3}\.[{DIGIT}]{4} { cout << "PHCONST" << yytext << endl; }
  36.  
  37. \([{DIGIT}]{3}\)\-[{DIGIT}]{3}\-[{DIGIT}]{4} { cout << "PHCONST" << yytext << endl; }
  38.  
  39. [{DIGIT}]{3}\-[{DIGIT}]{3}\-[{DIGIT}]{4} { cout << "PHCONST" << yytext << endl; }
  40.  
  41. ["if"|"then"|"else"|"while"|"end"|"func"|"print"] { cout << "KEYWORD"
  42. << yytext << endl;}
  43.  
  44. [{LCHAR}|{UCHAR}][{DIGIT}|{LCHAR}|{UCHAR}]* { cout << "IDENT" << yytext << endl; }
  45.  
  46. \"[{DIGIT}|{LCHAR}|{UCHAR}|\s]\" { cout << "STRCONST" << yytext << endl; }
  47.  
  48. [\+|\-|\*|\/|\<|\>|\=] { cout << "OPERATOR" << yytext << endl; }
  49. %%
  50.  
  51. int main()
  52. {
  53. cout << "Hello FLEX!" << endl;
  54. yylex();
  55. cout << "Done!" << endl;
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement