Last active
August 29, 2015 13:56
-
-
Save JALsnipe/d984be6e903cc9d2131d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%{ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int longest = 0; | |
char *word = NULL; | |
%} | |
%option noyywrap | |
match ^([abctuv])+$ | |
%% | |
{match} { | |
if(yyleng > longest) { | |
if(word == NULL) { | |
free(word); | |
} | |
longest = yyleng; | |
word = (char *) malloc((yyleng + 1) * sizeof(char)); | |
strcpy(word, yytext); | |
} | |
} | |
\n { } | |
. { } | |
%% | |
int main(int argc, char *argv[]) | |
{ | |
yylex(); | |
printf("Last four digits: 0282\n"); | |
printf("Word: %s\n", word); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment