Untitled

 avatar
unknown
plain_text
10 months ago
2.4 kB
15
Indexable
%{
#include <stdio.h>
#include <stdlib.h>
int a,b,c,count;
%}
%option noyywrap
%%
[0-9]+    {
            if (count==0) a = atoi(yytext);
            else if (count==1) b = atoi(yytext);
            else if (count==2) c = atoi(yytext);
            count++;
         }
\n        {
            if (count>=1) {
              int L = a;
              if (count>1 && b> L) L=b;
              if (count>2 && c> L) L=c;
              printf("Largest: %d\n", L);
            }
            count=0;
         }
.        ;
%%
int main(){ yylex(); return 0; }

%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
%}
%option noyywrap
%%
[^\n]+ {
    int r,c;
    int vals[1000];
    char *p, *tok, buf[1024];
    int i=0;
    strncpy(buf, yytext, sizeof(buf)-1); buf[sizeof(buf)-1]=0;
    p = buf;
    tok = strtok(p, " \t");
    if (!tok) return;
    r = atoi(tok);
    tok = strtok(NULL, " \t");
    if (!tok) return;
    c = atoi(tok);
    while ((tok = strtok(NULL, " \t")) && i < r*c) {
        vals[i++] = atoi(tok);
    }
    if (i < r*c) { printf("Not enough elements\n"); return; }
    for (int col=0; col<c; ++col) {
      for (int row=0; row<r; ++row) printf("%d ", vals[row*c + col]);
      printf("\n");
    }
}
\n ;
. ;
%%
int main(){ yylex(); return 0; }

%{
#include <stdio.h>
#include <string.h>
%}
%option noyywrap
%%
[^\n]+ {
    char a[512], b[512];
    if (sscanf(yytext, "%s %s", a, b) == 2) {
       printf("%s%s\n", a, b);
    }
}
\n ;
. ;
%%
int main(){ yylex(); return 0; }

%{
#include <stdio.h>
%}
%option noyywrap
%%
[A-Za-z][A-Za-z0-9]*    { printf("%c ", yytext[0]); }
\n                      { printf("\n"); }
.                       ;
%%
int main(){ yylex(); return 0; }

%{
#include <stdio.h>
#include <stdlib.h>
%}
%option noyywrap
%%
[0-9]+ {
    int y = atoi(yytext);
    if ((y%4==0 && y%100!=0) || (y%400==0)) printf("%d is leap year\n", y);
    else printf("%d is not leap year\n", y);
}
\n ;
. ;
%%
int main(){ yylex(); return 0; }

%{
#include <stdio.h>
#include <ctype.h>
%}
%option noyywrap
%%
[^\n]+ {
    int a=0,d=0,s=0;
    for (char *p = yytext; *p; ++p) {
        unsigned char ch = *p;
        if (isalpha(ch)) a++;
        else if (isdigit(ch)) d++;
        else if (!isspace(ch)) s++;
    }
    printf("Alphabets: %d\nDigits: %d\nSpecials: %d\n", a, d, s);
}
\n ;
. ;
%%
int main(){ yylex(); return 0; }
Editor is loading...
Leave a Comment