Skip to content

Instantly share code, notes, and snippets.

@nityeshaga
Last active November 24, 2018 03:08
Show Gist options
  • Select an option

  • Save nityeshaga/ae606b7e6f1b29dc6e66ff93af485621 to your computer and use it in GitHub Desktop.

Select an option

Save nityeshaga/ae606b7e6f1b29dc6e66ff93af485621 to your computer and use it in GitHub Desktop.
lex sample
%{
#include <stdio.h>
#include "y.tab.h"
void yyerror(char *s);
%}
letter [a-zA-Z]
digit [0-9]
%%
{letter}({letter}|{digit})* {countt++;}
[0-9]+ {yylval.val=atoi(yytext);return NUM;}
[ \t\n] {;}
. {return yytext[0];}
%%
void yyerror(char *s)
{
printf("ERROR IN LINENO : %d \n",yylineno);
exit(0);
}
int yywrap()
{
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment