Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %%
- [t]+
- is |
- am |
- are |
- was |
- were {printf("%s: is a verb",yytext);}
- [a-zA-Z]+ {printf("%s: is a verb",yytext);}
- . |n
- %%
- int main(int argc, char *argv[]){
- yyin = fopen(argv[1], "r");
- yylex();
- fclose(yyin);
- }
- %option noyywrap
- %x COMMENT_SINGLE
- %x COMMENT_MULTI
- %top{
- /* for strndup */
- #include <string.h>
- }
- %{
- char* commentStart;
- %}
- %%
- [ntr ]+ {
- /* ignore whitespace */ }
- <INITIAL>"//" {
- /* begin of single-line comment */
- commentStart = yytext;
- BEGIN(COMMENT_SINGLE);
- }
- <COMMENT_SINGLE>n {
- /* end of single-line comment */
- char* comment = strndup(commentStart, yytext - commentStart);
- printf("'%s': was a single-line commentn", comment);
- free(comment);
- BEGIN(INITIAL);
- }
- <COMMENT_SINGLE>[^n]+ {
- /* suppress whatever is in the comment */
- }
- <INITIAL>"/*" {
- /* begin of multi-line comment */
- commentStart = yytext;
- BEGIN(COMMENT_MULTI);
- }
- <COMMENT_MULTI>"*/" {
- /* end of multi-line comment */
- char* comment = strndup(commentStart, yytext + 2 - commentStart);
- printf("'%s': was a multi-line commentn", comment);
- free(comment);
- BEGIN(INITIAL);
- }
- <COMMENT_MULTI>. {
- /* suppress whatever is in the comment */
- }
- <COMMENT_MULTI>n {
- /* don't print newlines */
- }
- is |
- am |
- are |
- was |
- were {
- printf("'%s': is a verbn", yytext);
- }
- [a-zA-Z]+ {
- printf("'%s': is not a verbn", yytext);
- }
- . {
- /* don't print everything else */
- }
- %%
- int main(int argc, char *argv[]){
- yyin = fopen(argv[1], "r");
- yylex();
- fclose(yyin);
- }
Add Comment
Please, Sign In to add comment