lexyacc-calculator
This Interpreter includes 2 files to run a flex file and a yacc file.
- Open the terminal and go to the folder where these files are
- Write the the command lex bc.l to compile the lex file
- Then write yacc term1.y to compile the yacc file , this will generate y.tab.c
- Then compile y.tab.c using c compiler to generate a.out by writing the command cc y.tab.c -ly -ll -lm
- Run the a.out file using ./a.out command
- Your calculator is ready
- You can use different functions/operators given in manual
- If u write something other than functions as specified in manual it will give syntax error
- In order to get out of the calculator type ctrl+C .
Scientific calculator using lex and yacc Functions and Instructions :-
- log() :- Logarithmic function used for calculating log value
- pi :- Writing pi will give out the value of pi
- sin() :- Sin function used for calculating sin value
- cos() :- Cos function used for calculating cos value
- tan() :- Tan function used for calculating tan value
- and :- It will give logical AND of 2 numbers
- sinh() :- Sinh function used for return the sin hypotenuse value
- cosh() :- Cosh function used for returning the cos hypotenuse value
- tanh() :- Tanh function used for returning the tan hypotenuse value
- & :- It used to return bitwise AND of 2 numbers
- xor :- It is used to return XOR of 2 numbers
- or :- It is used to return OR of 2 numbers
- ceil :- It gives nearest integer greater then or equal to the number
- floor :- It gives nearest integer smaller then or equal to the number
- abs() :- Returns the absolute value of the number
- "<<" :- Left shifts the bits of expression to left of operator by number specified to the right of operator
- ">>" :- Right shifts the bits of expression to left of operator by number specified to the right of operator
- "++" :- Increment the number by 1 by writing ++ after number
- "--" :- Decrement the number by 1 by writing – after number
- "+" :- Used for adding 2 numbers
- "-" :- it is used for subtracting 2 numbers
- "|" :- It gives bitwise OR of 2 numbers;
- "%" :- It return the quotient when dividing 2 numbers
- "*" :- it used for multiplying 2 numbers
- "^" :- Returns the number given by left number to the operator to the power of number to the right of operator
- sqrt() :- It will return the square root value
- "/" :- It return the approximate number when 2 numbers are divided
- "&&" :- Returns logical AND of 2 numbers
- “||” :- Gives logical OR of 2 numbers
- asin() :- asin function used for calculating inverse sin value
- acos() :- acos function used for calculating inverse cos value
- atan() :- atan function used for calculating inverse tan value
- factorial() :- It will calculate the factorial of the given number
- bin_dec() :- Give a number in 1s and 0s and the function will return the decimal value
All the values in trigonometric functions which are inserted or returned are in radians . If the user wants to calculate other than this and if it gives input in the manner other than above specified it will give syntax error . In case of input given is out of range in inverse functions it will print out “nan” i.e. it is out of range . In case of bin_dec function if u give integer other than 0 and 1 it will return the same value.