-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 11c61e8
Showing
285 changed files
with
2,255,052 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# BTech Assignments | ||
A repository of my BTech assignments for papers: | ||
* IT351: Data Structures (C) | ||
* IT451: Computer Organisation and Architecture (VHDL) | ||
* IT453: Computer Graphics (C) | ||
* IT455: Modelling and Simulation (MATLAB) | ||
* IT552: Operating System (C) | ||
* IT553: Database Management System (SQL) | ||
* IT651: Design & Analysis of Algorithms (C) | ||
* IT652: Compiler Design (C) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Assignment 1 | ||
|
||
## Questions | ||
|
||
1. Write a C program to traverse a set of input strings through an FS for integer & floating point number; output is whether the strings are integers or floating point. | ||
|
||
2. Write a C program to filter comments: ```//``` & ```/**/``` from a given input file. | ||
|
||
3. Implement double buffering technique for Lexical Analyzer to separate numbers (int & float), tokens, and remove white spaces and comments. Report lexical errors if there exists any. Assume N = 128, input a C program from file, output numbers, tokens, errors (if any). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
123 | ||
14a | ||
4.501 | ||
174.5.3 | ||
01.67 | ||
88.a | ||
.51 | ||
87.. | ||
12. | ||
077 | ||
0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <stdio.h> | ||
|
||
int main(int argc, char *argv[]) { | ||
// this is an inline comment | ||
|
||
// this is another inline comment | ||
|
||
int a = 5; // define an integer | ||
|
||
/* this is | ||
a multiline | ||
comment spread over | ||
4 lines */ | ||
|
||
a = a + 9 * 5; | ||
printf("a /*is equal to*/= %d\n", a); | ||
|
||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
int main(int argc, char *argv[]) { | ||
// this is an inline comment | ||
|
||
// this is another inline comment | ||
|
||
int a = 5; // define an integer | ||
|
||
/* this is | ||
a multiline | ||
comment spread over | ||
4 lines */ | ||
|
||
int b = 9; | ||
b++; | ||
|
||
a = b + 9 * a; | ||
|
||
printf("a /*is equal to*/= %d\n", a); | ||
|
||
int c = b * 1d; float n = 0.05; | ||
n = (float) a / n; | ||
|
||
c <<= 2; | ||
|
||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Integer | ||
Invalid | ||
Float | ||
Invalid | ||
Invalid | ||
Invalid | ||
Float | ||
Invalid | ||
Invalid | ||
Invalid | ||
Integer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
this is an inline comment | ||
|
||
this is another inline comment | ||
|
||
define an integer | ||
|
||
this is | ||
a multiline | ||
comment spread over | ||
4 lines | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
KEYWORD int | ||
IDENTIFIER main | ||
SEPARATOR ( | ||
KEYWORD int | ||
IDENTIFIER argc | ||
SEPARATOR , | ||
KEYWORD char | ||
OPERATOR * | ||
IDENTIFIER argv | ||
SEPARATOR [ | ||
SEPARATOR ] | ||
SEPARATOR ) | ||
SEPARATOR { | ||
KEYWORD int | ||
IDENTIFIER a | ||
OPERATOR = | ||
INTEGER 5 | ||
SEPARATOR ; | ||
KEYWORD int | ||
IDENTIFIER b | ||
OPERATOR = | ||
INTEGER 9 | ||
SEPARATOR ; | ||
IDENTIFIER b | ||
OPERATOR ++ | ||
SEPARATOR ; | ||
IDENTIFIER a | ||
OPERATOR = | ||
IDENTIFIER b | ||
OPERATOR + | ||
INTEGER 9 | ||
OPERATOR * | ||
IDENTIFIER a | ||
SEPARATOR ; | ||
IDENTIFIER printf | ||
SEPARATOR ( | ||
STRING "a /*is equal to*/= %d\n" | ||
SEPARATOR , | ||
IDENTIFIER a | ||
SEPARATOR ) | ||
SEPARATOR ; | ||
KEYWORD int | ||
IDENTIFIER c | ||
OPERATOR = | ||
IDENTIFIER b | ||
OPERATOR * | ||
INVALID 1d | ||
SEPARATOR ; | ||
KEYWORD float | ||
IDENTIFIER n | ||
OPERATOR = | ||
FLOAT 0.05 | ||
SEPARATOR ; | ||
IDENTIFIER n | ||
OPERATOR = | ||
SEPARATOR ( | ||
KEYWORD float | ||
SEPARATOR ) | ||
IDENTIFIER a | ||
OPERATOR / | ||
IDENTIFIER n | ||
SEPARATOR ; | ||
IDENTIFIER c | ||
OPERATOR <<= | ||
INTEGER 2 | ||
SEPARATOR ; | ||
KEYWORD return | ||
INVALID 0 | ||
SEPARATOR ; | ||
SEPARATOR } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
Valid Integers: | ||
begins with 1 - 9, followed by any number | ||
of digits between 0 - 9 | ||
Valid Floating Point numbers: | ||
begins with 0., followed by any number of | ||
digits between 0 - 9 | ||
begins with ., followed by any number of | ||
digits between 0 - 9 | ||
begins with 1 - 9, followed by any number | ||
of digits between 0 - 9, followed by ., | ||
followed any whole number of digits | ||
between 0 - 9 | ||
*/ | ||
|
||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
|
||
int getType(int, char *); | ||
|
||
|
||
int main(int argc, char *argv[]) { | ||
FILE *fi = fopen("input-1.txt", "r"); // input file | ||
FILE *fo = fopen("output-1.txt", "w"); // output file | ||
if (fi == NULL) | ||
goto exit; // exit if no input file | ||
|
||
// run until input strings exist | ||
while (!feof(fi)) { | ||
char string[64]; | ||
fscanf(fi, "%s", string); | ||
|
||
int flag = getType(strlen(string), string); | ||
if (flag == 1) | ||
fprintf(fo, "Integer\n"); | ||
else if (flag == 2) | ||
fprintf(fo, "Float\n"); | ||
else | ||
fprintf(fo, "Invalid\n"); | ||
} | ||
|
||
fclose(fi); | ||
fclose(fo); | ||
exit: return 0; | ||
} | ||
|
||
|
||
// function to determine whether passed string is | ||
// an Integer, Float, or Invalid | ||
int getType(int len, char *s) { | ||
int state = 0, p = 0; | ||
|
||
/* | ||
state 0: initial state | ||
state 1: first digit is between 1 - 9 | ||
(end state) | ||
state 2: decimal has been encountered | ||
state 3: there is atleast one digit after decimal | ||
(end state) | ||
state 4: first digit is 0 | ||
state 5: string isn't an integer or float | ||
(dead state) | ||
*/ | ||
|
||
// loop until end of string or dead state reached | ||
while (state != 5 && p < len) { | ||
char c = *(s + p); | ||
|
||
switch (state) { | ||
// initial state | ||
case 0: | ||
if (c == '0') | ||
state = 4; | ||
else if (c >= '1' && c <= '9') | ||
state = 1; | ||
else if (c == '.') | ||
state = 2; | ||
else | ||
state = 5; | ||
break; | ||
|
||
// first digit is between 1 - 9 | ||
case 1: | ||
if (c >= '0' && c <= '9') | ||
state = 1; | ||
else if (c == '.') | ||
state = 2; | ||
else | ||
state = 5; | ||
break; | ||
|
||
// decimal has been encountered | ||
case 2: | ||
if (c >= '0' && c <= '9') | ||
state = 3; | ||
else | ||
state = 5; | ||
break; | ||
|
||
// there is atleast one digit after decimal | ||
case 3: | ||
if (c >= '0' && c <= '9') | ||
state = 3; | ||
else | ||
state = 5; | ||
break; | ||
|
||
// first digit is 0 | ||
case 4: | ||
if (c == '.') | ||
state = 2; | ||
else | ||
state = 5; | ||
break; | ||
} | ||
|
||
p++; | ||
} | ||
|
||
|
||
if (state == 1 || state == 4) | ||
return 1; | ||
else if (state == 3) | ||
return 2; | ||
else | ||
return 0; | ||
} |
Oops, something went wrong.