copied files over for PA3

This commit is contained in:
Ziad Arafat committed 2023-03-05 01:51:17 -07:00
1 parent 571102f413
commit c5f725a309
3 files changed
+67

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
FLAGS = -O0 -Wextra -Wall -pedantic -c
all: main_ada main_bash main_php main_perl
main_ada: main_ada.adb
# Running Ada Code
gcc -c main_ada.adb
gnatmake --GNATBIND=gnatbind --GNATLINK=gnatlink main_ada
./main_ada
# =====================
main_bash: main_bash.sh
# Running Bash Code
bash main_bash.sh
# =====================
main_php: main_php.php
# Running PHP Code
php main_php.php
# =====================
main_perl: main_perl.pl
# Running PHP Code
perl main_perl.pl
# =====================
clean:
rm -f main_ada main_ada.o main_ada.ali
test:
make clean
make
./main
+16
View File
@@ -0,0 +1,16 @@
## Usage
1. Clean, build, and run
```bash
make test
```
2. build all languages
```bash
make
```
3. Clean binaries
```
make clean
```
+18
View File
@@ -0,0 +1,18 @@
# Report
## Ziad Arafat
### 02/21/2023
### Programming Languages PA 2
In our code, we utilized a function call after an `AND` operator to determine whether or not short-circuit evaluation is used in a given programming language. If the language uses short-circuit evaluation, the `print_answer()` function will not be executed and the output will be "`If you only see this then we DO have short circuit evaluation`". However, if the language does not use short-circuit evaluation, the `print_answer()` function will be executed and the output will be "`We DO NOT have short-circuit evaluation!`" followed by "`If you only see this then we DO have short circuit evaluation`". By placing `print_answer()` as the second operand in the `AND` expression, we took advantage of the fact that the second operand will only be evaluated if the first operand is true. In this way, we were able to determine whether or not short-circuit evaluation is used in a given programming language.
| Language | Short-Circuit? | Output |
| -------- | -------------- | ------------------------------------- |
| Ada | No | We DO NOT have short-circuit evaluation! If you only see this then we DO have short circuit evaluation| |
| Bash | Yes | If you only see this then we DO have short circuit evaluation |
| Perl | Yes | If you only see this then we DO have short circuit evaluation |
| PHP | Yes | If you only see this then we DO have short circuit evaluation|
In the Ada example, we're using the `AND` operator and `print_answer` function, but it does not demonstrate short-circuit evaluation since the second operand will always be evaluated in Ada. I think it's worth noting that Ada does have an additional operator called `AND then` which does have short circuit evaluation.
In the Bash, Perl, and PHP examples, we are using the `&&` operator, which demonstrates short-circuit evaluation. The `print_answer` function is only called if the first operand is true, which allows the code to avoid unnecessary evaluations of the second operand if it is not needed to determine the result of the expression.