pos
#commands
First, make sure you have Flex installed:
For installing on Ubuntu- sudo apt-get install flex
- Save as
analyzer.l - Run:
flex analyzer.l - Compile:
gcc lex.yy.c -o analyzer -lfl - Execute:
./analyzer
%{
#include <stdio.h>
#include <ctype.h>
%}
%%
[ \t\n]+ ;
[0-9]+ { printf("Number\t\t=> %s\n", yytext); }
[.,!?'"-] { printf("Punctuation\t=> %s\n", yytext); }
"the"|"a"|"an" { printf("Article\t\t=> %s\n", yytext); }
"I"|"you"|"he"|"she"|"it"|"we"|"they" { printf("Pronoun\t\t=> %s\n", yytext); }
"I'm"|"you're"|"he's"|"she's"|"it's"|"we're"|"they're" { printf("Contraction\t=> %s\n", yytext); }
"am"|"is"|"are"|"was"|"were"|"be"|"being"|"been" { printf("Verb\t\t=> %s\n", yytext); }
"have"|"has"|"had"|"do"|"does"|"did" { printf("Verb\t\t=> %s\n", yytext); }
"can"|"could"|"shall"|"should"|"will"|"would"|"may"|"might"|"must" { printf("Modal Verb\t=> %s\n", yytext); }
"dread"|"run"|"arrives"|"stop"|"light"|"give"|"kill"|"imagines"|"divide" { printf("Verb\t\t=> %s\n", yytext); }
"thing"|"curiosity"|"reason"|"cigarette"|"power"|"generation" { printf("Noun\t\t=> %s\n", yytext); }
"intelligence"|"wisdom"|"human"|"beings"|"instinct"|"thinking" { printf("Noun\t\t=> %s\n", yytext); }
"urge"|"things"|"groups"|"gap"|"destiny"|"same" { printf("Noun\t\t=> %s\n", yytext); }
"important"|"own"|"every"|"intelligent"|"wiser"|"strong" { printf("Adjective\t=> %s\n", yytext); }
"dramatic"|"basic"|"distinct"|"empty"|"all"|"fine" { printf("Adjective\t=> %s\n", yytext); }
"not"|"never"|"how"|"very"|"more"|"than" { printf("Adverb\t\t=> %s\n", yytext); }
"before"|"after" { printf("Adverb\t\t=> %s\n", yytext); }
"to"|"for"|"from"|"by"|"in"|"on"|"at"|"with" { printf("Preposition\t=> %s\n", yytext); }
"about"|"between"|"after"|"before"|"into"|"through" { printf("Preposition\t=> %s\n", yytext); }
"and"|"but"|"or"|"if"|"that"|"than" { printf("Conjunction\t=> %s\n", yytext); }
"hello"|"thank" { printf("Interjection\t=> %s\n", yytext); }
[A-Za-z]+ { printf("Noun/Other\t=> %s\n", yytext); }
. { printf("Unknown\t\t=> %s\n", yytext); }
%%
int yywrap() { return 1; }
int main() {
yylex();
return 0;
}
Comments
Post a Comment