You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/* Lex program to print whether the entered word is keyword or identifiers.
2
+
// Lex program includes three sections :
3
+
// 1. definition section; which includes C header files and intialisation and declarition of variables.
4
+
// 2. Rule Section; includes the description of the tokens using regular language written in UNIX style. It consists of pattern and action. Action is enclosed in curly braces{}.
5
+
// 3. User subroutine Section which includes normal C program statements and calling statements to action part of section two. yylex() initialises the Lexer.
6
+
*/
7
+
8
+
%{
9
+
#include<stdio.h>
10
+
int key_Count=0, id_count=0;
11
+
%}
12
+
%%
13
+
const |
14
+
final |
15
+
break |
16
+
else |
17
+
while |
18
+
for |
19
+
if |
20
+
do |
21
+
switch { printf(" %s is a keyword\n",yytext);
22
+
return(0); }
23
+
[a-zA-Z]+[a-zA-Z0-9]* { printf(" %s is a identifier\n",yytext);
// progarm to check whether the given sentence is compound or simple.
2
+
/*// Lex program includes three sections :
3
+
// 1. definition section; which includes C header files and intialisation and declarition of variables.
4
+
// 2. Rule Section; includes the description of the tokens using regular language written in UNIX style. It consists of pattern and action. Action is enclosed in curly braces{}.
5
+
// 3. User subroutine Section which includes normal C program statements and calling statements to action part of section two. yylex() initialises the Lexer.
6
+
// v_count is used hold the count of vowels and c_count is used to hold the count of consonant.
7
+
*/
8
+
%{
9
+
#include<stdio.h>
10
+
int flag=0;
11
+
%}
12
+
%%
13
+
(""[nN][oO][rR]"")|(""[aA][nN][dD]"")|(""[oO][rR]"")|(""[sS][oO]"")|(""[bB][uU][tT]"") { printf("The compound word used is %s",yytext); flag=1;}
/* Program to count number of vowels and consonant in the entered string.
2
+
// Lex program includes three sections :
3
+
// 1. definition section; which includes C header files and intialisation and declarition of variables.
4
+
// 2. Rule Section; includes the description of the tokens using regular language written in UNIX style. It consists of pattern and action. Action is enclosed in curly braces{}.
5
+
// 3. User subroutine Section which includes normal C program statements and calling statements to action part of section two. yylex() initialises the Lexer.
6
+
// v_count is used hold the count of vowels and c_count is used to hold the count of consonant.
7
+
*/
8
+
%{
9
+
#include<stdio.h>
10
+
int v_count=0, c_count=0;
11
+
%}
12
+
13
+
%%
14
+
[\t\n] {;}
15
+
[aAeEiIoOuU] { v_count++; }
16
+
[a-zA-Z] {c_count++; }
17
+
%%
18
+
19
+
intmain(){
20
+
printf("Enter a sentence \n");
21
+
yylex();
22
+
printf("The number of vowels =%d \n",v_count);
23
+
printf("The number of consonants=%d \n", c_count);
0 commit comments