Gadgets
Copyright © 2024 Jiri Kriz, www.nosco.ch

Usage

You use the calculator as you would do mathematics on the paper. Type an expression, press the Enter key, and you get the result on the next line. Use '*' for multiplication, '/' for division, and '^' for exponentiation. Numbers can have exponents 'e' or 'E', for example 1.0e-2 means 0.01. You can use variables to store intermediate results. Please note that the variables keep their values only as long as you do not leave the page.

You can reuse previous lines: move the cursor to the respective line, and press Enter. The line will be copied to the end of the sheet, it can be edited there and supplied to the interpreter by pressing Enter. The result will be displayed below.

You can apply the usual mathematical functions and constants in the PHP style. The most common functions and constants are in the respective menus where they can be selected from. Other PHP functions and constants need to be typed into the sheet.

Example

1 + 2 <ENTER>
= 3
x = (1 + 2) * 3 <ENTER>
= 9
y = (x - 1) / 2 <ENTER>
= 4
z = x - sqrt(y) <ENTER>
= 7
Radius = 1 <ENTER>
= 1
A = M_PI * M_PI * Radius^2 <ENTER>
= 3.1415926535898
Area = M_PI * pow(Radius, 2) <ENTER>
= 3.1415926535898

References

PHP functions
PHP constants

Technology

The interaction with the user is done with Javascript. The actual calculator is realized in PHP as top-down recursive descent parser and interpreter. Javascript communicates to PHP using the Ajax technique.

The BNF of the used grammar is:

program := statement
statement := assignment | expression
assignment := variable_name = expression
expression := term | term + term | term - term
term := power | term * power | term / power
power := factor | factor ^ factor
factor := number | variable_name | function_name ( function_call ) | - factor | + factor | ( factor )