This was a class project and took a few days to adequately hash out. It also turned out to be relatively easy and fun - but I didn't want to tell that to the other folks in my comparative languages class who hadn't started on it when I was turning it in. Description of Grammar / Development Notes Lexer Class Source Parser Class Source Parser Applet Source |
Example Expression |
Answer |
y = 1+2*3^4 |
y = 163.0 |
y = (tan(45)*2)/3.22 |
y = 0.6211180124223601 |
y = 10 + 4 * ( 2 + 1 ) + 10 |
y = 32.0 |
x = aln( ln( sin(90))) |
x = 1.0 |
The following operations are supported: |
|
+ |
Addition |
- |
Subtraction |
* |
Multiplication |
/ |
Division |
^ |
Exponentiation |
( ... ) |
Precedence |
sin ( value ) |
sine function (value in degrees) |
cos ( value ) |
cosine function (value in degrees) |
tan ( value ) |
tangent function (value in degrees) |
asin ( value ) |
arcsine function (value in degrees) |
acos ( value ) |
arccosine function (value in degrees) |
atan ( value ) |
arctangent function (value in degrees) |
ln ( value ) |
natural log function |
log ( value ) |
common log (base 10) function |
aln ( value ) |
anti-natural log function |
alog ( value ) |
anti-common log (base 10) function |
The following constants are supported: |
|
PI |
Ratio of circumference to diameter of a circle |
e |
Base of natural log |