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.
- Comprehensive Trigonometric Support: Evaluate functions like
sin,cos, andtanwith 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.
Follow these simple steps to install, compile, and run the program.
- A Linux-based operating system (tested on Linux Mint).
- GCC (GNU Compiler Collection) installed on your system.
Use the following command to compile the code:
gcc -o trig_evaluator trig_evaluator.c -lm- The
-lmflag links the math library, which is essential for operations likesin,cos, andpow.
Run the program with the expression you want to evaluate as a command-line argument:
./trig_evaluator "<expression>"Here are some examples to help you get started:
-
Simple Arithmetic:
./trig_evaluator "3 + 5 * 2"Output:
Result: 13.000000 -
Trigonometric Evaluation:
./trig_evaluator "sin(30) + cos(60) - tan(45)"Output:
Result: 0.500000 -
Nested Expressions:
./trig_evaluator "(2 + 3)^2 - 10 / 5"Output:
Result: 23.000000