juneja-codebase 0.1.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- juneja_codebase/__init__.py +6 -0
- juneja_codebase/main.py +197 -0
- juneja_codebase/templates/compiler_design/AnshJuneja_Practical10_CD.l +15 -0
- juneja_codebase/templates/compiler_design/AnshJuneja_Practical10_CD.y +27 -0
- juneja_codebase/templates/compiler_design/AnshJuneja_Practical11_CD.l +15 -0
- juneja_codebase/templates/compiler_design/AnshJuneja_Practical11_CD.y +36 -0
- juneja_codebase/templates/compiler_design/AnshJuneja_Practical12_CD.l +14 -0
- juneja_codebase/templates/compiler_design/AnshJuneja_Practical12_CD.y +31 -0
- juneja_codebase/templates/compiler_design/AnshJuneja_Practical13_CD.l +14 -0
- juneja_codebase/templates/compiler_design/AnshJuneja_Practical13_CD.y +38 -0
- juneja_codebase/templates/compiler_design/AnshJuneja_Practical1_CD.l +38 -0
- juneja_codebase/templates/compiler_design/AnshJuneja_Practical2_CD.l +27 -0
- juneja_codebase/templates/compiler_design/AnshJuneja_Practical3_CD.l +39 -0
- juneja_codebase/templates/compiler_design/AnshJuneja_Practical4_CD.l +32 -0
- juneja_codebase/templates/compiler_design/AnshJuneja_Practical5_CD.l +51 -0
- juneja_codebase/templates/compiler_design/AnshJuneja_Practical6_CD.l +46 -0
- juneja_codebase/templates/compiler_design/AnshJuneja_Practical7_CD.l +36 -0
- juneja_codebase/templates/compiler_design/AnshJuneja_Practical8_CD.l +33 -0
- juneja_codebase/templates/compiler_design/AnshJuneja_Practical9_CD.l +19 -0
- juneja_codebase/templates/compiler_design/AnshJuneja_Practical9_CD.y +36 -0
- juneja_codebase/templates/social_network_analysis/1_try.ipynb +286 -0
- juneja_codebase/templates/social_network_analysis/2_try.ipynb +352 -0
- juneja_codebase/templates/social_network_analysis/3_try.ipynb +207 -0
- juneja_codebase/templates/social_network_analysis/4_try.ipynb +1218 -0
- juneja_codebase/templates/social_network_analysis/5_try.ipynb +326 -0
- juneja_codebase/templates/social_network_analysis/6_try.ipynb +241 -0
- juneja_codebase/templates/social_network_analysis/new.ipynb +592 -0
- juneja_codebase-0.1.3.dist-info/LICENSE +21 -0
- juneja_codebase-0.1.3.dist-info/METADATA +75 -0
- juneja_codebase-0.1.3.dist-info/RECORD +33 -0
- juneja_codebase-0.1.3.dist-info/WHEEL +5 -0
- juneja_codebase-0.1.3.dist-info/entry_points.txt +3 -0
- juneja_codebase-0.1.3.dist-info/top_level.txt +1 -0
juneja_codebase/main.py
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Main CLI entry point for reqcode-aj
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import os
|
|
8
|
+
import shutil
|
|
9
|
+
import zipfile
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def get_templates_dir():
|
|
14
|
+
"""Get the path to the templates directory"""
|
|
15
|
+
return Path(__file__).parent / "templates"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def list_subjects():
|
|
19
|
+
"""List all available subjects"""
|
|
20
|
+
templates_dir = get_templates_dir()
|
|
21
|
+
subjects = [d.name for d in templates_dir.iterdir() if d.is_dir()]
|
|
22
|
+
return subjects
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def copy_subject_files(subject, output_dir):
|
|
26
|
+
"""Copy files for a specific subject to the output directory"""
|
|
27
|
+
templates_dir = get_templates_dir()
|
|
28
|
+
subject_dir = templates_dir / subject
|
|
29
|
+
|
|
30
|
+
if not subject_dir.exists():
|
|
31
|
+
print(f"Error: Subject '{subject}' not found!")
|
|
32
|
+
print(f"Available subjects: {', '.join(list_subjects())}")
|
|
33
|
+
return False
|
|
34
|
+
|
|
35
|
+
output_path = Path(output_dir) / subject
|
|
36
|
+
output_path.mkdir(parents=True, exist_ok=True)
|
|
37
|
+
|
|
38
|
+
# Copy all files from subject directory
|
|
39
|
+
for item in subject_dir.rglob('*'):
|
|
40
|
+
if item.is_file():
|
|
41
|
+
relative_path = item.relative_to(subject_dir)
|
|
42
|
+
dest_path = output_path / relative_path
|
|
43
|
+
dest_path.parent.mkdir(parents=True, exist_ok=True)
|
|
44
|
+
shutil.copy2(item, dest_path)
|
|
45
|
+
print(f"Created: {dest_path}")
|
|
46
|
+
|
|
47
|
+
return True
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def copy_all_subjects(output_dir):
|
|
51
|
+
"""Copy files for all subjects to the output directory"""
|
|
52
|
+
subjects = list_subjects()
|
|
53
|
+
success = True
|
|
54
|
+
|
|
55
|
+
for subject in subjects:
|
|
56
|
+
print(f"\n=== Generating {subject} files ===")
|
|
57
|
+
if not copy_subject_files(subject, output_dir):
|
|
58
|
+
success = False
|
|
59
|
+
|
|
60
|
+
return success
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def create_zip_archive(subject, output_file):
|
|
64
|
+
"""Create a zip archive for a specific subject or all subjects"""
|
|
65
|
+
templates_dir = get_templates_dir()
|
|
66
|
+
|
|
67
|
+
if subject:
|
|
68
|
+
# Zip specific subject
|
|
69
|
+
subject_dir = templates_dir / subject
|
|
70
|
+
if not subject_dir.exists():
|
|
71
|
+
print(f"Error: Subject '{subject}' not found!")
|
|
72
|
+
return False
|
|
73
|
+
|
|
74
|
+
zip_name = output_file if output_file else f"{subject}.zip"
|
|
75
|
+
|
|
76
|
+
with zipfile.ZipFile(zip_name, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
|
77
|
+
for item in subject_dir.rglob('*'):
|
|
78
|
+
if item.is_file():
|
|
79
|
+
arcname = subject / item.relative_to(subject_dir)
|
|
80
|
+
zipf.write(item, arcname)
|
|
81
|
+
print(f"Added to zip: {arcname}")
|
|
82
|
+
|
|
83
|
+
print(f"\n✓ Created zip file: {zip_name}")
|
|
84
|
+
return True
|
|
85
|
+
else:
|
|
86
|
+
# Zip all subjects
|
|
87
|
+
zip_name = output_file if output_file else "all_subjects.zip"
|
|
88
|
+
|
|
89
|
+
with zipfile.ZipFile(zip_name, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
|
90
|
+
for subject_dir in templates_dir.iterdir():
|
|
91
|
+
if subject_dir.is_dir():
|
|
92
|
+
print(f"\nAdding {subject_dir.name} to zip...")
|
|
93
|
+
for item in subject_dir.rglob('*'):
|
|
94
|
+
if item.is_file():
|
|
95
|
+
arcname = item.relative_to(templates_dir)
|
|
96
|
+
zipf.write(item, arcname)
|
|
97
|
+
print(f"Added: {arcname}")
|
|
98
|
+
|
|
99
|
+
print(f"\n✓ Created zip file: {zip_name}")
|
|
100
|
+
return True
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def main():
|
|
104
|
+
"""Main entry point for the CLI"""
|
|
105
|
+
parser = argparse.ArgumentParser(
|
|
106
|
+
description="Generate code files for academic practicals",
|
|
107
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
108
|
+
epilog="""
|
|
109
|
+
Examples:
|
|
110
|
+
reqcode --list # List available subjects
|
|
111
|
+
reqcode --all # Generate all code files
|
|
112
|
+
reqcode --subject compiler_design # Generate specific subject files
|
|
113
|
+
reqcode --all --output ./my_codes # Generate to specific directory
|
|
114
|
+
reqcode --all --zip # Create zip of all subjects
|
|
115
|
+
reqcode --subject compiler_design --zip # Create zip of specific subject
|
|
116
|
+
"""
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
parser.add_argument(
|
|
120
|
+
'--list', '-l',
|
|
121
|
+
action='store_true',
|
|
122
|
+
help='List all available subjects'
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
parser.add_argument(
|
|
126
|
+
'--all', '-a',
|
|
127
|
+
action='store_true',
|
|
128
|
+
help='Generate code files for all subjects'
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
parser.add_argument(
|
|
132
|
+
'--subject', '-s',
|
|
133
|
+
type=str,
|
|
134
|
+
help='Generate code files for a specific subject'
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
parser.add_argument(
|
|
138
|
+
'--output', '-o',
|
|
139
|
+
type=str,
|
|
140
|
+
default='.',
|
|
141
|
+
help='Output directory or zip filename (default: current directory)'
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
parser.add_argument(
|
|
145
|
+
'--zip', '-z',
|
|
146
|
+
action='store_true',
|
|
147
|
+
help='Create a zip file instead of extracting files'
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
parser.add_argument(
|
|
151
|
+
'--version', '-v',
|
|
152
|
+
action='version',
|
|
153
|
+
version='%(prog)s 0.1.0'
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
args = parser.parse_args()
|
|
157
|
+
|
|
158
|
+
# List subjects
|
|
159
|
+
if args.list:
|
|
160
|
+
subjects = list_subjects()
|
|
161
|
+
print("Available subjects:")
|
|
162
|
+
for i, subject in enumerate(subjects, 1):
|
|
163
|
+
print(f" {i}. {subject}")
|
|
164
|
+
return
|
|
165
|
+
|
|
166
|
+
# Create zip archive
|
|
167
|
+
if args.zip:
|
|
168
|
+
if args.all:
|
|
169
|
+
create_zip_archive(None, args.output if args.output != '.' else None)
|
|
170
|
+
elif args.subject:
|
|
171
|
+
create_zip_archive(args.subject, args.output if args.output != '.' else None)
|
|
172
|
+
else:
|
|
173
|
+
print("Error: Please specify --all or --subject with --zip")
|
|
174
|
+
parser.print_help()
|
|
175
|
+
return
|
|
176
|
+
|
|
177
|
+
# Generate files
|
|
178
|
+
if args.all:
|
|
179
|
+
print("Generating all subject files...")
|
|
180
|
+
copy_all_subjects(args.output)
|
|
181
|
+
print(f"\n✓ All files generated in: {os.path.abspath(args.output)}")
|
|
182
|
+
elif args.subject:
|
|
183
|
+
print(f"Generating {args.subject} files...")
|
|
184
|
+
copy_subject_files(args.subject, args.output)
|
|
185
|
+
print(f"\n✓ Files generated in: {os.path.abspath(args.output)}")
|
|
186
|
+
else:
|
|
187
|
+
# No action specified, show help
|
|
188
|
+
parser.print_help()
|
|
189
|
+
print("\n" + "="*70)
|
|
190
|
+
print("💡 TIP: If 'reqcode' command doesn't work in your system, use:")
|
|
191
|
+
print(" python -m reqcode_aj.main --list")
|
|
192
|
+
print(" python -m reqcode_aj.main --all")
|
|
193
|
+
print("="*70)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
if __name__ == '__main__':
|
|
197
|
+
main()
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
%{
|
|
2
|
+
#include <stdio.h>
|
|
3
|
+
#include <stdlib.h>
|
|
4
|
+
|
|
5
|
+
int yylex();
|
|
6
|
+
int yyerror(const char *s);
|
|
7
|
+
%}
|
|
8
|
+
|
|
9
|
+
%token LETTER DIGIT
|
|
10
|
+
|
|
11
|
+
%%
|
|
12
|
+
|
|
13
|
+
S : LETTER DIGIT '\n' { printf("Valid variable\n"); }
|
|
14
|
+
;
|
|
15
|
+
|
|
16
|
+
%%
|
|
17
|
+
|
|
18
|
+
int yyerror(const char *s) {
|
|
19
|
+
printf("Invalid variable\n");
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
int main() {
|
|
24
|
+
printf("Enter variable: ");
|
|
25
|
+
yyparse();
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
%{
|
|
2
|
+
#include <stdio.h>
|
|
3
|
+
#include <stdlib.h>
|
|
4
|
+
|
|
5
|
+
int yylex();
|
|
6
|
+
int yyerror(const char *s);
|
|
7
|
+
%}
|
|
8
|
+
|
|
9
|
+
%token NUM
|
|
10
|
+
%left '+' '-'
|
|
11
|
+
%left '*' '/'
|
|
12
|
+
|
|
13
|
+
%%
|
|
14
|
+
|
|
15
|
+
S : E '\n' { printf("Result = %d\n", $1); }
|
|
16
|
+
;
|
|
17
|
+
|
|
18
|
+
E : E '+' E { $$ = $1 + $3; }
|
|
19
|
+
| E '-' E { $$ = $1 - $3; }
|
|
20
|
+
| E '*' E { $$ = $1 * $3; }
|
|
21
|
+
| E '/' E { $$ = $1 / $3; }
|
|
22
|
+
| NUM { $$ = $1; }
|
|
23
|
+
;
|
|
24
|
+
|
|
25
|
+
%%
|
|
26
|
+
|
|
27
|
+
int yyerror(const char *s) {
|
|
28
|
+
printf("Invalid expression\n");
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
int main() {
|
|
33
|
+
printf("Enter expression:\n");
|
|
34
|
+
yyparse();
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
%{
|
|
2
|
+
#include <stdio.h>
|
|
3
|
+
#include <stdlib.h>
|
|
4
|
+
|
|
5
|
+
int yylex();
|
|
6
|
+
int yyerror(const char *s);
|
|
7
|
+
%}
|
|
8
|
+
|
|
9
|
+
%token A B
|
|
10
|
+
|
|
11
|
+
%%
|
|
12
|
+
|
|
13
|
+
S : A BPLUS '\n' { printf("Valid string\n"); }
|
|
14
|
+
;
|
|
15
|
+
|
|
16
|
+
BPLUS : B
|
|
17
|
+
| B BPLUS
|
|
18
|
+
;
|
|
19
|
+
|
|
20
|
+
%%
|
|
21
|
+
|
|
22
|
+
int yyerror(const char *s) {
|
|
23
|
+
printf("Invalid string\n");
|
|
24
|
+
return 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
int main() {
|
|
28
|
+
printf("Enter string: ");
|
|
29
|
+
yyparse();
|
|
30
|
+
return 0;
|
|
31
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
%{
|
|
2
|
+
#include <stdio.h>
|
|
3
|
+
#include <stdlib.h>
|
|
4
|
+
|
|
5
|
+
int yylex();
|
|
6
|
+
int yyerror(const char *s);
|
|
7
|
+
int count = 0;
|
|
8
|
+
%}
|
|
9
|
+
|
|
10
|
+
%token A B
|
|
11
|
+
|
|
12
|
+
%%
|
|
13
|
+
|
|
14
|
+
S : ALIST B '\n'
|
|
15
|
+
{
|
|
16
|
+
if (count >= 1)
|
|
17
|
+
printf("Valid string\n");
|
|
18
|
+
else
|
|
19
|
+
printf("Invalid string\n");
|
|
20
|
+
}
|
|
21
|
+
;
|
|
22
|
+
|
|
23
|
+
ALIST : A { count++; }
|
|
24
|
+
| ALIST A { count++; }
|
|
25
|
+
;
|
|
26
|
+
|
|
27
|
+
%%
|
|
28
|
+
|
|
29
|
+
int yyerror(const char *s) {
|
|
30
|
+
printf("Invalid string\n");
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
int main() {
|
|
35
|
+
printf("Enter string: ");
|
|
36
|
+
yyparse();
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
%{
|
|
2
|
+
#include <stdio.h>
|
|
3
|
+
#include <ctype.h>
|
|
4
|
+
int charCount = 0;
|
|
5
|
+
int lineCount = 1;
|
|
6
|
+
int numCount = 0;
|
|
7
|
+
int special = 0;
|
|
8
|
+
%}
|
|
9
|
+
|
|
10
|
+
%%
|
|
11
|
+
[\n] lineCount++; printf("%c" , yytext[0]);
|
|
12
|
+
[a-zA-Z] charCount++; printf("%c", yytext[0]);
|
|
13
|
+
[0-9] numCount++; printf("%c" , yytext[0]);
|
|
14
|
+
[@#$%*<:>;&^!()_+=|\~`{}] special = 1; printf("%c" , yytext[0]);
|
|
15
|
+
|
|
16
|
+
%%
|
|
17
|
+
int yywrap(){
|
|
18
|
+
return 1;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
int main(int argc, char* argv[]){
|
|
22
|
+
|
|
23
|
+
yyin = fopen("input.txt", "r");
|
|
24
|
+
yyout = fopen("output.txt", "w");
|
|
25
|
+
|
|
26
|
+
yylex();
|
|
27
|
+
|
|
28
|
+
fprintf(yyout,"Line Count %d\n ", lineCount);
|
|
29
|
+
fprintf(yyout,"Character Count %d\n ", charCount);
|
|
30
|
+
fprintf(yyout,"Number Count %d\n ", numCount);
|
|
31
|
+
if (special==1)fprintf(yyout,"Special: True\n");
|
|
32
|
+
else fprintf(yyout,"Special: False\n");
|
|
33
|
+
|
|
34
|
+
fclose(yyin);
|
|
35
|
+
fclose(yyout);
|
|
36
|
+
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
%{
|
|
2
|
+
#include<stdio.h>
|
|
3
|
+
#include<ctype.h>
|
|
4
|
+
int vowelcnt = 0;
|
|
5
|
+
int constcnt = 0;
|
|
6
|
+
%}
|
|
7
|
+
|
|
8
|
+
%%
|
|
9
|
+
[aeiouAEIOU] vowelcnt++;
|
|
10
|
+
[a-zA-Z] constcnt++;
|
|
11
|
+
|
|
12
|
+
%%
|
|
13
|
+
int yywrap() {
|
|
14
|
+
return 1;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
int main(){
|
|
18
|
+
|
|
19
|
+
yylex();
|
|
20
|
+
|
|
21
|
+
printf("vowel count : %d\n",vowelcnt);
|
|
22
|
+
printf("Consonant Count : %d\n", constcnt);
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
return 0;
|
|
26
|
+
|
|
27
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
%{
|
|
2
|
+
#include <stdio.h>
|
|
3
|
+
#include <ctype.h>
|
|
4
|
+
|
|
5
|
+
char shift_char(char c) {
|
|
6
|
+
if (c >= 'a' && c <= 'z') {
|
|
7
|
+
return 'a' + ( (c - 'a' + 3) % 26 );
|
|
8
|
+
}
|
|
9
|
+
else if (c >= 'A' && c <= 'Z') {
|
|
10
|
+
return 'A' + ( (c - 'A' + 3) % 26 );
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return c;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
%}
|
|
17
|
+
|
|
18
|
+
%%
|
|
19
|
+
[a-zA-Z] {
|
|
20
|
+
char c = yytext[0];
|
|
21
|
+
c = shift_char(c);
|
|
22
|
+
printf("%c", c);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.|\n {
|
|
26
|
+
printf("%s", yytext);
|
|
27
|
+
}
|
|
28
|
+
%%
|
|
29
|
+
|
|
30
|
+
int yywrap() {
|
|
31
|
+
return 1;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
int main() {
|
|
35
|
+
|
|
36
|
+
yylex();
|
|
37
|
+
|
|
38
|
+
return 0;
|
|
39
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
%{
|
|
2
|
+
#include <stdio.h>
|
|
3
|
+
#include <ctype.h>
|
|
4
|
+
#include <string.h>
|
|
5
|
+
char longestWord[1000];
|
|
6
|
+
%}
|
|
7
|
+
|
|
8
|
+
%%
|
|
9
|
+
[A-Za-z]+ {
|
|
10
|
+
if (strlen(yytext) > strlen(longestWord)){
|
|
11
|
+
strcpy(longestWord, yytext);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
%%
|
|
18
|
+
|
|
19
|
+
int yywrap(){
|
|
20
|
+
return 1;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
int main(){
|
|
24
|
+
yylex();
|
|
25
|
+
if(strlen(longestWord) > 0)
|
|
26
|
+
printf("Longest word: %s\n", longestWord);
|
|
27
|
+
else
|
|
28
|
+
printf("No words found \n");
|
|
29
|
+
|
|
30
|
+
return 0;
|
|
31
|
+
|
|
32
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
%{
|
|
2
|
+
#include <stdio.h>
|
|
3
|
+
#include <ctype.h>
|
|
4
|
+
#include <string.h>
|
|
5
|
+
|
|
6
|
+
%}
|
|
7
|
+
|
|
8
|
+
/* List of some common C keywords */
|
|
9
|
+
KEYWORD "int"|"float"|"char"|"double"|"if"|"else"|"for"|"while"|"return"
|
|
10
|
+
|
|
11
|
+
IDENT [a-zA-Z_][a-zA-Z0-9_]*
|
|
12
|
+
INT [0-9]+
|
|
13
|
+
FLOAT [0-9]+"."[0-9]+
|
|
14
|
+
|
|
15
|
+
OP [+\-*/=<>]
|
|
16
|
+
|
|
17
|
+
COMMENT1 "//".*
|
|
18
|
+
COMMENT2 "/\*([^*]|\*+[^*/])*\*/"
|
|
19
|
+
|
|
20
|
+
%%
|
|
21
|
+
|
|
22
|
+
{KEYWORD} { printf("Keyword: %s\n", yytext); }
|
|
23
|
+
|
|
24
|
+
{FLOAT} { printf("Float: %s\n", yytext); }
|
|
25
|
+
|
|
26
|
+
{INT} { printf("Integer: %s\n", yytext); }
|
|
27
|
+
|
|
28
|
+
{IDENT} { printf("Identifier: %s\n", yytext); }
|
|
29
|
+
|
|
30
|
+
{OP} { printf("Operator: %s\n", yytext); }
|
|
31
|
+
|
|
32
|
+
{COMMENT1} { printf("Comment: %s\n", yytext); }
|
|
33
|
+
|
|
34
|
+
{COMMENT2} { printf("Comment: %s\n", yytext); }
|
|
35
|
+
|
|
36
|
+
[ \t\n]+ { /* ignore whitespace */ }
|
|
37
|
+
|
|
38
|
+
. { printf("Other: %s\n", yytext); }
|
|
39
|
+
|
|
40
|
+
%%
|
|
41
|
+
|
|
42
|
+
int yywrap() {
|
|
43
|
+
return 1;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
int main() {
|
|
47
|
+
|
|
48
|
+
yylex();
|
|
49
|
+
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
%{
|
|
2
|
+
#include <stdio.h>
|
|
3
|
+
#include <ctype.h>
|
|
4
|
+
|
|
5
|
+
int wordCount = 0;
|
|
6
|
+
int charCount = 0;
|
|
7
|
+
int spaceCount = 0;
|
|
8
|
+
int lineCount = 0;
|
|
9
|
+
%}
|
|
10
|
+
|
|
11
|
+
%%
|
|
12
|
+
|
|
13
|
+
[ \t] { spaceCount++; charCount++; }
|
|
14
|
+
|
|
15
|
+
\n { lineCount++; charCount++; }
|
|
16
|
+
|
|
17
|
+
[a-zA-Z0-9_]+ { wordCount++; charCount += yyleng; }
|
|
18
|
+
|
|
19
|
+
. { charCount++; }
|
|
20
|
+
|
|
21
|
+
%%
|
|
22
|
+
|
|
23
|
+
int yywrap() {
|
|
24
|
+
return 1;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
int main() {
|
|
28
|
+
|
|
29
|
+
yyin = fopen("input.c", "r");
|
|
30
|
+
|
|
31
|
+
if (!yyin) {
|
|
32
|
+
printf("Cannot open input.c\n");
|
|
33
|
+
return 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
yylex();
|
|
37
|
+
|
|
38
|
+
printf("Word Count: %d\n", wordCount);
|
|
39
|
+
printf("Character Count: %d\n", charCount);
|
|
40
|
+
printf("Blank Spaces: %d\n", spaceCount);
|
|
41
|
+
printf("Line Count: %d\n", lineCount);
|
|
42
|
+
|
|
43
|
+
fclose(yyin);
|
|
44
|
+
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
%{
|
|
2
|
+
#include <stdio.h>
|
|
3
|
+
#include <string.h>
|
|
4
|
+
|
|
5
|
+
void print_substrings(char *s);
|
|
6
|
+
%}
|
|
7
|
+
|
|
8
|
+
%%
|
|
9
|
+
|
|
10
|
+
"abcd" {
|
|
11
|
+
/* yytext holds the matched string "abcd" */
|
|
12
|
+
print_substrings(yytext);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.|\n { /* Ignore all other characters */ }
|
|
16
|
+
|
|
17
|
+
%%
|
|
18
|
+
|
|
19
|
+
void print_substrings(char *s) {
|
|
20
|
+
int len = strlen(s);
|
|
21
|
+
int i;
|
|
22
|
+
|
|
23
|
+
for (i = len; i >= 1; i--) {
|
|
24
|
+
printf("%.*s\n", i, s);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
int main(void) {
|
|
29
|
+
printf("Please enter the string 'abcd': \n");
|
|
30
|
+
yylex();
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
int yywrap() {
|
|
35
|
+
return 1;
|
|
36
|
+
}
|