Skip to content

Malk97sc/Trigonometric

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

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:

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:

./trig_evaluator "<expression>"

Examples

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
    

About

Trigonometric Expression Evaluator

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages