Last active
August 29, 2015 14:01
-
-
Save nachivpn/9ce131d1307394c7f8c7 to your computer and use it in GitHub Desktop.
LEX Program to simulate tokens
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
%{ | |
/* Scan and return a token for identifiers of the format : | |
string number | |
Note: strings are not case sensitive | |
Examples: a0 , A1 , ab2 , AB4 , aBc5 | |
*/ | |
#include<stdio.h> | |
#define ID 1 //Identifier token | |
#define ER 2 //Error token | |
%} | |
low [a-z] | |
upp [A-Z] | |
number [0-9] | |
%option noyywrap | |
%% | |
({low}|{upp})({low}|{upp})*({number}) return ID; | |
(.)* return ER; | |
%% | |
int main() | |
{ | |
int token = yylex(); | |
if(token==ID) | |
printf("Acceptable\n"); | |
else if(token==ER) | |
printf("Unacceptable\n"); | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment