Skip to content
Open
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
15 changes: 15 additions & 0 deletions homework/81950/homework2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
all: parser

lexer_code.c: lexer.l
flex lexer.l

lexer: lex.yy.c
gcc lex.yy.c -o lexer

parser.tab.c: parser.y
bison -d -v parser.y

parser.tab.h: parser.tab.c

parser: parser.tab.c parser.tab.h lex.yy.c
${CC} ${CFLAGS} lex.yy.c parser.tab.c -o parser
8 changes: 8 additions & 0 deletions homework/81950/homework2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### Collapsible control structures
1. Run ```bash
make
```
2. Run ```
bash start.sh
```
3. Open js2html.html
25 changes: 25 additions & 0 deletions homework/81950/homework2/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// program to check the number of occurrence of a character

function countString(str, letter) {
let count = 0;

// looping through the items
for (let i = 0; i < str.length; i++) {

// check if the character is at that position
if (str.charAt(i) == letter) {
count += 1;
}
}
return count;
}

// take input from the user
const string = prompt('Enter a string: ');
const letterToCheck = prompt('Enter a letter to check: ');

//passing parameters and calling the function
const result = countString(string, letterToCheck);

// displaying the result
console.log(result);
Loading