]> gitweb.factorcode.org Git - factor.git/commitdiff
infix: adding pow().
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 4 Apr 2013 22:04:14 +0000 (15:04 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 4 Apr 2013 22:04:14 +0000 (15:04 -0700)
extra/infix/infix-tests.factor
extra/infix/infix.factor
extra/infix/parser/parser.factor

index 342f436271607405265829e30c6a97d4883cc769..8a729aa3445b56f4fd7103e92437d5f8187e4a9c 100644 (file)
@@ -8,6 +8,7 @@ IN: infix.tests
 [ 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*
index 9cb01454bb6f1db66c88a32f50e935c55f660007..96887687dc0b82a60c3b7a01d779bb2d186cee0e 100644 (file)
@@ -2,8 +2,9 @@
 ! 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
 
@@ -18,13 +19,17 @@ M: local-not-defined summary
 : >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 )
index def3898fad8300f7bd6d4f6941b90c1e90a2f1f2..5b02dd05c257542aaed9257de40f8c5e632c7597 100644 (file)
@@ -21,7 +21,7 @@ Terminal    =   ("-"|"+"):op Terminal:term => [[ term op "-" = [ ast-negation bo
               | 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 ]]