Skip to content

Instantly share code, notes, and snippets.

@nachivpn
Last active August 29, 2015 14:01
Show Gist options
  • Save nachivpn/9ce131d1307394c7f8c7 to your computer and use it in GitHub Desktop.
Save nachivpn/9ce131d1307394c7f8c7 to your computer and use it in GitHub Desktop.
LEX Program to simulate tokens
%{
/* 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