[ 0.5 ] [ [infix 3.0/6 infix] ] unit-test
[ 1+2/3 ] [ [infix 5/3 infix] ] unit-test
[ 3 ] [ [infix 2*7%3+1 infix] ] unit-test
+[ 1419857 ] [ [infix 17**5 infix] ] unit-test
[ 1 ] [ [infix 2-
1
-5*
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs combinators combinators.short-circuit
effects fry infix.parser infix.ast kernel locals locals.parser
-locals.types math math.order math.ranges multiline namespaces
-parser quotations sequences summary words vocabs.parser ;
+locals.types math math.functions math.order math.ranges
+multiline namespaces parser quotations sequences summary
+words vocabs.parser ;
IN: infix
: >local-word ( string -- word )
locals get ?at [ local-not-defined ] unless ;
+ERROR: invalid-op string ;
+
: select-op ( string -- word )
{
{ "+" [ [ + ] ] }
{ "-" [ [ - ] ] }
{ "*" [ [ * ] ] }
{ "/" [ [ / ] ] }
- [ drop [ mod ] ]
+ { "%" [ [ mod ] ] }
+ { "**" [ [ ^ ] ] }
+ [ invalid-op ]
} case ;
GENERIC: infix-codegen ( ast -- quot/number )
| Number | Array | Slice | Function
| Identifier => [[ ast-local boa ]]
-Product = Product:p ("*"|"/"|"%"):op Terminal:term => [[ p term op ast-op boa ]]
+Product = Product:p ("**"|"*"|"/"|"%"):op Terminal:term => [[ p term op ast-op boa ]]
| Terminal
Sum = Sum:s ("+"|"-"):op Product:p => [[ s p op ast-op boa ]]