-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInteger_Recognizer.l
More file actions
65 lines (57 loc) · 2.13 KB
/
Integer_Recognizer.l
File metadata and controls
65 lines (57 loc) · 2.13 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
%{
/*
* =========================================================================================
* Experiment 10.1: Integer Recognizer using LEX
* Course: System Programming and Compiler Construction (SPCC)
*
* Author: Amey Thakur
* GitHub: https://github.com/Amey-Thakur
* Repository: https://github.com/Amey-Thakur/SYSTEM-PROGRAMMING-AND-COMPILER-CONSTRUCTION-AND-SYSTEM-SOFTWARE-LAB
* =========================================================================================
*
* TECHNICAL LOGIC EXPLANATION:
* This program serves as a specialized pattern matcher designed to extract and identify
* whole numbers (integers) from a stream of text data.
*
* Detection Logic:
* 1. Rule Definition: The regular expression [0-9]+ specifies a pattern where one
* or more numeric digits occur consecutively.
* 2. Scan Phase: The LEX engine evaluates incoming text against this pattern.
* 3. Identification: When a match is secured, the program identifies the segment
* as a 'Lexeme' of type 'Integer' and logs its value.
* 4. Filtering: Any characters that do not conform to the numeric pattern (like
* letters or symbols) are filtered out and discarded.
*/
#include <stdio.h>
%}
/*
* PATTERN RULES SECTION
*/
%%
[0-9]+ {
/* Action: Print the successfully matched numeric sequence */
printf("\n[REPORT] Lexeme identified: %s | Result: Valid Integer\n", yytext);
}
.|\n {
/* Action: Silence (Ignore all non-numeric characters and whitespace) */
}
%%
/*
* USER EXECUTION LOGIC
*/
/* Required function to handle single-input source completion */
int yywrap() {
return 1;
}
int main(void) {
printf("==============================================\n");
printf(" INTEGER RECOGNIZER (LEX) \n");
printf("==============================================\n");
printf("Operation: Extracting numeric patterns from input.\n");
printf("Usage: Type input and observe extraction results.\n");
printf("Input Stream (End with Ctrl+D / Ctrl+Z):\n");
/* Initiating the scanner engine */
yylex();
printf("\n==============================================\n");
return 0;
}