Skip to content

Commit 8a0178d

Browse files
committed
v1.1.0 final, some UI changes and final fixes
1 parent 9f6c5bf commit 8a0178d

28 files changed

+400
-556
lines changed

src/components/LearningMode.vue

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/exampleCodes/multical.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const tW = (strings) => {
2+
return strings
3+
.map((s) => s.replace(/\s+/g, "\n"))
4+
.join("")
5+
.trim();
6+
};
7+
8+
export const multical = tW`
9+
a=10
10+
b=10
11+
12+
c=(a+b)/2 + (a+b)*2
13+
14+
दिखाए(c)
15+
16+
17+
18+
`;

src/lib/Compiler/main.js

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ export default function Compile(sourcecode, ActiveLangugae) {
128128

129129
kalaam.output = "";
130130
kalaam.LastConditionValue = [];
131+
kalaam.ExecutionStack = [];
131132

132133
kalaam.linebylineOutput = kalaam.output.split("\n");
133134
kalaam.error = [];
@@ -233,7 +234,7 @@ export default function Compile(sourcecode, ActiveLangugae) {
233234
assigned_variables.push(el.name);
234235
}
235236

236-
//We will simplify self conditions as we move forward
237+
//We will simplify this conditions as we move forward
237238
else if (!isPureEval(el.value) && !isNumber(el.value)) {
238239
if (!(el.name.includes("]") && el.name.includes("["))) {
239240
if (el.type === "Array") {
@@ -616,12 +617,48 @@ export default function Compile(sourcecode, ActiveLangugae) {
616617

617618
try {
618619
let el = element;
620+
let cal = "";
621+
let count = 0;
622+
// function findCalculation(cleaned_sourcedata, i) {
623+
let x = i;
624+
let d = 0;
625+
626+
while (isCalculation(cleaned_sourcedata[x]) || cleaned_sourcedata[x] == "+") {
627+
cal = cal + cleaned_sourcedata[x];
628+
count += 1;
629+
x++;
630+
}
619631

620-
let c_el = RemoveBrackets(el);
632+
function isMultiCalculation(c, op = "*+/-") {
633+
if (c.includes("(") && c.includes(")")) {
634+
let s = c.split("");
635+
s.forEach((el) => {
636+
if (op.includes(el)) {
637+
d = d + 1;
638+
}
639+
});
640+
641+
if (d > 1) {
642+
return true;
643+
} else {
644+
return false;
645+
}
646+
}
647+
}
648+
649+
let multiCal = isMultiCalculation(cal);
650+
651+
// console.log("x", x, i);
652+
skipParsing = count - 1;
653+
// cal = RemoveBrackets(cal);
654+
655+
//let c_el = RemoveBrackets(cal);
656+
657+
// let cal = findCalculation();
621658

622659
// to stop prevention of expressions like is"+ getting added as a calculation
623-
!c_el.includes('"') && !["/", "*", "'", '"'].includes(el.charAt(0))
624-
? PushCalculation(el, tokens, cleaned_sourcedata, i)
660+
!cal.includes('"') && !["/", "*", "'", '"'].includes(el.charAt(0))
661+
? PushCalculation(cal, tokens, cleaned_sourcedata, i, multiCal)
625662
: console.log(`impure calculation terms ${el}`);
626663
} catch (e) {
627664
console.log(e, `Error in completing calculation ${element}`);
@@ -1269,7 +1306,6 @@ export default function Compile(sourcecode, ActiveLangugae) {
12691306
_analyzeToken(cleaned_sourcedata, i, tokens);
12701307

12711308
//Code to skip improve a particular part of cleaned_sourcedata if it's being operated by two different functions.
1272-
12731309
if (skipParsing != 0) {
12741310
i = i + skipParsing;
12751311
}
@@ -1340,7 +1376,8 @@ export default function Compile(sourcecode, ActiveLangugae) {
13401376
return item !== "";
13411377
});
13421378

1343-
return { ExecutionStack, kalaam };
1379+
kalaam.ExecutionStack = ExecutionStack;
1380+
return kalaam;
13441381
} catch (e) {
13451382
console.log(e);
13461383
}

src/lib/PushTokens/main.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { RemoveQuotes, RemoveBrackets, operatorType } from "../Scripts/Helpers";
1+
import { RemoveBrackets, operatorType } from "../Scripts/Helpers";
22
import { ActiveLangugaeKeywords } from "../Compiler/constants";
33
//ANCHOR - Functions to push token with type and value into tokens array for further parsing
4-
54
function isNumber(element) {
65
return /^[0-9]*$/gm.test(element);
76
}
@@ -229,15 +228,17 @@ function PushArray(value, tokens) {
229228
}
230229
}
231230

232-
function PushCalculation(value, tokens, cleaned_sourcedata, i) {
231+
function PushCalculation(value, tokens, cleaned_sourcedata, i, multiCal) {
233232
//not allowing values like Numbers[a]
234233
//revisit this
234+
235235
if (!(!/\d+/.test(cleaned_sourcedata[i - 2]) && cleaned_sourcedata[i - 2].includes("["))) {
236236
//
237237

238238
tokens.push({
239239
type: "Calculation",
240240
value: value,
241+
multiCal,
241242
});
242243
}
243244
}

src/lib/Scripts/Helpers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ function earlyCleaning(c) {
1515
return c;
1616
}
1717
function RemoveBrackets(e) {
18-
let a = e.replace("(", "");
19-
let b = a.replace(")", "");
18+
let a = e.replace(/\(/g, "");
19+
let b = a.replace(/\)/g, "");
2020
let c = b.replace("}", "");
2121
let d = c.replace("{", "");
2222

src/lib/Scripts/main.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ function GetcleanedExpression(expression) {
168168

169169
//To convert 'a+b-c*d' into ['a','+','-','c','*','d']
170170

171-
function SplitElementsArray(element) {
172-
element = RemoveBrackets(element);
171+
function SplitElementsArray(element, multiCal) {
172+
element = multiCal ? element : RemoveBrackets(element);
173173

174174
if (IsConditionalOperator(element)) {
175175
element = element.replace(/' '/g, "");
@@ -400,19 +400,25 @@ function AcceptInputandSetValue(tokens, index, updated_tokens, ExecutionStack, L
400400

401401
//If you are not getting the values right, this is where you should start debugging
402402

403-
function CalculateValues(calculation, j, updated_tokens) {
403+
function CalculateValues(calculation, j, updated_tokens, multiCal) {
404404
var result;
405405
try {
406-
var calculationArray = SplitElementsArray(calculation);
406+
var calculationArray = SplitElementsArray(calculation, multiCal);
407407

408408
var StringVar = SetValues(calculationArray, updated_tokens);
409409

410410
let joinStringVar = StringVar.join("");
411411

412412
let NewStringVar = "";
413-
if (isNumber(joinStringVar.charAt(0)) == true) {
413+
//evaluate the exepression as it is when multical is true
414+
//for expressions like c=(ageone+agetwo)/2 + (ageone+agetwo)*2
415+
416+
if (isNumber(joinStringVar.charAt(0)) || multiCal) {
414417
NewStringVar = eval(joinStringVar);
415-
} else if (isNumber(joinStringVar.charAt(0)) == undefined) {
418+
}
419+
420+
//Not realted to numbers at all but strings
421+
else if (!isNumber(joinStringVar.charAt(0))) {
416422
StringVar.forEach((el) => {
417423
if (el != "+") {
418424
el = el.toString();
@@ -1072,8 +1078,8 @@ function AssignorUpdateValues(
10721078
//type 2- X= ageone+agetwo
10731079
else {
10741080
//performing the calculation
1075-
1076-
let value = CalculateValues(varvalue, i, updated_tokens);
1081+
let multiCal = sourcedata[i + 1].multiCal;
1082+
let value = CalculateValues(varvalue, i, updated_tokens, multiCal);
10771083

10781084
updated_tokens.push({
10791085
name: variable,

0 commit comments

Comments
 (0)