%{

#include <iostream>

using namespace std;

#define TK_EMAIL	257
#define TK_ILLEGAL_SEQ	258


%}

	/* define patterns here */

letter	[a-zA-Z]
word	{letter}{letter}+
digit	[0-9]
other_chars	[.\-_]
id	{letter}({letter}|{digit}|{other_chars})*
domain	{word}\.{word}(\.{word})*
email	{id}\@{domain}
ws	[ \t\n]

%%

	/* define actions here */

{email}	{ return TK_EMAIL; }
{ws}	{ /* ignore whitespaces */ }
.	{ return TK_ILLEGAL_SEQ; }


%%

int main(void) {
	int token;

	while ((token = yylex()) != 0) {
		if (token == TK_ILLEGAL_SEQ) {
			cerr << "Encountered illegal sequence <" << yytext << ">" << endl;
		} else {

			cout << "Email: " << yytext << endl;
		}
	}

	return 0;
}
