aboutsummaryrefslogtreecommitdiff
path: root/calc.y
diff options
context:
space:
mode:
Diffstat (limited to 'calc.y')
-rw-r--r--calc.y11
1 files changed, 10 insertions, 1 deletions
diff --git a/calc.y b/calc.y
index e6bb2d9..3ca3083 100644
--- a/calc.y
+++ b/calc.y
@@ -3,7 +3,11 @@
package main
-import "math"
+import (
+ "math"
+ "math/rand"
+ "time"
+)
var reg = map[string]float64{
"pi": math.Pi,
@@ -46,6 +50,7 @@ exp
: NUMBER
| WORD { $$ = reg[$1] }
| '_' { $$ = reg[last] }
+ | '!' { $$ = rand.Float64() }
| exp '+' exp { $$ = $1 + $3 }
| exp '-' exp { $$ = $1 - $3 }
| exp '*' exp { $$ = $1 * $3 }
@@ -59,6 +64,10 @@ exp
%%
+func init() {
+ rand.Seed(time.Now().UnixNano())
+}
+
func Parse(input string) (float64, bool, error) {
l := lex(input)
yyParse(l)