Table
摘要
Please use lex to read an input file which contains file size, IP addresses, and email addresses and then print the output as follows.
描述
This task requires you to use several complex regular expressions to scan file size, IP addresses, and email addresses. When a token is matched, you should output the tokens according to the examples below.
Table I shows a list of tokens your program need to recognize.
Name | Descriptions | Examples |
File Size | File size format is a number that between 0 & 1023 followed by the size keyword(kb, mb, gb, tb) |
0mb(valid) 31kb(valid) 351tb (valid) 123KB (invalid) 1029gb(invalid) ABC (invalid) |
IP Address | Internet IP address format. Note the each integer in an IP address is between 0 & 255. |
0.0.0.0(valid) 255.255.255.255 (valid) 1.100.50.0001 (invalid) |
Email Address |
Email address format. A word is composed by characters in a..z,A..Z,0..9. The left hand side of "@" can contain a word. The right hand side of "@" can contain at least two words where a "." must be inserted between two words. A "." may not appear at the end of an email address or after "@". |
oolab@cc.ncu.edu.tw(valid) abc@qwe.xyz (valid) 0436abc@i8w28.com(valid) Aq_23$@www.com(invalid) xxx@ncu.edu. (invalid) ooo@.ncu.edu (invalid) ooo@edu (invalid) |
Example #: Suppose we have the input file
351tb
123long
1kb
140.115.53.32
0.1.2.3
255.256.257.258
1.100.50.0001
oolab@cc.ncu.edu.tw
007@abc
@abc@
When pattern is matched, print it out below:
351tb is a file size
1kb is a file size
140.115.53.32 is an IP address
0.1.2.3 is an IP address
oolab@cc.ncu.edu.tw is an email address
%{ %} %option noyywrap file_int [0-9]|([1-9][0-9])|([1-9][0-9][0-9])|10([0-1][0-9]|2[0-3]) file_cap ([k|m|g|t])b file ^{file_int}{file_cap}$ ip_int (?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) ip ^{ip_int}\.{ip_int}\.{ip_int}\.{ip_int}$ email_word [0-9a-zA-Z]+ email ^{email_word}@{email_word}(\.{email_word})+$ %% {file} {ECHO;printf(" is a file size\n");} {ip} {ECHO;printf(" is an IP address\n");} {email} {ECHO;printf(" is an email address\n");} [ ] ; . ; \n ; %% int main(int argc,char *argv[]) { yylex(); return(0); } |