The syntax is still a little rough around the edges, but works like this. The Base Unit statement defines a dimension and specifies its base unit from which other units can be derived. The Unit statement defines a unit and may include a conversion formula. There are ways to specify (1) that the unit is defined by the SI; (2) aliases, such as meter vs metre and meter vs meters vs m. A consequence of declaring an SI unit is the automatic creation of conversion factors of 10 with the standard prefixes, such as Kilometer and km. While VF's keywords and identifiers are case-insensitive, units are case-sensitive, just as they are in the real world.
Rather than giving the grammar, I'll just post my test file for you all to look over and give your opinions about it.
Code: |
module StdUnits
base unit length in meters unit -meter(s) metre(s) m unit inch(es) = 2.54cm unit foot feet ft = 12inches unit yard(s) yd(s) = 3feet unit mile(s) mi = 5280feet unit light_year(s) ly = 9.4605284 petameters base unit time in seconds unit -second(s) sec(s) s unit minute(s) min(s) m = 60secs unit hour(s) h = 60mins base unit speed in meters/second = length/time unit MPH = miles/hour base unit angle in radians unit radian(s) rad unit degree(s) deg = 0.0174532925 radians unit gradian(s) grad = 0.9 degrees base unit temperature in Kelvin unit Kelvin K unit degree_C degrees_C += 273.15 Kelvin unit degree_F degrees_F = 1.8 degrees_C + 32 unit Rankine R = (0 degrees_C + 273.15) * 1.8 base unit area in meters2 = meters * meters unit -meter2 meters2 metre2 metres2 m2 unit hectare ha = 10000 meters2 unit square_foot square_feet sq_ft = 0.09290304 meters2 base unit seconds_squared in seconds2 = seconds * seconds unit second2 seconds2 sec2 secs2 s2 base unit acceleration in meters/second2 = length/time/time unit Earth_gravity g = 9.80665 m/s2 base unit mass in kilograms unit -gram(s) g unit metric_ton(s) metric_tonne(s) t = 1000 kilograms |