Skip to content

Commit

Permalink
Implied Multiplication #243 - Global Mode on/off, Unicode Parser Keyw…
Browse files Browse the repository at this point in the history
…ords - Global / Local Mode on/off #249
  • Loading branch information
mariuszgromada committed Mar 20, 2022
1 parent 9097552 commit f8087fb
Show file tree
Hide file tree
Showing 10 changed files with 640 additions and 128 deletions.
163 changes: 108 additions & 55 deletions CURRENT/c-sharp/src/org/mariuszgromada/math/mxparser/Expression.cs

Large diffs are not rendered by default.

75 changes: 70 additions & 5 deletions CURRENT/c-sharp/src/org/mariuszgromada/math/mxparser/mXparser.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* @(#)mXparser.cs 5.0.0 2022-01-29
* @(#)mXparser.cs 5.0.0 2022-03-20
*
* You may use this software under the condition of "Simplified BSD License"
*
Expand Down Expand Up @@ -215,10 +215,6 @@ public sealed class mXparser {
* Threads number settings
*/
private static int THREADS_NUMBER = Environment.ProcessorCount;
/**
* Empty expression for general help purposes.
*/
internal static volatile Expression mXparserExp = new Expression();
/**
* Double floating-point precision arithmetic causes
*
Expand Down Expand Up @@ -279,6 +275,17 @@ public sealed class mXparser {
* built-in tokens.
*/
internal volatile static bool overrideBuiltinTokens = false;
/**
* Implied multiplication mode
*/
internal volatile static bool impliedMultiplicationMode = true;
/**
* Internal indicator informing hte parser
* that unicode know keywords are enabled
* and will be recognized by the parser
* as built-in functions or operators
*/
internal volatile static bool unicodeKeyWordsEnabled = true;
/**
* Options changeset
*/
Expand All @@ -287,6 +294,10 @@ public sealed class mXparser {
* Indicator whether to call cancel current calculation
*/
private static volatile bool cancelCurrentCalculationFlag = false;
/**
* Empty expression for general help purposes.
*/
internal static volatile Expression mXparserExp = new Expression();
/**
* Initialization of prime numbers cache.
* Cache size according to {@link PrimesCache#DEFAULT_MAX_NUM_IN_CACHE}
Expand Down Expand Up @@ -771,6 +782,58 @@ public static bool checkIfRadiansMode() {
public static bool checkIfDegreesMode() {
return degreesMode;
}
/**
* Sets implied multiplication
*/
public static void enableImpliedMultiplicationMode() {
impliedMultiplicationMode = true;
mXparserExp.enableImpliedMultiplicationMode();
}
/**
* Disables implied multiplication
*/
public static void disableImpliedMultiplicationMode() {
impliedMultiplicationMode = false;
mXparserExp.disableImpliedMultiplicationMode();
}
/**
* Gets implied multiplication status
*
* @return true if implied multiplication is enabled,
* otherwise returns false.
*/
public static bool checkIfImpliedMultiplicationMode() {
return impliedMultiplicationMode;
}
/**
* Enables unicode built-in parser keywords, this flag
* informs the parser that built-in unicode keywords
* are supported and will be recognized as functions or
* operators.
*/
public static void enableUnicodeBuiltinKeyWordsMode() {
unicodeKeyWordsEnabled = true;
mXparserExp.enableUnicodeBuiltinKeyWordsMode();
}
/**
* Disables unicode built-in parser keywords, this flag
* informs the parser that built-in unicode keywords
* are not supported and will not be recognized as functions or
* operators.
*/
public static void disableUnicodeBuiltinKeyWordsMode() {
unicodeKeyWordsEnabled = false;
mXparserExp.disableUnicodeBuiltinKeyWordsMode();
}
/**
* Gets unicode built-in parser keywords mode
*
* @return true if unicode built-in parser keywords is enabled,
* otherwise returns false.
*/
public static bool checkIfUnicodeBuiltinKeyWordsMode() {
return unicodeKeyWordsEnabled;
}
/**
* Sets initial search size for the toFraction method
*
Expand Down Expand Up @@ -983,6 +1046,8 @@ public static void setDefaultOptions() {
setDefaultEpsilon();
setEpsilonComparison();
setToFractionInitSearchSize(NumberTheory.DEFAULT_TO_FRACTION_INIT_SEARCH_SIZE);
enableImpliedMultiplicationMode();
enableUnicodeBuiltinKeyWordsMode();
optionsChangesetNumber++;
}
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* @(#)ParserSymbol.cs 5.0.0 2022-03-13
* @(#)ParserSymbol.cs 5.0.0 2022-03-20
*
* You may use this software under the condition of "Simplified BSD License"
*
Expand Down Expand Up @@ -319,6 +319,7 @@ public sealed class ParserSymbol {
public const String BLANK_DESC = "Blank (whitespace) character";
public const String NUMBER_DESC = "Decimal number";
public const String NUMBER_REG_DESC = "Regullar expression for decimal numbers";
public const String UNICODE_MATH = " - unicode math symbol";
/*
* ParserSymbol - since.
*/
Expand Down
137 changes: 136 additions & 1 deletion CURRENT/c-sharp/tests-and-release/4-Unit-Tests/ApiTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* @(#)ApiTest.cs 5.0.0 2022-03-13
* @(#)ApiTest.cs 5.0.0 2022-03-20
*
* You may use this software under the condition of "Simplified BSD License"
*
Expand Down Expand Up @@ -3433,6 +3433,141 @@ public void testApi0128() {
TestCommonTools.consolePrintTestApiEnd(testResult);
Assert.IsTrue(testResult);
}
[TestMethod]
public void testApi0129() {
TestCommonTools.testApiSettingsInit();
bool testResult = false;
String testDescr = "Implied Multiplication on/off API - global and local";
TestCommonTools.consolePrintTestApiStart(129, testDescr);
mXparser.enableImpliedMultiplicationMode();
Expression e1 = new Expression("2pi");
bool global1 = mXparser.checkIfImpliedMultiplicationMode();
bool local1 = e1.checkIfImpliedMultiplicationMode();
mXparser.disableImpliedMultiplicationMode();
Expression e2 = new Expression("2pi");
bool global2 = mXparser.checkIfImpliedMultiplicationMode();
bool local2 = e2.checkIfImpliedMultiplicationMode();
if (global1 && local1 && !global2 && !local2)
testResult = true;
TestCommonTools.consolePrintTestApiEnd(testResult);
Assert.IsTrue(testResult);
}
[TestMethod]
public void testApi0130() {
TestCommonTools.testApiSettingsInit();
bool testResult = false;
String testDescr = "Unicode Parser Keywords on/off API - global and local";
TestCommonTools.consolePrintTestApiStart(130, testDescr);
mXparser.enableUnicodeBuiltinKeyWordsMode();
Expression e1 = new Expression("2pi");
bool global1 = mXparser.checkIfUnicodeBuiltinKeyWordsMode();
bool local1 = e1.checkIfUnicodeBuiltinKeyWordsMode();
mXparser.disableUnicodeBuiltinKeyWordsMode();
Expression e2 = new Expression("2pi");
bool global2 = mXparser.checkIfUnicodeBuiltinKeyWordsMode();
bool local2 = e2.checkIfUnicodeBuiltinKeyWordsMode();
if (global1 && local1 && !global2 && !local2)
testResult = true;
TestCommonTools.consolePrintTestApiEnd(testResult);
Assert.IsTrue(testResult);
}
[TestMethod]
public void testApi0131() {
TestCommonTools.testApiSettingsInit();
bool testResult = false;
String testDescr = "Implied Multiplication on/off API - global - check syntax impact";
TestCommonTools.consolePrintTestApiStart(131, testDescr);
mXparser.enableImpliedMultiplicationMode();
Expression e1 = new Expression("2pi");
bool syn1 = e1.checkSyntax();
mXparser.disableImpliedMultiplicationMode();
Expression e2 = new Expression("2pi");
bool syn2 = e2.checkSyntax();
if (syn1 && !syn2)
testResult = true;
TestCommonTools.consolePrintTestApiEnd(testResult);
Assert.IsTrue(testResult);
}
[TestMethod]
public void testApi0132() {
TestCommonTools.testApiSettingsInit();
bool testResult = false;
String testDescr = "Implied Multiplication on/off API - local - check syntax impact";
TestCommonTools.consolePrintTestApiStart(132, testDescr);
Expression e = new Expression("2pi");
e.enableImpliedMultiplicationMode();
bool syn1 = e.checkSyntax();
e.disableImpliedMultiplicationMode();
bool syn2 = e.checkSyntax();
if (syn1 && !syn2)
testResult = true;
TestCommonTools.consolePrintTestApiEnd(testResult);
Assert.IsTrue(testResult);
}
[TestMethod]
public void testApi0133() {
TestCommonTools.testApiSettingsInit();
bool testResult = false;
String testDescr = "Unicode Parser Keywords on/off API - global - check syntax impact";
TestCommonTools.consolePrintTestApiStart(133, testDescr);
mXparser.enableUnicodeBuiltinKeyWordsMode();
Expression e1 = new Expression("√π");
bool syn1 = e1.checkSyntax();
mXparser.disableUnicodeBuiltinKeyWordsMode();
Expression e2 = new Expression("√π");
bool syn2 = e2.checkSyntax();
if (syn1 && !syn2)
testResult = true;
TestCommonTools.consolePrintTestApiEnd(testResult);
Assert.IsTrue(testResult);
}
[TestMethod]
public void testApi0134() {
TestCommonTools.testApiSettingsInit();
bool testResult = false;
String testDescr = "Unicode Parser Keywords on/off API - local - check syntax impact";
TestCommonTools.consolePrintTestApiStart(134, testDescr);
Expression e = new Expression("√π");
e.enableUnicodeBuiltinKeyWordsMode();
bool syn1 = e.checkSyntax();
e.disableUnicodeBuiltinKeyWordsMode();
bool syn2 = e.checkSyntax();
if (syn1 && !syn2)
testResult = true;
TestCommonTools.consolePrintTestApiEnd(testResult);
Assert.IsTrue(testResult);
}
[TestMethod]
public void testApi0135() {
TestCommonTools.testApiSettingsInit();
bool testResult = false;
String testDescr = "Unicode Parser Keywords on/off API - global - syntax help";
TestCommonTools.consolePrintTestApiStart(135, testDescr);
mXparser.enableUnicodeBuiltinKeyWordsMode();
int n1 = mXparser.getKeyWords().Count;
mXparser.disableUnicodeBuiltinKeyWordsMode();
int n2 = mXparser.getKeyWords().Count;
if (n1 == n2 + 49)
testResult = true;
TestCommonTools.consolePrintTestApiEnd(testResult);
Assert.IsTrue(testResult);
}
[TestMethod]
public void testApi0136() {
TestCommonTools.testApiSettingsInit();
bool testResult = false;
String testDescr = "Unicode Parser Keywords on/off API - local - syntax help";
TestCommonTools.consolePrintTestApiStart(136, testDescr);
Expression e = new Expression("2pi");
e.enableUnicodeBuiltinKeyWordsMode();
int n1 = e.getKeyWords().Count;
e.disableUnicodeBuiltinKeyWordsMode();
int n2 = e.getKeyWords().Count;
if (n1 == n2 + 49)
testResult = true;
TestCommonTools.consolePrintTestApiEnd(testResult);
Assert.IsTrue(testResult);
}
public static bool testImpliedMultiplication(String expStr, String expResStr, params String[] elements) {
Expression e = new Expression(expStr);
if (elements != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* @(#)Miscellaneous.cs 5.0.0 2022-02-12
* @(#)Miscellaneous.cs 5.0.0 2022-03-20
*
* You may use this software under the condition of "Simplified BSD License"
*
Expand Down Expand Up @@ -66,7 +66,7 @@ internal static void consolePrintOptionsMxparser(String prefix) {

internal static void consolePrintOptionsExpression(Expression testExp) {
mXparser.consolePrintln("------------ OPTIONS AFTER ------------");
mXparser.consolePrintln("getImpliedMultiplicationMode = " + testExp.getImpliedMultiplicationMode());
mXparser.consolePrintln("getImpliedMultiplicationMode = " + testExp.checkIfImpliedMultiplicationMode());
mXparser.consolePrintln("getCanonicalExpressionString = " + testExp.getCanonicalExpressionString());
mXparser.consolePrintSettings();
mXparser.consolePrintln("getErrorMessage = " + testExp.getErrorMessage());
Expand Down Expand Up @@ -131,6 +131,8 @@ internal static void testExprSettingsInit() {
mXparser.setEpsilonComparison();
mXparser.setDefaultEpsilon();
mXparser.enableUlpRounding();
mXparser.enableImpliedMultiplicationMode();
mXparser.enableUnicodeBuiltinKeyWordsMode();
}
internal static void testSynSettingsInit() {
mXparser.setDefaultOptions();
Expand Down
Loading

0 comments on commit f8087fb

Please sign in to comment.