Skip to content

Instantly share code, notes, and snippets.

@meldsza
Created February 25, 2020 10:07
Show Gist options
  • Save meldsza/5ca59988b0bff3f1434261518a229985 to your computer and use it in GitHub Desktop.
Save meldsza/5ca59988b0bff3f1434261518a229985 to your computer and use it in GitHub Desktop.
CD LAB 25-02-2020 no of id
%{
#include <stdio.h>
#include <stdlib.h>
int nc=0;
%}
%option noyywrap
%%
[a-zA-Z_][a-zA-Z_0-9]* {nc++;}
.|\n { }
%%
int main(int argc, char* argv[]){
if(argc != 2)
{
puts("Invalid arguments provided");
return 1;
}
yyin = fopen(argv[1], "r");
yylex();
printf("No of identifiers: %d\n", nc);
fclose(yyin);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment