├── .gitignore ├── .travis.yml ├── KParser ├── .gitignore ├── build.gradle └── src │ ├── commonMain │ └── kotlin │ │ └── io │ │ └── kaen │ │ └── dagger │ │ ├── DeprecateParser.kt │ │ ├── Exceptions.kt │ │ ├── ExpressionParser.kt │ │ ├── Operators.kt │ │ └── Stack.kt │ ├── commonTest │ └── kotlin │ │ └── io │ │ └── kaen │ │ └── dagger │ │ └── ExpressionParserTests.kt │ └── main │ └── AndroidManifest.xml ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle ├── publish.gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | classes 4 | /local.properties 5 | .idea 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | /keys.properties 11 | KParser/src/jvmMain/ 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | matrix: 2 | include: 3 | - language: android 4 | os: linux 5 | dist: trusty 6 | android: 7 | components: 8 | - build-tools-28.0.3 9 | - android-28 10 | licenses: 11 | - 'android-sdk-license-.+' -------------------------------------------------------------------------------- /KParser/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /.idea 3 | *.iml -------------------------------------------------------------------------------- /KParser/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'kotlin-multiplatform' 3 | } 4 | 5 | 6 | apply plugin: 'com.android.library' 7 | apply plugin: 'maven-publish' 8 | apply plugin: 'com.jfrog.bintray' 9 | apply from: rootProject.file('gradle/publish.gradle') 10 | 11 | kotlin { 12 | 13 | android{ 14 | publishAllLibraryVariants() 15 | } 16 | jvm() 17 | js() 18 | // For ARM, should be changed to iosArm32 or iosArm64 19 | // For Linux, should be changed to e.g. linuxX64 20 | // For MacOS, should be changed to e.g. macosX64 21 | // For Windows, should be changed to e.g. mingwX64 22 | linuxX64("linux"){ 23 | binaries{ 24 | sharedLib{ 25 | baseName = "kparser" 26 | } 27 | } 28 | } 29 | 30 | sourceSets { 31 | commonMain { 32 | dependencies { 33 | implementation kotlin('stdlib-common') 34 | } 35 | } 36 | commonTest { 37 | dependencies { 38 | implementation kotlin('test-common') 39 | implementation kotlin('test-annotations-common') 40 | } 41 | } 42 | jvmMain { 43 | dependencies { 44 | implementation kotlin('stdlib-jdk8') 45 | } 46 | } 47 | jvmTest { 48 | dependencies { 49 | implementation kotlin('test') 50 | implementation kotlin('test-junit') 51 | } 52 | } 53 | jsMain { 54 | dependencies { 55 | implementation kotlin('stdlib-js') 56 | } 57 | } 58 | jsTest { 59 | dependencies { 60 | implementation kotlin('test-js') 61 | } 62 | } 63 | linuxMain { 64 | } 65 | linuxTest { 66 | } 67 | 68 | androidMain{ 69 | dependencies { 70 | implementation kotlin('stdlib-jdk8') 71 | } 72 | } 73 | 74 | androidTest{ 75 | dependencies{ 76 | implementation kotlin("test") 77 | implementation kotlin("test-junit") 78 | } 79 | } 80 | 81 | } 82 | } 83 | 84 | android{ 85 | compileSdkVersion 28 86 | } 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /KParser/src/commonMain/kotlin/io/kaen/dagger/DeprecateParser.kt: -------------------------------------------------------------------------------- 1 | package io.kaen.dagger 2 | 3 | import kotlin.math.* 4 | 5 | class DeprecateParser { 6 | 7 | private enum class Operators(val sign: Char) { 8 | PLUS('+'), 9 | MINUS('-'), 10 | MULTIPLY('*'), 11 | DIVISION('/'), 12 | POWER('^'), 13 | EXPONENTIAL('E'); 14 | } 15 | 16 | private fun String.split(position: Int) = 17 | listOf( 18 | this.substring(0, position), 19 | this.substring(position + 1, this.length) 20 | ) 21 | 22 | private fun extractNumber(numString: String) = numString.toDoubleOrNull() 23 | 24 | private fun isValue(expression: String): Boolean { 25 | val validChars = "1234567890.-" 26 | 27 | for (i in expression.indices) { 28 | val char = expression[i] 29 | if (char !in validChars) return false 30 | if (expression.count { it == '.' } > 1) return false 31 | if (char == '-' && i != 0) return false 32 | } 33 | return true 34 | } 35 | 36 | private fun String.lastIndexOf(char: Char): Int { 37 | var bOpen = 0 38 | var bClose = 0 39 | for (i in this.indices) { 40 | val currChar = this[i] 41 | 42 | when { 43 | currChar == char && bOpen == bClose -> return this.length - i - 1 44 | currChar == '(' -> bOpen++ 45 | currChar == ')' -> bClose++ 46 | } 47 | } 48 | return -1 49 | } 50 | 51 | private fun isOperator(operator: Operators, expression: String, position: Int): Boolean { 52 | if (operator == Operators.PLUS) { 53 | if (expression[position - 1] == 'E') { 54 | if (position >= 2) { 55 | return false 56 | } 57 | } else { 58 | return true 59 | } 60 | } else if (operator == Operators.MINUS) { 61 | if (position == 0) { 62 | return false 63 | } else if (expression[position - 1] == 'E' && position >= 2) { 64 | return false 65 | } else { 66 | val prevOperator = expression[position - 1] 67 | for (legalOp in Operators.values()) { 68 | if (prevOperator == legalOp.sign) 69 | return false 70 | } 71 | println("returning operator minus") 72 | return true 73 | } 74 | } 75 | return true 76 | } 77 | 78 | private fun evaluateFunction(funString: String, value: Double): Double { 79 | return when (funString) { 80 | // Trigonometric 81 | "SIN", "sin", "Sin" -> sin(value) 82 | "COS", "cos", "Cos" -> cos(value) 83 | "TAN", "tan", "Tan" -> tan(value) 84 | "ASIN", "asin" -> asin(value) 85 | "ACOS", "acos" -> acos(value) 86 | "ATAN", "atan" -> atan(value) 87 | 88 | //arithmetic 89 | "LOG10", "log10", "Log10" -> log10(value) 90 | "LN", "Ln", "ln" -> ln(value) 91 | "SQRT", "sqrt", "Sqrt" -> sqrt(value) 92 | "EXP", "exp", "Exp" -> exp(value) 93 | 94 | //hyperbolic 95 | "SINH", "sinh", "Sinh" -> sinh(value) 96 | "COSH", "cosh", "Cosh" -> cosh(value) 97 | "TANH", "tanh", "Tanh" -> tanh(value) 98 | 99 | 100 | else -> throw 101 | ArithmeticException("Function cannot be determined $funString") 102 | } 103 | } 104 | 105 | private fun roundToPrecision(value: Double, precision: Int = 3): Double { 106 | val corrector = 10.0.pow(precision).toInt() 107 | return round(value * corrector) / corrector 108 | } 109 | 110 | fun evaluateExpression(expression: String, precision: Int = 3): Double { 111 | val res = evaluate(expression) 112 | return roundToPrecision(res, precision) 113 | } 114 | 115 | private fun evaluate(expression: String): Double { 116 | for (operator in Operators.values()) { 117 | /* 118 | find the operator from right side (last) 119 | for cases : 20/10/2 120 | */ 121 | var position = expression.reversed().lastIndexOf(operator.sign) 122 | println("op ${operator.sign} pos $position") 123 | 124 | while (position > 0) { 125 | if (isOperator(operator, expression, position)) { 126 | val partialExpressions = expression.split(position) 127 | val left = partialExpressions[0] 128 | val right = partialExpressions[1] 129 | 130 | val value0 = evaluate(left) 131 | val value1 = evaluate(right) 132 | 133 | println( 134 | """ 135 | left $left 136 | right $right 137 | 138 | valueLeft $value0 139 | valueRight $value1 140 | """.trimIndent() 141 | ) 142 | 143 | val res = when (operator) { 144 | Operators.PLUS -> value0 + value1 145 | Operators.MINUS -> value0 - value1 146 | Operators.DIVISION -> { 147 | if (value1 == 0.0) 148 | throw ArithmeticException("Divide By Zero") 149 | value0 / value1 150 | } 151 | Operators.MULTIPLY -> value0 * value1 152 | Operators.POWER -> value0.pow(value1) 153 | Operators.EXPONENTIAL -> value0 * (10.0.pow(value1)) 154 | } 155 | return res 156 | } 157 | if (position > 0) { 158 | position = 159 | expression.substring(0, position).reversed().lastIndexOf(operator.sign) 160 | } 161 | } 162 | } 163 | 164 | // Checking for function in expression 165 | val position = expression.lastIndexOf('(') 166 | println("Expression $expression pos $position ${expression.lastIndex}") 167 | 168 | if (position > 0 && expression.last() == ')') { 169 | val funString = expression.substring(0, position) 170 | val value = evaluate(expression.substring(position + 1, expression.lastIndex)) 171 | val res = evaluateFunction(funString, value) 172 | return res 173 | } 174 | 175 | if (expression.startsWith('(') && expression.endsWith(')')) { 176 | return evaluate(expression.substring(1, expression.lastIndex)) 177 | } 178 | println("Expression : $expression") 179 | return when { 180 | isValue(expression) -> extractNumber(expression) ?: Double.MIN_VALUE 181 | expression == "PI" -> PI 182 | expression == "E" || expression == "e" -> E 183 | else -> throw NumberFormatException() 184 | } 185 | } 186 | } -------------------------------------------------------------------------------- /KParser/src/commonMain/kotlin/io/kaen/dagger/Exceptions.kt: -------------------------------------------------------------------------------- 1 | package io.kaen.dagger 2 | 3 | class BadSyntaxException(msg: String = "Bad Syntax") : Exception(msg) 4 | 5 | class DomainException(msg: String = "Domain Error") : Exception(msg) 6 | 7 | class ImaginaryException(msg:String = "Imaginary Number not supported"):Exception(msg) 8 | 9 | class BaseNotFoundException(msg: String = "Base Not Found"):Exception(msg) -------------------------------------------------------------------------------- /KParser/src/commonMain/kotlin/io/kaen/dagger/ExpressionParser.kt: -------------------------------------------------------------------------------- 1 | package io.kaen.dagger 2 | 3 | import kotlin.math.* 4 | 5 | class ExpressionParser { 6 | 7 | private val numStack = Stack() 8 | private val opStack = Stack() 9 | 10 | var isDegrees = false 11 | private var logEnabled = false 12 | 13 | 14 | fun enableLog(status: Boolean) { 15 | logEnabled = status 16 | } 17 | 18 | fun evaluate(expression: String, precision: Int = 3): Double { 19 | val uExpression = convertToUExpression(expression) 20 | val res = evaluateExpression(uExpression) 21 | return roundToPrecision(res, precision) 22 | } 23 | 24 | private fun convertToUExpression(expression: String): String { 25 | val sb = StringBuilder() 26 | for (i in expression.indices) { 27 | val currChar = expression[i] 28 | if (currChar.toString() == NormalOperators.MINUS.sign) { 29 | if (i == 0) { 30 | sb.append('u') 31 | } else { 32 | val prevChar = expression[i - 1] 33 | if (prevChar in "+*/^E(") { 34 | sb.append('u') 35 | } else { 36 | sb.append(currChar) 37 | } 38 | } 39 | } else { 40 | sb.append(currChar) 41 | } 42 | } 43 | return sb.toString() 44 | } 45 | 46 | private fun roundToPrecision(value: Double, precision: Int = 3): Double { 47 | val corrector = 10.0.pow(precision).toInt() 48 | var result = round(value * corrector) / corrector 49 | if (result == -0.0) { 50 | result = 0.0 51 | } 52 | return result 53 | } 54 | 55 | 56 | private fun computeNormalOperation(op: String) { 57 | try { 58 | when (op) { 59 | NormalOperators.PLUS.sign -> { 60 | val num0 = numStack.pop() 61 | val num1 = numStack.pop() 62 | numStack.push(num1 + num0) 63 | } 64 | NormalOperators.MINUS.sign -> { 65 | val num0 = numStack.pop() 66 | val num1 = numStack.pop() 67 | numStack.push(num1 - num0) 68 | } 69 | NormalOperators.MULTIPLY.sign -> { 70 | val num0 = numStack.pop() 71 | val num1 = numStack.pop() 72 | numStack.push(num1 * num0) 73 | } 74 | NormalOperators.DIVISION.sign -> { 75 | val num0 = numStack.pop() 76 | val num1 = numStack.pop() 77 | numStack.push(num1 / num0) 78 | } 79 | NormalOperators.POWER.sign -> { 80 | val num0 = numStack.pop() 81 | val num1 = numStack.pop() 82 | numStack.push(num1.pow(num0)) 83 | } 84 | NormalOperators.EXPONENTIAL.sign -> { 85 | val num0 = numStack.pop() 86 | val num1 = numStack.pop() 87 | numStack.push(num1 * (10.0.pow(num0))) 88 | } 89 | NormalOperators.UNARY.sign -> { 90 | val num0 = numStack.pop() 91 | numStack.push(-1.0 * num0) 92 | } 93 | } 94 | } catch (es: IndexOutOfBoundsException) { 95 | clearStacks() 96 | throw BadSyntaxException() 97 | } catch (ae: ArithmeticException) { 98 | // division by zero 99 | clearStacks() 100 | throw Exception("Division by zero not possible") 101 | } 102 | } 103 | 104 | private fun evaluateExpression(expression: String): Double { 105 | var i = 0; 106 | val numString = StringBuilder() 107 | while (i < expression.length) { 108 | val currChar = expression[i] 109 | if (currChar in "0123456789.") { 110 | // check for implicit multiply 111 | if (i != 0 && 112 | (expression[i - 1] == ')' || expression[i - 1] == 'e' || 113 | (i >= 2 && expression.substring(i - 2, i) == "PI")) 114 | ) { 115 | performSafePushToStack(numString, "*") 116 | } 117 | numString.append(currChar) 118 | i++ 119 | 120 | } else if (currChar.toString() isIn NormalOperators.values() || currChar == '(') { 121 | 122 | if (currChar == '(') { 123 | // check for implicit multiply 124 | if (i != 0 && expression[i - 1].toString() notIn NormalOperators.values()) { 125 | performSafePushToStack(numString, "*") 126 | } 127 | opStack.push("(") 128 | } else { 129 | performSafePushToStack(numString, currChar.toString()) 130 | } 131 | 132 | i++ 133 | } else if (currChar == ')') { 134 | computeBracket(numString) 135 | i++ 136 | } else if (currChar == '!') { 137 | performFactorial(numString) 138 | i++ 139 | } else if (currChar == '%') { 140 | performPercentage(numString) 141 | i++ 142 | } else if (i + 2 <= expression.length && expression.substring(i, i + 2) == "PI") { 143 | // check for implicit multiply 144 | if (i != 0 && expression[i - 1].toString() notIn NormalOperators.values() 145 | && expression[i - 1] != '(' 146 | ) { 147 | performSafePushToStack(numString, "*") 148 | } 149 | numStack.push(PI) 150 | i += 2 151 | } else if (expression[i] == 'e' && 152 | (i + 1 == expression.length || (i + 1) < expression.length && expression[i + 1] != 'x') 153 | ) { 154 | // check for implicit multiply 155 | if (i != 0 && expression[i - 1].toString() notIn NormalOperators.values() 156 | && expression[i - 1] != '(' 157 | ) { 158 | performSafePushToStack(numString, "*") 159 | } 160 | numStack.push(E) 161 | i++ 162 | } else { 163 | // check for implicit multiply 164 | if (i != 0 && expression[i - 1].toString() notIn NormalOperators.values() 165 | && expression[i - 1] != '(' 166 | ) { 167 | performSafePushToStack(numString, "*") 168 | } 169 | val increment = pushFunctionalOperator(expression, i) 170 | i += increment 171 | } 172 | } 173 | 174 | if (numString.isNotEmpty()) { 175 | val number = numString.toString().toDouble() 176 | numStack.push(number) 177 | numString.clear() 178 | } 179 | while (!opStack.isEmpty()) { 180 | val op = opStack.pop() 181 | if (op isIn FunctionalOperators.values()) { 182 | clearStacks() 183 | throw BadSyntaxException() 184 | } 185 | computeNormalOperation(op) 186 | } 187 | if (logEnabled) { 188 | opStack.display() 189 | numStack.display() 190 | } 191 | return try { 192 | numStack.pop() 193 | } catch (ie: IndexOutOfBoundsException) { 194 | clearStacks() 195 | throw BadSyntaxException() 196 | } 197 | } 198 | 199 | 200 | private fun pushFunctionalOperator( 201 | expression: String, 202 | index: Int 203 | ): Int { 204 | for (func in FunctionalOperators.values()) { 205 | val funLength = func.func.length 206 | if ((index + funLength < expression.length) && 207 | expression.substring(index, index + funLength) == func.func 208 | ) { 209 | if (func != FunctionalOperators.logx) { 210 | opStack.push(func.func) 211 | return funLength 212 | } else { 213 | val logRegex = Regex("log[0123456789.]+\\(") 214 | val found = logRegex.find(expression.substring(index, expression.length)) 215 | try { 216 | val logxString = found!!.value 217 | opStack.push(logxString) 218 | return logxString.length 219 | }catch (e: NullPointerException){ 220 | throw BaseNotFoundException() 221 | } 222 | } 223 | } 224 | } 225 | clearStacks() 226 | throw Exception("Unsupported Operation at ${expression.substring(index, expression.length)}") 227 | } 228 | 229 | private fun performSafePushToStack( 230 | numString: StringBuilder, 231 | currOp: String 232 | ) { 233 | if (numString.isNotEmpty()) { 234 | val number = numString.toString().toDouble() 235 | numStack.push(number) 236 | numString.clear() 237 | 238 | if (opStack.isEmpty()) { 239 | opStack.push(currOp) 240 | } else { 241 | var prevOpPrecedence = getBinaryOperatorPrecedence(opStack.peek()) 242 | val currOpPrecedence = getBinaryOperatorPrecedence(currOp) 243 | if (currOpPrecedence > prevOpPrecedence) { 244 | opStack.push(currOp) 245 | } else { 246 | while (currOpPrecedence <= prevOpPrecedence) { 247 | val op = opStack.pop() 248 | computeNormalOperation(op) 249 | if (!opStack.isEmpty()) 250 | prevOpPrecedence = getBinaryOperatorPrecedence(opStack.peek()) 251 | else 252 | break 253 | } 254 | opStack.push(currOp) 255 | } 256 | } 257 | } else if (!numStack.isEmpty() || currOp == NormalOperators.UNARY.sign) { 258 | opStack.push(currOp) 259 | } 260 | 261 | } 262 | 263 | private fun getBinaryOperatorPrecedence(currOp: String): Int { 264 | return when (currOp) { 265 | NormalOperators.PLUS.sign -> NormalOperators.PLUS.precedence 266 | NormalOperators.MINUS.sign -> NormalOperators.MINUS.precedence 267 | NormalOperators.MULTIPLY.sign -> NormalOperators.MULTIPLY.precedence 268 | NormalOperators.DIVISION.sign -> NormalOperators.DIVISION.precedence 269 | NormalOperators.POWER.sign -> NormalOperators.POWER.precedence 270 | NormalOperators.EXPONENTIAL.sign -> NormalOperators.EXPONENTIAL.precedence 271 | NormalOperators.UNARY.sign -> NormalOperators.UNARY.precedence 272 | else -> -1 273 | } 274 | } 275 | 276 | private fun computeBracket(numString: StringBuilder) { 277 | if (numString.isNotEmpty()) { 278 | val number = numString.toString().toDouble() 279 | numStack.push(number) 280 | numString.clear() 281 | } 282 | var operator = opStack.pop() 283 | while (operator != "(" && operator notIn FunctionalOperators.values()) { 284 | computeNormalOperation(operator) 285 | operator = opStack.pop() 286 | } 287 | if (operator isIn FunctionalOperators.values()) { 288 | computeFunction(operator) 289 | } 290 | } 291 | 292 | private fun computeFunction(func: String) { 293 | var num = numStack.pop() 294 | 295 | when (func) { 296 | FunctionalOperators.sin.func -> { 297 | if (isDegrees) { 298 | num = (num * PI) / 180 299 | } 300 | numStack.push(sin(num)) 301 | } 302 | FunctionalOperators.cos.func -> { 303 | if (isDegrees) { 304 | num = (num * PI) / 180 305 | } 306 | numStack.push(cos(num)) 307 | } 308 | FunctionalOperators.tan.func -> { 309 | if (isDegrees) { 310 | num = (num * PI) / 180 311 | } 312 | numStack.push(tan(num)) 313 | } 314 | FunctionalOperators.asin.func -> { 315 | if (isDegrees) { 316 | num = (num * PI) / 180 317 | } 318 | numStack.push(asin(num)) 319 | } 320 | FunctionalOperators.acos.func -> { 321 | if (isDegrees) { 322 | num = (num * PI) / 180 323 | } 324 | numStack.push(acos(num)) 325 | } 326 | FunctionalOperators.atan.func -> { 327 | if (isDegrees) { 328 | num = (num * PI) / 180 329 | } 330 | numStack.push(atan(num)) 331 | } 332 | FunctionalOperators.sinh.func -> { 333 | if (isDegrees) { 334 | num = (num * PI) / 180 335 | } 336 | numStack.push(sinh(num)) 337 | } 338 | FunctionalOperators.cosh.func -> { 339 | if (isDegrees) { 340 | num = (num * PI) / 180 341 | } 342 | numStack.push(cosh(num)) 343 | } 344 | FunctionalOperators.tanh.func -> { 345 | if (isDegrees) { 346 | num = (num * PI) / 180 347 | } 348 | numStack.push(tanh(num)) 349 | } 350 | FunctionalOperators.sqrt.func -> { 351 | if (num < 0) { 352 | clearStacks() 353 | throw ImaginaryException() 354 | } 355 | numStack.push(sqrt(num)) 356 | } 357 | FunctionalOperators.exp.func -> numStack.push(exp(num)) 358 | FunctionalOperators.ln.func -> numStack.push(ln(num)) 359 | FunctionalOperators.log2.func -> numStack.push(log2(num)) 360 | FunctionalOperators.log10.func -> numStack.push(log10(num)) 361 | else -> { 362 | if (func.contains(FunctionalOperators.logx.func)) { 363 | val base = func.substring(3, func.lastIndex).toDouble() 364 | numStack.push(log(num, base)) 365 | } 366 | } 367 | } 368 | } 369 | 370 | private fun performFactorial(numString: StringBuilder) { 371 | if (numString.isNotEmpty()) { 372 | val number = numString.toString().toDouble() 373 | numString.clear() 374 | if (number.isInt()) { 375 | val result = factorial(number) 376 | numStack.push(result) 377 | return 378 | } else { 379 | clearStacks() 380 | throw DomainException() 381 | } 382 | } else if (!numStack.isEmpty()) { 383 | val number = numStack.pop() 384 | if (number.isInt()) { 385 | var result = factorial(number.absoluteValue) 386 | if (number < 0) { 387 | result = 0 - result 388 | } 389 | numStack.push(result) 390 | return 391 | } else { 392 | clearStacks() 393 | throw DomainException() 394 | } 395 | } 396 | clearStacks() 397 | throw DomainException() 398 | } 399 | 400 | 401 | private fun performPercentage(numString: StringBuilder) { 402 | if (numString.isNotEmpty()) { 403 | val number = numString.toString().toDouble() 404 | numString.clear() 405 | val result = number / 100 406 | numStack.push(result) 407 | return 408 | 409 | } else if (!numStack.isEmpty()) { 410 | val number = numStack.pop() 411 | val result = number / 100.0 412 | numStack.push(result) 413 | return 414 | } 415 | clearStacks() 416 | throw BadSyntaxException() 417 | } 418 | 419 | private fun Double.isInt() = this == floor(this) 420 | 421 | private fun clearStacks() { 422 | numStack.clear() 423 | opStack.clear() 424 | } 425 | 426 | private fun factorial(num: Double, output: Double = 1.0): Double { 427 | return if (num == 0.0) output 428 | else factorial(num - 1, output * num) 429 | } 430 | 431 | } -------------------------------------------------------------------------------- /KParser/src/commonMain/kotlin/io/kaen/dagger/Operators.kt: -------------------------------------------------------------------------------- 1 | package io.kaen.dagger 2 | 3 | enum class NormalOperators(val sign: String, val precedence: Int) { 4 | PLUS("+", 2), 5 | MINUS("-", 2), 6 | MULTIPLY("*", 3), 7 | DIVISION("/", 4), 8 | POWER("^", 5), 9 | EXPONENTIAL("E", 5), 10 | UNARY("u", 6); 11 | } 12 | 13 | enum class FunctionalOperators(val func: String) { 14 | sin("sin("), 15 | cos("cos("), 16 | tan("tan("), 17 | asin("asin("), 18 | acos("acos("), 19 | atan("atan("), 20 | sinh("sinh("), 21 | cosh("cosh("), 22 | tanh("tanh("), 23 | log2("log2("), 24 | log10("log10("), 25 | ln("ln("), 26 | logx("log"), 27 | sqrt("sqrt("), 28 | exp("exp(") 29 | 30 | } 31 | 32 | infix fun String.isIn(operators: Array): Boolean { 33 | 34 | for (operator in operators) { 35 | if (operator is NormalOperators) { 36 | if (this == operator.sign) { 37 | return true 38 | } 39 | } else if (operator is FunctionalOperators) { 40 | if (this.contains(operator.func)) { 41 | return true 42 | } else if (this.contains(FunctionalOperators.logx.func)) { 43 | return true 44 | } 45 | } 46 | } 47 | return false 48 | } 49 | 50 | infix fun String.notIn(operators: Array): Boolean { 51 | return !(this isIn operators) 52 | } 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /KParser/src/commonMain/kotlin/io/kaen/dagger/Stack.kt: -------------------------------------------------------------------------------- 1 | package io.kaen.dagger 2 | 3 | class Stack { 4 | private val stack = arrayListOf() 5 | private var top = -1 6 | fun push(item: T) { 7 | stack.add(item) 8 | top++ 9 | } 10 | 11 | fun pop(): T = stack.removeAt(top--) 12 | 13 | fun peek(): T = stack[top] 14 | 15 | fun isEmpty() = stack.isEmpty() 16 | 17 | fun size() = top + 1 18 | 19 | fun display() = println(stack) 20 | 21 | fun clear(){ 22 | stack.clear() 23 | top = -1 24 | } 25 | } -------------------------------------------------------------------------------- /KParser/src/commonTest/kotlin/io/kaen/dagger/ExpressionParserTests.kt: -------------------------------------------------------------------------------- 1 | package io.kaen.dagger 2 | 3 | import kotlin.math.* 4 | import kotlin.test.* 5 | 6 | class ExpressionParserTests { 7 | 8 | val expressionParser = ExpressionParser() 9 | 10 | private fun roundToPrecision(value: Double, precision: Int = 3): Double { 11 | val corrector = 10.0.pow(precision).toInt() 12 | return round(value * corrector) / corrector 13 | } 14 | 15 | private fun factorial(num: Int, output: Int = 1): Int { 16 | return if (num == 0) output 17 | else factorial(num - 1, output * num) 18 | } 19 | 20 | @Test 21 | fun simpleAdd() { 22 | val result = expressionParser.evaluate("1+3") 23 | assertEquals(4.0, result) 24 | } 25 | 26 | @Test 27 | fun divide() { 28 | val result = expressionParser.evaluate("4/5") 29 | assertEquals(4 / 5.0, result) 30 | } 31 | 32 | @Test 33 | fun subtract() { 34 | val result = expressionParser.evaluate("10-9-9") 35 | assertEquals(-8.0, result) 36 | } 37 | 38 | @Test 39 | fun simpleUnaryMinus() { 40 | val result = expressionParser.evaluate("-9") 41 | assertEquals(-9.0, result) 42 | } 43 | 44 | @Test 45 | fun negativeAdd() { 46 | val result = expressionParser.evaluate("-9-9.6") 47 | assertEquals(-18.6, result) 48 | } 49 | 50 | @Test 51 | fun positiveDivisionByZero() { 52 | val result = expressionParser.evaluate("9/0") 53 | assertEquals(Double.POSITIVE_INFINITY, result) 54 | } 55 | 56 | @Test 57 | fun negativeDivisionByZero() { 58 | val result = expressionParser.evaluate("-9.0/0") 59 | assertEquals(Double.NEGATIVE_INFINITY, result) 60 | } 61 | 62 | @Test 63 | fun logXTest() { 64 | val result = expressionParser.evaluate("log12(50)") 65 | val precised = roundToPrecision(log(50.0, 12.0)) 66 | assertEquals(precised, result) 67 | } 68 | 69 | @Test 70 | fun complexLogXFactorialBracMultiply() { 71 | val result = expressionParser.evaluate("(10*log2(2))!") 72 | val precisesd = roundToPrecision(factorial((10 * log2(2.0).toInt())).toDouble()) 73 | assertEquals(precisesd, result) 74 | } 75 | 76 | @Test 77 | fun chainedDivision() { 78 | val result = expressionParser.evaluate("20/10/2") 79 | assertEquals(1.0, result) 80 | } 81 | 82 | @Test 83 | fun simpleSinh() { 84 | val result = expressionParser.evaluate("sinh(PI)") 85 | val precised = roundToPrecision(sinh(PI)) 86 | assertEquals(precised, result) 87 | } 88 | 89 | @Test 90 | fun simplePercent() { 91 | val result = expressionParser.evaluate("1-6%") 92 | assertEquals(1 - 0.06, result) 93 | } 94 | 95 | @Test 96 | fun simpleUnaryFunction() { 97 | val result = expressionParser.evaluate("-cos(PI)") 98 | assertEquals(-cos(PI), result) 99 | } 100 | 101 | @Test 102 | fun complexUnaryCase() { 103 | val result = expressionParser.evaluate("2*-(-cos(PI))") 104 | assertEquals(-2.0, result) 105 | } 106 | 107 | @Test 108 | fun evalInDegrees() { 109 | expressionParser.isDegrees = true 110 | val result = expressionParser.evaluate("sin(90)") 111 | assertEquals(1.0, result) 112 | val result2 = expressionParser.evaluate("sin(30)") 113 | assertEquals(0.5, result2) 114 | } 115 | 116 | @Test 117 | fun simpleExpTest() { 118 | expressionParser.isDegrees = true 119 | val result = expressionParser.evaluate("exp(cos(90))") 120 | assertEquals(1.0, result) 121 | } 122 | 123 | @Test 124 | fun funcInFunc() { 125 | expressionParser.isDegrees = true 126 | val result = expressionParser.evaluate("e^2+exp(cos(90))") 127 | assertEquals(8.389, result) 128 | } 129 | 130 | @Test 131 | fun ePiTest(){ 132 | val result = expressionParser.evaluate("ePI") 133 | assertEquals(8.54,result) 134 | 135 | val result2 = expressionParser.evaluate("PIe") 136 | assertEquals(8.54,result2) 137 | } 138 | 139 | @Test 140 | fun numPiETest(){ 141 | val result = expressionParser.evaluate("e8") 142 | assertEquals(21.746,result) 143 | 144 | val result2 = expressionParser.evaluate("PI8") 145 | assertEquals(25.133,result2) 146 | } 147 | } -------------------------------------------------------------------------------- /KParser/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### KParser 2 | 3 | Arithmetic Expression Parser Koltin Multi-Platform Library 4 | 5 | [![Build Status](https://travis-ci.com/KaenDagger/KParser.svg?branch=master)](https://travis-ci.com/KaenDagger/KParser) 6 | [ ![Download](https://api.bintray.com/packages/kaendagger/KParser/KParser/images/download.svg) ](https://bintray.com/kaendagger/KParser/KParser/_latestVersion) 7 | [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) 8 | 9 | ### Features 10 | 11 | - Evaluated in Degrees and Radians 12 | 13 | - Handle Multiple Operators 14 | - Minus (-) 15 | - Plus (+) 16 | - Multiply (*) 17 | - Division (/) 18 | - Power (^) 19 | - Exponential (E) 20 | - Mathematical Functions 21 | - Trigonometric (Sin, Cos, Tan, asin,acos,atan) 22 | - Hyperbolic (Sinh, Cosh, Tanh) 23 | - Log10, 24 | - ln (Natural log) 25 | - Log2() 26 | - LogX() (where X = base) 27 | - sqrt(Square root) 28 | - ! (Factorial) 29 | - % (Percentage) 30 | - Mathematical Constants 31 | - PI 32 | - e 33 | 34 | #### Sample 35 | 36 | **JVM/Android** 37 | ``` 38 | val parser = ExpressionParser() 39 | val result = parser.evaluate("sin(PI)+1+cos(PI)") 40 | println(result) 41 | 42 | // result 0.0 43 | ``` 44 | 45 | **C/C++** 46 | 47 | build the project with `./gradlew build` 48 | 49 | Navigate to `KParser/build/bin/linux/releaseShared/` 50 | 51 | Use the generated `libkparser_api.h` (header file) and `libkparser.so` (shared object file) 52 | 53 | ``` 54 | #include 55 | #include "libkparser_api.h" 56 | 57 | int main() { 58 | 59 | libkparser_ExportedSymbols* lib = libkparser_symbols(); 60 | libkparser_kref_io_thelimitbreaker_ExpressionParser kparser = libkparser_kref_io_thelimitbreaker_ExpressionParser(); 61 | 62 | double result = lib->kotlin.root.io.thelimitbreaker.ExpressionParser.evaluate(kparser,"1+sin(PI)+cos(PI)",3); 63 | std::cout< 42 | publication.pom.withXml { 43 | def root = asNode() 44 | root.appendNode('name', project.name) 45 | root.appendNode('description', 'Multi-Platform Arithmatic Parser for JVM/Android, Linux, Windows and Web') 46 | root.appendNode('url', 'https://github.com/KaenDagger/KParser') 47 | root.children().last() + pomConfig 48 | } 49 | } 50 | } 51 | 52 | bintrayUpload.doFirst { 53 | publications = project.publishing.publications 54 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RotBolt/KParser/4176451deb5aff83e3a16923e8fb625fd0f22663/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | resolutionStrategy { 3 | eachPlugin { 4 | if (requested.id.id == "kotlin-multiplatform") { 5 | useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}") 6 | } 7 | } 8 | } 9 | 10 | repositories { 11 | mavenCentral() 12 | maven { url 'https://plugins.gradle.org/m2/' } 13 | } 14 | } 15 | enableFeaturePreview('GRADLE_METADATA') 16 | include ':KParser' --------------------------------------------------------------------------------