https://github.com/malk97sc/trigonometric
Trigonometric Expression Evaluator
https://github.com/malk97sc/trigonometric
c compiler ll1-grammar ll1-parser trigonometric-calculations
Last synced: 7 months ago
JSON representation
Trigonometric Expression Evaluator
- Host: GitHub
- URL: https://github.com/malk97sc/trigonometric
- Owner: Malk97sc
- Created: 2024-11-25T23:11:31.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-03-07T03:20:36.000Z (7 months ago)
- Last Synced: 2025-03-07T04:25:24.880Z (7 months ago)
- Topics: c, compiler, ll1-grammar, ll1-parser, trigonometric-calculations
- Language: C
- Homepage:
- Size: 27.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Trigonometric Expression Evaluator
**Trigonometric Expression Evaluator**, a lightweight and efficient program designed to parse and evaluate complex mathematical expressions. Built using the powerful principles of **LL(1) grammar** and **recursive descent parsing**, this evaluator is perfect for anyone delving into compiler design, numerical computations, or advanced mathematics.
## Features
- **Comprehensive Trigonometric Support**: Evaluate functions like `sin`, `cos`, and `tan` with degree input.
- **Arithmetic Operations**: Perform operations such as `+`, `-`, `*`, `/`, and exponentiation `^`.
- **Error Handling**: Detect invalid inputs, manage division by zero, and handle syntax errors gracefully.
- **Educational Value**: A practical implementation of compiler theory concepts for real-world applications.## Getting Started
Follow these simple steps to install, compile, and run the program.
### 1. Prerequisites
- A Linux-based operating system (tested on Linux Mint).
- GCC (GNU Compiler Collection) installed on your system.### 2. Compiling
Use the following command to compile the code:
```bash
gcc -o trig_evaluator trig_evaluator.c -lm
```- The `-lm` flag links the math library, which is essential for operations like `sin`, `cos`, and `pow`.
### 3. Running
Run the program with the expression you want to evaluate as a command-line argument:
```bash
./trig_evaluator ""
```## Examples
Here are some examples to help you get started:
- **Simple Arithmetic**:
```bash
./trig_evaluator "3 + 5 * 2"
```
Output:
```
Result: 13.000000
```- **Trigonometric Evaluation**:
```bash
./trig_evaluator "sin(30) + cos(60) - tan(45)"
```
Output:
```
Result: 0.500000
```- **Nested Expressions**:
```bash
./trig_evaluator "(2 + 3)^2 - 10 / 5"
```
Output:
```
Result: 23.000000
```