Paste: calc deploy test

Author: mrjbq7
Mode: factor
Date: Wed, 10 Dec 2014 16:38:13
Plain Text |
USING: command-line fry io kernel macros math math.parser
namespaces peg.ebnf prettyprint sequences strings ;
IN: b

EBNF: parse-calc

sign   = "-"          => [[ >string ]]
whole  = ([0-9])*     => [[ >string ]]
digit  = "." ([0-9])* => [[ [ >string ] map concat ]]

number = sign? whole digit?  
=> [[ [ f eq? not ] filter concat string>number ]]

add  = "+"  => [[ [ + ] ]]         
sub  = "-"  => [[ [ - ] ]]         
mul  = "*"  => [[ [ * ] ]]         
div  = "/"  => [[ [ / ] ]]

ops  = add|sub|mul|div

expr = number ops number
=> [[ [ first ] [ third ] [ second ] tri '[ _ _ @ ] ]]

;EBNF

MACRO: calc ( string -- ) parse-calc ;


: b-main ( -- )
    command-line get [
        first parse-calc call( -- x ) number>string print
    ] unless-empty ;

MAIN: b-main

Annotation: deploy.factor

Author: mrjbq7
Mode: factor
Date: Wed, 10 Dec 2014 16:38:27
Plain Text |
USING: tools.deploy.config ;
H{
    { deploy-c-types? f }
    { deploy-help? f }
    { deploy-name "b" }
    { "stop-after-last-window?" t }
    { deploy-unicode? f }
    { deploy-console? t }
    { deploy-io 3 }
    { deploy-reflection 1 }
    { deploy-ui? f }
    { deploy-word-defs? f }
    { deploy-threads? t }
    { deploy-math? t }
    { deploy-word-props? f }
}

Annotation: run it like this

Author: mrjbq7
Mode: factor
Date: Wed, 10 Dec 2014 16:40:37
Plain Text |
$ ./b 2+2
4

New Annotation

Summary:
Author:
Mode:
Body: