Skip to content

Added shell #3

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Program_1/Program_1_CountVowelConsonants
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#line 1 "Program_1_CountVowelConsonants.c"

#line 2 "lex.yy.c"
#line 3 "Program_1_CountVowelConsonants.c"

#define YY_INT_ALIGNED short int

Expand Down Expand Up @@ -442,8 +443,8 @@ char *yytext;

#include <stdio.h>
int vowel = 0, consonants = 0;
#line 445 "lex.yy.c"
#line 446 "lex.yy.c"
#line 446 "Program_1_CountVowelConsonants.c"
#line 447 "Program_1_CountVowelConsonants.c"

#define INITIAL 0

Expand Down Expand Up @@ -662,7 +663,7 @@ YY_DECL
{
#line 8 "Program_1_CountVowelConsonants.l"

#line 665 "lex.yy.c"
#line 666 "Program_1_CountVowelConsonants.c"

while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
{
Expand Down Expand Up @@ -734,7 +735,7 @@ YY_RULE_SETUP
#line 11 "Program_1_CountVowelConsonants.l"
ECHO;
YY_BREAK
#line 737 "lex.yy.c"
#line 738 "Program_1_CountVowelConsonants.c"
case YY_STATE_EOF(INITIAL):
yyterminate();

Expand Down Expand Up @@ -1748,11 +1749,11 @@ int yywrap()
}
int main()
{
printf("\n Enter the string: when done press Ctrl+D to view output\n");
printf("\nEnter the string: when done press Ctrl+D to view output\n");
yylex();
yywrap();
printf("\n The number of vowels in the string is %d\n",vowel);
printf("\n The number of consonants in the string is %d\n",consonants);
printf("\nThe number of vowels in the string is %d\n",vowel);
printf("\nThe number of consonants in the string is %d\n",consonants);
return 0;
}

Binary file removed Program_1/a.out
Binary file not shown.
Binary file added Program_2/Program_2_CountCharWordSpaceDigit
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#line 1 "Program_2_CountCharWordSpaceDigit.c"

#line 2 "lex.yy.c"
#line 3 "Program_2_CountCharWordSpaceDigit.c"

#define YY_INT_ALIGNED short int

Expand Down Expand Up @@ -452,8 +453,8 @@ char *yytext;
int num_digits = 0;
int num_spaces = 0;
int num_tabs = 0;
#line 455 "lex.yy.c"
#line 456 "lex.yy.c"
#line 456 "Program_2_CountCharWordSpaceDigit.c"
#line 457 "Program_2_CountCharWordSpaceDigit.c"

#define INITIAL 0

Expand Down Expand Up @@ -672,7 +673,7 @@ YY_DECL
{
#line 13 "Program_2_CountCharWordSpaceDigit.l"

#line 675 "lex.yy.c"
#line 676 "Program_2_CountCharWordSpaceDigit.c"

while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
{
Expand Down Expand Up @@ -765,7 +766,7 @@ YY_RULE_SETUP
#line 20 "Program_2_CountCharWordSpaceDigit.l"
ECHO;
YY_BREAK
#line 768 "lex.yy.c"
#line 769 "Program_2_CountCharWordSpaceDigit.c"
case YY_STATE_EOF(INITIAL):
yyterminate();

Expand Down Expand Up @@ -1781,6 +1782,7 @@ int main(){
printf("Enter the input string: - after entering the string press Ctrl+D\n");
yylex();
yywrap();
printf("\n");
printf("Number of digits: %d\n", num_digits);
printf("Number of white spaces: %d\n", num_spaces);
printf("Number of lines: %d\n", num_lines);
Expand Down
Binary file removed Program_2/a.out
Binary file not shown.
Binary file not shown.
11 changes: 6 additions & 5 deletions Program_3/lex.yy.c → Program_3/Program_3_CountIntDecFrac.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#line 1 "Program_3_CountIntDecFrac.c"

#line 2 "lex.yy.c"
#line 3 "Program_3_CountIntDecFrac.c"

#define YY_INT_ALIGNED short int

Expand Down Expand Up @@ -457,8 +458,8 @@ char *yytext;
#line 2 "Program_3_CountIntDecFrac.l"
#include <stdio.h>
int posint = 0, negint = 0, posfloat = 0, negfloat = 0, posfrac = 0, negfrac = 0;
#line 460 "lex.yy.c"
#line 461 "lex.yy.c"
#line 461 "Program_3_CountIntDecFrac.c"
#line 462 "Program_3_CountIntDecFrac.c"

#define INITIAL 0

Expand Down Expand Up @@ -677,7 +678,7 @@ YY_DECL
{
#line 6 "Program_3_CountIntDecFrac.l"

#line 680 "lex.yy.c"
#line 681 "Program_3_CountIntDecFrac.c"

while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
{
Expand Down Expand Up @@ -769,7 +770,7 @@ YY_RULE_SETUP
#line 13 "Program_3_CountIntDecFrac.l"
ECHO;
YY_BREAK
#line 772 "lex.yy.c"
#line 773 "Program_3_CountIntDecFrac.c"
case YY_STATE_EOF(INITIAL):
yyterminate();

Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Compiler Design codes for the course 21CS63 conducted at RV College of Engineering, Bangalore.

- The following codes are written in C and are meant to be compiled with CC or GCC compilers.
Expand All @@ -12,11 +11,13 @@
## How to run the code

- To run the code, follow the steps below:
- Open the terminal
- Navigate to the directory where the code is stored
- Run the following commands:
- `flex <filename>.l`
- `gcc lex.yy.c -lfl`
- `./a.out`
- The output will be displayed on the terminal

- Open terminal and navigate to the directory `Compiler-Design/`
- Run the following command to compile the code:
```shell
bash build.sh
```
- This will compile the code and generate an executable file named after the code file.
- To run the code, run the following command:
```shell
./<executable_file>
```
20 changes: 20 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# bin/bash
echo "Building the lexical parser"

# Compile the lexical parser
for folder in $(ls -d */)
do
echo "Building $folder"
cd $folder
for file in $(ls *.l)
do
echo "Building $file"
filename=$(basename -- $file)
filename="${filename%.*}"
lex -o $filename.c $file
gcc $filename.c -lfl -o $filename
echo "Done building $file"
done
cd ..
echo "Done building $folder"
done