Skip to content

Commit 5ecea65

Browse files
authored
Add files via upload
0 parents  commit 5ecea65

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed

identifiersKeywords.l

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* 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);
24+
return(0); }
25+
%%
26+
int main(){
27+
printf("Enter a cahracter/word. \n");
28+
yylex();
29+
}

outputScreenShot.xcf

93.9 KB
Binary file not shown.

readmeLex.odt

13.5 KB
Binary file not shown.

simple.l

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// 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;}
14+
%%
15+
int main()
16+
{
17+
printf("Enter the sentence\n");
18+
yylex();
19+
if(flag==1)
20+
printf("\nCompound sentence\n");
21+
else
22+
printf("\nSimple sentence\n");
23+
return 0;
24+
}

vowel_consonant.l

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
int main(){
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);
24+
}

0 commit comments

Comments
 (0)