Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %{
- #include <iostream>
- using namespace std;
- int no_lines = 0;
- int no_cases = 0;
- %}
- %option noyywrap
- DIGIT [0-9]
- LCHAR [a-z]
- UCHAR [A-Z]
- HEX [A|B|C|D|E|F]
- %%
- [ \t] ;
- \n { no_lines++; }
- \s { no_cases++; }
- '#' ;
- [+|-]?{DIGIT}+ { cout << "INTCONST" << yytext << endl; }
- [+|-]?{DIGIT}+\.{DIGIT}+ { cout << "DECCONST" << yytext << endl; }
- [+|-]?{DIGIT}+\.{DIGIT}+\E-?{DIGIT}+ { cout << "SCICONST" << yytext << endl; }
- [{HEX}|{DIGIT}]+\H { cout << "HEXCONST" << yytext << endl; }
- [0|1]+\B { cout << "BINCONST" << yytext << endl; }
- [{DIGIT}]{3}\.[{DIGIT}]{3}\.[{DIGIT}]{4} { cout << "PHCONST" << yytext << endl; }
- \([{DIGIT}]{3}\)\-[{DIGIT}]{3}\-[{DIGIT}]{4} { cout << "PHCONST" << yytext << endl; }
- [{DIGIT}]{3}\-[{DIGIT}]{3}\-[{DIGIT}]{4} { cout << "PHCONST" << yytext << endl; }
- ["if"|"then"|"else"|"while"|"end"|"func"|"print"] { cout << "KEYWORD"
- << yytext << endl;}
- [{LCHAR}|{UCHAR}][{DIGIT}|{LCHAR}|{UCHAR}]* { cout << "IDENT" << yytext << endl; }
- \"[{DIGIT}|{LCHAR}|{UCHAR}|\s]\" { cout << "STRCONST" << yytext << endl; }
- [\+|\-|\*|\/|\<|\>|\=] { cout << "OPERATOR" << yytext << endl; }
- %%
- int main()
- {
- cout << "Hello FLEX!" << endl;
- yylex();
- cout << "Done!" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement