Posts

Showing posts with the label Lex code To Check Syntax of For loop

Lex Program To Check The Syntax of For Loop

Image
Lex Code To check the syntax of For loop:- Source code:- 1:  %{   2:  #include<stdio.h> 3:  #include<ctype.h> 4:  int c; 5:  %} 6:  op "++"|"--" 7:  rop "<"|">"|"<="|">="|"=="|"!=" 8:  id [a-zA-Z][a-zA-Z0-9]* 9:  no [0-9]* 10:  pp [\n\t" "] 11:  %% 12:  for\({id}=({no}|{id})\)?(,{id}=({no}|{id}))*\;({id}{rop}({id}|{no}))?\;({id}{op})?(,{id}{op})*\)\;?{pp}*\("{"(.*\n)*.*"}") {printf("correct");c=0;} 13:  .*    {printf("\nwrong");} 14:  %% 15:  main() 16:  { yyin=fopen("file11.c","r"); 17:  yylex(); 18:  } 19:  int yywrap() 20:  {return 1; 21:  }