[gcalctool/gnome-2-28] Disable ambiguous multiplication with Eulers number, e.g. "2e" as this makes exponential numbers con



commit 9b7efd798f226ce4f1a86162112f09d7c42783e2
Author: Robert Ancell <robert ancell gmail com>
Date:   Wed Dec 16 10:57:32 2009 +1100

    Disable ambiguous multiplication with Eulers number, e.g. "2e" as this makes exponential numbers confusing

 ChangeLog                |    5 +++++
 src/mp-equation-lexer.l  |    5 +++--
 src/mp-equation-parser.y |    6 +++---
 src/unittest.c           |    6 +++---
 4 files changed, 14 insertions(+), 8 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index b59113e..0efbf1a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,11 @@
 gcalctool change history.
 =========================
 
+2009-12-16 Robert Ancell <robert ancell gmail com>
+
+    * Disable ambiguous multiplication with Eulers number, e.g. "2e" as this
+      makes exponential numbers confusing
+
 2009-11-17 Robert Ancell <robert ancell gmail com>
 
     * Fix negative exponential detection e.g. "2eâ??3" = 0.002
diff --git a/src/mp-equation-lexer.l b/src/mp-equation-lexer.l
index f1f9ecf..fd83a32 100644
--- a/src/mp-equation-lexer.l
+++ b/src/mp-equation-lexer.l
@@ -96,11 +96,11 @@ OCT_NUM {OCT}+|{OCT}*{DECIMAL}{OCT}+
 BIN_NUM {BIN}+|{BIN}*{DECIMAL}{BIN}+
 SUP_NUM  {SUPER_DIGITS}+
 SUB_NUM  {SUB_DIGITS}+
-GREEKS   "α"|"β"|"γ"|"δ"|"ε"|"ζ"|"η"|"θ"|"ι"|"κ"|"λ"|"μ"|"ν"|"ξ"|"ο"|"Ï?"|"Ï?"|"Ï?"|"Ï?"|"Ï?"|"Ï?"|"Ï?"|"Ï?"|"Ï?"|"Ï?"
 REGISTERS "R0"|"R1"|"R2"|"R3"|"R4"|"R5"|"R6"|"R7"|"R8"|"R9"
 ANS       [aA][nN][sS]
 RAND      [rR][aA][nN][dD]
-VARIABLE {REGISTERS}|{GREEKS}|"e"|{ANS}|{RAND}
+VARIABLE  {REGISTERS}|"e"|{ANS}|{RAND}
+PI        "Ï?"
 VARIABLE_NAME [a-zA-Z]+
 FUNCTION {VARIABLE_NAME}|{VARIABLE_NAME}{INVERSE}|{VARIABLE_NAME}{SUB_NUM}
 
@@ -129,6 +129,7 @@ NOT  "¬"|"~"|[nN][oO][tT]
 {SUP_NUM}  {yylval->integer = super_atoi(yytext); return tSUPNUM; }
 {SUB_NUM}  {yylval->integer = sub_atoi(yytext); return tSUBNUM; }
 {VARIABLE} {yylval->name = strdup(yytext); return tVARIABLE;}
+{PI}       {yylval->name = strdup(yytext); return tPI;}
 {INVERSE}  {return tINVERSE;}
 
 {DEC_NUM}{EXP}{DEC_NUM} {
diff --git a/src/mp-equation-parser.y b/src/mp-equation-parser.y
index a2f7897..9954f56 100644
--- a/src/mp-equation-parser.y
+++ b/src/mp-equation-parser.y
@@ -111,7 +111,7 @@ static void do_mod(yyscan_t yyscanner, const MPNumber *x, const MPNumber *y, MPN
 %left tMULTIPLY tDIVIDE tMOD MULTIPLICATION
 %left tNOT
 %left tROOT tROOT3 tROOT4
-%left <name> tVARIABLE tFUNCTION
+%left <name> tVARIABLE tPI tFUNCTION
 %right <integer> tSUBNUM tSUPNUM
 %left BOOLEAN_OPERATOR
 %left PERCENTAGE
@@ -136,10 +136,10 @@ exp:
 | exp tINVERSE {mp_reciprocal(&$1, &$$);}
 | exp '!' {mp_factorial(&$1, &$$);}
 | tVARIABLE {get_variable(yyscanner, $1, &$$); free($1);}
-| tVARIABLE tVARIABLE %prec MULTIPLICATION {MPNumber t; get_variable(yyscanner, $1, &t); get_variable(yyscanner, $2, &$$); mp_multiply(&t, &$$, &$$); free($1);}
+| tPI {get_variable(yyscanner, $1, &$$); free($1);}
 | function {mp_set_from_mp(&$1, &$$);}
 | tNUMBER function  %prec MULTIPLICATION {mp_multiply(&$1, &$2, &$$);}
-| tNUMBER tVARIABLE %prec MULTIPLICATION {get_variable(yyscanner, $2, &$$); mp_multiply(&$1, &$$, &$$); free($2);}
+| tNUMBER tPI %prec MULTIPLICATION {get_variable(yyscanner, $2, &$$); mp_multiply(&$1, &$$, &$$); free($2);}
 | tSUBTRACT exp %prec UNARY_MINUS {mp_invert_sign(&$2, &$$);}
 | tADD tNUMBER %prec UNARY_PLUS {mp_set_from_mp(&$2, &$$);}
 | exp tDIVIDE exp {mp_divide(&$1, &$3, &$$);}
diff --git a/src/unittest.c b/src/unittest.c
index 87e266c..f3c7550 100644
--- a/src/unittest.c
+++ b/src/unittest.c
@@ -205,13 +205,13 @@ test_parser()
     test("Ï?", "3.141592654", 0);
     test("e", "2.718281828", 0);
     test("2Ï?", "6.283185307", 0);
-    test("2e", "5.436563657", 0);
+    //test("2e", "5.436563657", 0);
     //test("2Ï?²", "19.739208802", 0);
     //test("2e²", "14.778112198", 0);
     test("e2", "", -1);
     test("Ï?2", "", -1);
-    test("Ï?e", "8.539734223", 0);
-    test("eÏ?", "8.539734223", 0);
+    //test("Ï?e", "8.539734223", 0);
+    //test("eÏ?", "8.539734223", 0);
     //test("2Ï?e", "17.079468445", 0);
 
     test("0+0", "0", 0);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]