bcalc

cli bitcoin unit calculator
git clone git://jb55.com/bcalc
Log | Files | Refs | README | LICENSE

commit f0198314a1678d11a4e8cbc6381b5682536f099d
parent 465405e43b9438166a4f040f61a805efede57f20
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 23 Dec 2017 18:47:52 -0800

grammar: "expr in unit"

new grammar to specify the output unit

Diffstat:
Mlexer.l | 4++++
Mparser.y | 3++-
Mtest/tests.csv | 2++
3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/lexer.l b/lexer.l @@ -19,6 +19,10 @@ return T_UNIT; } +in|IN { + return T_IN; +} + [mM]?[bB][tT][cC] { int ism = yytext[0] == 'm' || yytext[0] == 'M'; yylval.unit = ism? UNIT_MBTC : UNIT_BTC; diff --git a/parser.y b/parser.y @@ -21,7 +21,7 @@ int g_print_unit; %token<floatval> T_FLOAT %token<unit> T_UNIT -%token T_PLUS T_MINUS T_MULTIPLY T_DIVIDE T_LEFT T_RIGHT +%token T_PLUS T_MINUS T_MULTIPLY T_DIVIDE T_LEFT T_RIGHT T_IN %token T_NEWLINE T_QUIT %left T_PLUS T_MINUS %left T_MULTIPLY T_DIVIDE @@ -38,6 +38,7 @@ calc: line: T_NEWLINE | expr T_NEWLINE { num_print(&$1, g_output_format, g_print_unit); } + | expr T_IN T_UNIT T_NEWLINE { num_print(&$1, $3, g_print_unit); } ; unit_number: diff --git a/test/tests.csv b/test/tests.csv @@ -27,6 +27,8 @@ simple fiat test with bits,--price 15000 --bits,1 fiat,66.66666 bits 1 btc/2 should work,--btc -n,1 btc / 2,0.5 60 usd at 25000 in bits,--bits --price 25000,60 fiat,2400 bits penny usd to msats,--price 20000 --msats,0.01 usd,50000 msat +100 mbtc in bits grammar,,100 mbtc in bits,100000 bits +100 mbtc in bits grammar with arith,,100 mbtc + 2 btc in btc,2.1 BTC # failing 1 BTC is 15000 usd,--price 15000 --usd,1 btc,15000 USD # needs implementation