As part of the effort to allow web programming in Cedalion, we created a transformation of Cedalion code into Javascript. This allows Javascript code running on the browser to consult the Cedalion program, without connecting to a server.

# Calculator Demo

Below are two text boxes. One contains an expression. Try editing the expression and you'll see the result below. The other text-box will show you how long it took it to parse the input, calculate the result and update the display.

This is a unit calculator, that performs calculations on physical units. Try the expressions below, or build your own expression. The result will be given in SI units, or in the units of your choice when asking for them, using "in".

This calculator can also make currency conversions, or perform computations based on currencies. In this demo we use fake values, just to demonstrate the technology, so don't rely on these results for anything useful...

Below are a few examples accepted by this calculator:

- Basic arithmetics: (1+2)*3/4
- Fractions: 1.23/4.56
- Unit conversion: 100 meters in feet
- Unit arithmetics: 80 oz + 250 grams in pounds
- The relation between OZ and FL OZ: 1 fl oz * (0.959 kilogram / liter) in oz
- The wavelength of some radio frequency: (300000 kilometer / second) / 91.8 megahertz
- Currency conversion: 200 JPY in USD
- Currency arithmetics: 200 JPY + 2 GBP in EUR
- Financial calculation: 200 acres * (3 EUR / sq meter) in USD

# Implementation

Unlike other online calculators, such as the Google Calculator, which parse the expression and calculate the value on the server, this calculator works entirely on the client side, apart for AJAX calls to retrieve currency rates.

The logic of this calculator is implemented in Cedalion, and translated to Javascript. It is implemented in a DSL for parsing (based on BNF notation), combined with a DSL for AJAX expressions (expressions which need AJAX calls to as part of their evaluation). For your reference, we added a part of the implementation below.

## Number Format

## Physical Measure Syntax

## Arithmetic Operations