init
Browse files- .gitignore +0 -52
- README.md +0 -53
- compiler.c +0 -84
.gitignore
DELETED
|
@@ -1,52 +0,0 @@
|
|
| 1 |
-
# Prerequisites
|
| 2 |
-
*.d
|
| 3 |
-
|
| 4 |
-
# Object files
|
| 5 |
-
*.o
|
| 6 |
-
*.ko
|
| 7 |
-
*.obj
|
| 8 |
-
*.elf
|
| 9 |
-
|
| 10 |
-
# Linker output
|
| 11 |
-
*.ilk
|
| 12 |
-
*.map
|
| 13 |
-
*.exp
|
| 14 |
-
|
| 15 |
-
# Precompiled Headers
|
| 16 |
-
*.gch
|
| 17 |
-
*.pch
|
| 18 |
-
|
| 19 |
-
# Libraries
|
| 20 |
-
*.lib
|
| 21 |
-
*.a
|
| 22 |
-
*.la
|
| 23 |
-
*.lo
|
| 24 |
-
|
| 25 |
-
# Shared objects (inc. Windows DLLs)
|
| 26 |
-
*.dll
|
| 27 |
-
*.so
|
| 28 |
-
*.so.*
|
| 29 |
-
*.dylib
|
| 30 |
-
|
| 31 |
-
# Executables
|
| 32 |
-
*.exe
|
| 33 |
-
*.out
|
| 34 |
-
*.app
|
| 35 |
-
*.i*86
|
| 36 |
-
*.x86_64
|
| 37 |
-
*.hex
|
| 38 |
-
|
| 39 |
-
# Debug files
|
| 40 |
-
*.dSYM/
|
| 41 |
-
*.su
|
| 42 |
-
*.idb
|
| 43 |
-
*.pdb
|
| 44 |
-
|
| 45 |
-
# Kernel Module Compile Results
|
| 46 |
-
*.mod*
|
| 47 |
-
*.cmd
|
| 48 |
-
.tmp_versions/
|
| 49 |
-
modules.order
|
| 50 |
-
Module.symvers
|
| 51 |
-
Mkfile.old
|
| 52 |
-
dkms.conf
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
DELETED
|
@@ -1,53 +0,0 @@
|
|
| 1 |
-
# Compiler
|
| 2 |
-
|
| 3 |
-
This is a simple C program named `compiler.c` that implements a recursive descent parser for evaluating arithmetic expressions.
|
| 4 |
-
|
| 5 |
-
## Description
|
| 6 |
-
|
| 7 |
-
The `compiler.c` file contains a basic implementation of a recursive descent parser for arithmetic expressions. It supports addition, subtraction, multiplication, and division operations, as well as parentheses for grouping expressions. The program reads an arithmetic expression entered by the user, evaluates it, and prints the result.
|
| 8 |
-
|
| 9 |
-
## Usage
|
| 10 |
-
|
| 11 |
-
To use the compiler, follow these steps:
|
| 12 |
-
|
| 13 |
-
1. Clone the repository:
|
| 14 |
-
|
| 15 |
-
```
|
| 16 |
-
git clone https://github.com/Ismat-Samadov/compiler.git
|
| 17 |
-
```
|
| 18 |
-
|
| 19 |
-
2. Navigate to the directory:
|
| 20 |
-
|
| 21 |
-
```
|
| 22 |
-
cd compiler
|
| 23 |
-
```
|
| 24 |
-
|
| 25 |
-
3. Compile the `compiler.c` file:
|
| 26 |
-
|
| 27 |
-
```
|
| 28 |
-
gcc compiler.c -o compiler
|
| 29 |
-
```
|
| 30 |
-
|
| 31 |
-
4. Run the compiled program:
|
| 32 |
-
|
| 33 |
-
```
|
| 34 |
-
./compiler
|
| 35 |
-
```
|
| 36 |
-
|
| 37 |
-
5. Enter an arithmetic expression when prompted.
|
| 38 |
-
|
| 39 |
-
6. The program will evaluate the expression and print the result.
|
| 40 |
-
|
| 41 |
-
## Example
|
| 42 |
-
|
| 43 |
-
Here's an example of using the compiler:
|
| 44 |
-
|
| 45 |
-
```
|
| 46 |
-
$ ./compiler
|
| 47 |
-
Enter an arithmetic expression: 5+3
|
| 48 |
-
Result: 8
|
| 49 |
-
```
|
| 50 |
-
|
| 51 |
-
## Contributing
|
| 52 |
-
|
| 53 |
-
Contributions to this project are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
compiler.c
DELETED
|
@@ -1,84 +0,0 @@
|
|
| 1 |
-
#include <stdio.h>
|
| 2 |
-
#include <stdlib.h>
|
| 3 |
-
#include <ctype.h>
|
| 4 |
-
|
| 5 |
-
int expr();
|
| 6 |
-
int term();
|
| 7 |
-
int factor();
|
| 8 |
-
void error();
|
| 9 |
-
|
| 10 |
-
char token;
|
| 11 |
-
|
| 12 |
-
void next_token() {
|
| 13 |
-
token = getchar();
|
| 14 |
-
}
|
| 15 |
-
|
| 16 |
-
void match(char expected_token) {
|
| 17 |
-
if (token == expected_token) {
|
| 18 |
-
next_token();
|
| 19 |
-
} else {
|
| 20 |
-
error();
|
| 21 |
-
}
|
| 22 |
-
}
|
| 23 |
-
|
| 24 |
-
void error() {
|
| 25 |
-
printf("Syntax error\n");
|
| 26 |
-
exit(1);
|
| 27 |
-
}
|
| 28 |
-
|
| 29 |
-
int expr() {
|
| 30 |
-
int result = term();
|
| 31 |
-
while (token == '+' || token == '-') {
|
| 32 |
-
char op = token;
|
| 33 |
-
next_token();
|
| 34 |
-
if (op == '+') {
|
| 35 |
-
result += term();
|
| 36 |
-
} else {
|
| 37 |
-
result -= term();
|
| 38 |
-
}
|
| 39 |
-
}
|
| 40 |
-
return result;
|
| 41 |
-
}
|
| 42 |
-
|
| 43 |
-
int term() {
|
| 44 |
-
int result = factor();
|
| 45 |
-
while (token == '*' || token == '/') {
|
| 46 |
-
char op = token;
|
| 47 |
-
next_token();
|
| 48 |
-
if (op == '*') {
|
| 49 |
-
result *= factor();
|
| 50 |
-
} else {
|
| 51 |
-
int divisor = factor();
|
| 52 |
-
if (divisor != 0) {
|
| 53 |
-
result /= divisor;
|
| 54 |
-
} else {
|
| 55 |
-
error();
|
| 56 |
-
}
|
| 57 |
-
}
|
| 58 |
-
}
|
| 59 |
-
return result;
|
| 60 |
-
}
|
| 61 |
-
|
| 62 |
-
int factor() {
|
| 63 |
-
int result;
|
| 64 |
-
if (isdigit(token)) {
|
| 65 |
-
ungetc(token, stdin);
|
| 66 |
-
scanf("%d", &result);
|
| 67 |
-
next_token();
|
| 68 |
-
} else if (token == '(') {
|
| 69 |
-
next_token();
|
| 70 |
-
result = expr();
|
| 71 |
-
match(')');
|
| 72 |
-
} else {
|
| 73 |
-
error();
|
| 74 |
-
}
|
| 75 |
-
return result;
|
| 76 |
-
}
|
| 77 |
-
|
| 78 |
-
int main() {
|
| 79 |
-
printf("Enter an arithmetic expression: ");
|
| 80 |
-
next_token();
|
| 81 |
-
int result = expr();
|
| 82 |
-
printf("Result: %d\n", result);
|
| 83 |
-
return 0;
|
| 84 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|