G2A Many GEOs
SHARE
TWEET

Untitled

a guest Dec 10th, 2019 18 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Running the example program
  2. Compilation, e.g.: clang++-7 -std=c++17 main.cpp
  3.  
  4. Running: ./a.out "7 l / 100 km" (mind the double quotes and spaces between tokens).
  5.  
  6. # Unit Conversion Scripting Language (UCSL)
  7. A language for unit conversions. UCSL is able to find a chain of implicit conversions needed to end up with desired result unit.
  8.  
  9. # Hello world
  10.  
  11. print 1 Hello / 1 World!
  12.  
  13. # Statements
  14. ## constant
  15. Defines a constant that is used for conversion. E.g.
  16.  
  17. ```
  18. constant 1000 m <-> 1 km
  19. constant 0.01 m <-> 1 cm
  20. ```
  21. To properly categorize units, make sure that the units from one category are always 'chained'. E.g. here the units are not chained and two categories are created, instead of just one.
  22.  
  23. ```
  24. constant 1 cm <-> 10 mm
  25. constant 1 km <-> 1000 m
  26. constant 1 m <-> 100 cm
  27. ```
  28. There is no connection between defining cm <-> mm and km <-> m. To chain the units properly, rearrange constants in such way:
  29.  
  30. ```
  31. constant 1 cm <-> 10 mm
  32. constant 1 m <-> 100 cm
  33. constant 1 km <-> 1000 m
  34. ```
  35. Chaining units from one category can be interrupted. E.g. this script is valid:
  36.  
  37. ```
  38. constant 1 cm <-> 10 mm
  39. constant 1000 g <-> 1 kg
  40. constant 1 m <-> 100 cm
  41. print 1 g / 42.42 mm to X g / 20 m
  42. ```
  43.  
  44. ## value
  45. Defines a named value with a result of value expression. Later on, the name can be referred.
  46.  
  47. ```
  48. value value_name 42 km / 1 h
  49. value another_value value_name
  50. ```
  51.  
  52. ## print
  53. Prints result of a value expression to stdout.
  54.  
  55. ```
  56. print 1 m / 2 s
  57. ```
  58. Prints: 1 m / 2 s
  59.  
  60. ## to operator
  61. Converts a value in one unit to a value in another unit. Conversion has to be known based on constants.
  62.  
  63. ```
  64. constant 1.605 km <-> 1 mi
  65. constant 3.785 l <-> 1 gal
  66. value l_per_100_km 7 l / 100 km
  67. value conversion_result l_per_100_km to X mi / 1 gal
  68. print conversion_result
  69. ```
  70. This script prints `33.605 mi / 1 gal` to stdout.
  71.  
  72. The X indicates that the mi value can change. That's why the result is some amount of miles per one gallon. X can appear in the denominator as well. X must apprear exactly once in the desired unit, otherwise the behavior is undefined.
  73.  
  74. to operator automatically detects conversion chain. Here, it detects that it needs to convert m to km and then km to mi to meet desired unit.
  75.  
  76. ```
  77. constant 1.605 km <-> 1 mi
  78. constant 1000 m <-> 1 km
  79. constant 3.785 l <-> 1 gal
  80. value l_per_m 0.00007 l / 1 m
  81. value conversion_result l_per_100_km to X mi / 1 gal
  82. print conversion_result
  83. ```
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top