-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFull_Program.l
More file actions
41 lines (36 loc) · 1.19 KB
/
Full_Program.l
File metadata and controls
41 lines (36 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
%{
#include "y.tab.h"
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX_LENGTH 1000
// Declare global variables
char sentence[MAX_LENGTH];
char concatenated[MAX_LENGTH];
char search_word[100];
char new_word[100];
int mode;
%}
%%
"reverse" { return REVERSE; }
"vowels_consonants" { return VOWELS_CONSONANTS; }
"view" { return VIEW; }
"add" { return ADD_WORD; }
"delete" { return DELETE_WORD; }
"replace" { return REPLACE_WORD; }
"palindrome" { return PALINDROME; }
"count" { return COUNT; }
"case" { return CHANGE_CASE; }
"concat" { return CONCATENATE; }
"print_strings" { return PRINT_STRINGS; }
"longest" { return LONGEST_STRING; }
[a-zA-Z]+ { yylval.str_val = strdup(yytext); return WORD; }
"+" { return PLUS; }
\"[^\"]*\" { yylval.str_val = strdup(yytext + 1); yylval.str_val[strlen(yylval.str_val) - 1] = '\0'; return STRING; }
[ \t]+ { return SPACE; } // Match spaces or tabs
\n { return NEWLINE; }
. { return *yytext; }
%%
int yywrap() {
return 1;
}