├── .github
└── FUNDING.yml
├── MandettaCompiler
├── .gitignore
├── .idea
│ ├── .gitignore
│ ├── codeStyles
│ │ ├── Project.xml
│ │ └── codeStyleConfig.xml
│ ├── compiler.xml
│ ├── kotlinc.xml
│ ├── libraries
│ │ ├── KotlinJavaRuntime.xml
│ │ ├── Maven__org_jetbrains_annotations_13_0.xml
│ │ ├── Maven__org_jetbrains_kotlin_kotlin_stdlib_1_3_71.xml
│ │ ├── Maven__org_jetbrains_kotlin_kotlin_stdlib_common_1_3_71.xml
│ │ ├── Maven__org_jetbrains_kotlin_kotlin_stdlib_jdk7_1_3_71.xml
│ │ ├── Maven__org_jetbrains_kotlin_kotlin_stdlib_jdk8_1_3_71.xml
│ │ ├── Maven__org_jetbrains_kotlin_kotlin_test_1_3_71.xml
│ │ └── Maven__org_jetbrains_kotlin_kotlin_test_common_1_3_71.xml
│ ├── misc.xml
│ ├── modules.xml
│ └── vcs.xml
├── pom.xml
└── src
│ ├── main
│ └── kotlin
│ │ └── com
│ │ └── vitorblog
│ │ └── compiler
│ │ ├── Main.kt
│ │ ├── dao
│ │ ├── FunctionDao.kt
│ │ └── VariableDao.kt
│ │ ├── function
│ │ ├── InputFunction.kt
│ │ ├── OpenSocketFunction.kt
│ │ ├── PrintFunction.kt
│ │ ├── PrintlnFunction.kt
│ │ ├── RandomFunction.kt
│ │ └── SendSocketMessageFunction.kt
│ │ ├── model
│ │ ├── Function.kt
│ │ ├── MandettaClass.kt
│ │ ├── MandettaHandler.kt
│ │ ├── Status.kt
│ │ ├── TerminalHandler.kt
│ │ ├── Variable.kt
│ │ └── exception
│ │ │ ├── FunctionNotFoundException.kt
│ │ │ ├── InvalidArgsException.kt
│ │ │ ├── InvalidIFException.kt
│ │ │ ├── InvalidVarNameException.kt
│ │ │ └── VarNameParseException.kt
│ │ ├── parser
│ │ └── ValueParser.kt
│ │ ├── process
│ │ ├── CodeProcess.kt
│ │ ├── FunctionProcess.kt
│ │ ├── IFProcess.kt
│ │ └── VariableProcess.kt
│ │ └── util
│ │ └── StringUtils.kt
│ └── test
│ └── kotlin
│ └── TestMain.kt
├── MandettaWebsite
├── .gitignore
└── MandettaWebsite.iml
├── README.md
└── test.sus
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | custom: ['https://hypehost.com.br/', 'https://www.buymeacoffee.com/vit.orpaulo']
13 |
--------------------------------------------------------------------------------
/MandettaCompiler/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | target
3 | MandettaCompiler.iml
--------------------------------------------------------------------------------
/MandettaCompiler/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /workspace.xml
--------------------------------------------------------------------------------
/MandettaCompiler/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/MandettaCompiler/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/MandettaCompiler/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/MandettaCompiler/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/MandettaCompiler/.idea/libraries/KotlinJavaRuntime.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/MandettaCompiler/.idea/libraries/Maven__org_jetbrains_annotations_13_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/MandettaCompiler/.idea/libraries/Maven__org_jetbrains_kotlin_kotlin_stdlib_1_3_71.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/MandettaCompiler/.idea/libraries/Maven__org_jetbrains_kotlin_kotlin_stdlib_common_1_3_71.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/MandettaCompiler/.idea/libraries/Maven__org_jetbrains_kotlin_kotlin_stdlib_jdk7_1_3_71.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/MandettaCompiler/.idea/libraries/Maven__org_jetbrains_kotlin_kotlin_stdlib_jdk8_1_3_71.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/MandettaCompiler/.idea/libraries/Maven__org_jetbrains_kotlin_kotlin_test_1_3_71.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/MandettaCompiler/.idea/libraries/Maven__org_jetbrains_kotlin_kotlin_test_common_1_3_71.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/MandettaCompiler/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/MandettaCompiler/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/MandettaCompiler/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/MandettaCompiler/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.vitorblog
8 | MandettaCompiler
9 | 0.2
10 |
11 |
12 | 1.3.71
13 |
14 |
15 |
16 |
17 | jitpack.io
18 | https://jitpack.io
19 |
20 |
21 |
22 |
23 |
24 | org.jetbrains.kotlin
25 | kotlin-stdlib-jdk8
26 | ${kotlin.version}
27 |
28 |
29 | org.jetbrains.kotlin
30 | kotlin-test
31 | ${kotlin.version}
32 | test
33 |
34 |
35 | org.reflections
36 | reflections
37 | 0.9.11
38 |
39 |
40 |
41 |
42 | src/main/kotlin
43 | src/test/kotlin
44 |
45 |
46 | org.jetbrains.kotlin
47 | kotlin-maven-plugin
48 | ${kotlin.version}
49 |
50 |
51 | compile
52 | compile
53 |
54 | compile
55 |
56 |
57 |
58 | test-compile
59 | test-compile
60 |
61 | test-compile
62 |
63 |
64 |
65 |
66 | 1.8
67 |
68 |
69 |
70 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/Main.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler
2 |
3 | import com.andreapivetta.kolor.lightBlue
4 | import com.vitorblog.compiler.model.MandettaClass
5 | import com.vitorblog.compiler.process.FunctionProcess
6 | import java.io.File
7 | import java.time.Duration
8 | import java.time.Instant
9 |
10 | object Main {
11 |
12 | @JvmStatic
13 | fun main(args: Array) {
14 | if (args.isEmpty()) {
15 | println("No file selected.")
16 | return
17 | }
18 |
19 | FunctionProcess.load()
20 | val mandettaClass = MandettaClass(File(args.first()))
21 |
22 | println("\nExecuted in: ${mandettaClass.elapsedTime}ms".lightBlue())
23 | }
24 |
25 | }
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/dao/FunctionDao.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.dao
2 |
3 | import com.vitorblog.compiler.model.Function
4 |
5 | object FunctionDao {
6 |
7 | val FUNCTIONS = hashMapOf()
8 |
9 | fun add(function: Function) = FUNCTIONS.put(function.name, function)
10 |
11 | operator fun get(name: String) = FUNCTIONS[name]
12 |
13 | fun contains(name: String) = FUNCTIONS.containsKey(name)
14 |
15 | }
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/dao/VariableDao.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.dao
2 |
3 | import com.vitorblog.compiler.model.Variable
4 |
5 | object VariableDao {
6 |
7 | val VARIABLES = hashMapOf()
8 |
9 | fun add(variable: Variable) = VARIABLES.put(variable.name, variable)
10 |
11 | operator fun get(name:String) = VARIABLES[name]
12 |
13 | fun contains(name:String) = VARIABLES.containsKey(name)
14 |
15 | }
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/function/InputFunction.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.function
2 |
3 | import com.vitorblog.compiler.dao.VariableDao
4 | import com.vitorblog.compiler.model.Function
5 | import com.vitorblog.compiler.model.MandettaClass
6 | import com.vitorblog.compiler.model.Variable
7 | import java.util.function.Consumer
8 |
9 | class InputFunction : Function {
10 |
11 | override val name = "input"
12 | override val args = 1
13 |
14 | override
15 | fun execute(arguments: List) {
16 |
17 | val arg = arguments[0]
18 | val variable = if (VariableDao.contains(arg)) {
19 | VariableDao[arg]!!
20 | } else {
21 | Variable("var $arg = \"\"")
22 | }
23 |
24 | MandettaClass.instance.mandettaHandler.consoleInput(Consumer { variable.value = it })
25 |
26 | VariableDao.add(variable)
27 |
28 | }
29 |
30 | }
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/function/OpenSocketFunction.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.function
2 |
3 | import com.vitorblog.compiler.dao.VariableDao
4 | import com.vitorblog.compiler.model.Function
5 | import com.vitorblog.compiler.model.Variable
6 | import java.net.Inet4Address
7 | import java.net.Socket
8 | import java.net.SocketAddress
9 | import kotlin.random.Random
10 |
11 | class OpenSocketFunction : Function {
12 |
13 | override val name = "openSocket"
14 | override val args = 2
15 |
16 | override
17 | fun execute(arguments: List) {
18 |
19 | val varName = arguments[0]
20 | val ip = arguments[1]
21 | val port = arguments[2].toInt()
22 |
23 | val variable = if (VariableDao.contains(varName)) {
24 | VariableDao[varName]!!
25 | } else {
26 | Variable("var $varName = \"\"")
27 | }
28 |
29 | variable.value = Socket(ip.replace("\"", ""), port)
30 |
31 | VariableDao.add(variable)
32 |
33 | }
34 |
35 | }
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/function/PrintFunction.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.function
2 |
3 | import com.vitorblog.compiler.dao.VariableDao
4 | import com.vitorblog.compiler.model.Function
5 | import com.vitorblog.compiler.model.MandettaClass
6 | import com.vitorblog.compiler.parser.ValueParser
7 | import com.vitorblog.compiler.util.StringUtils
8 |
9 | class PrintFunction : Function {
10 |
11 | override val name = "print"
12 | override val args = 1
13 |
14 | override
15 | fun execute(arguments: List) {
16 |
17 | val arg = arguments[0]
18 | val text = ValueParser.getRealValue(arg)
19 |
20 | MandettaClass.instance.mandettaHandler.consoleOutput(text.toString())
21 |
22 | }
23 |
24 | }
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/function/PrintlnFunction.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.function
2 |
3 | import com.vitorblog.compiler.dao.VariableDao
4 | import com.vitorblog.compiler.model.Function
5 | import com.vitorblog.compiler.model.MandettaClass
6 | import com.vitorblog.compiler.parser.ValueParser
7 | import com.vitorblog.compiler.util.StringUtils
8 |
9 | class PrintlnFunction : Function {
10 |
11 | override val name = "println"
12 | override val args = 1
13 |
14 | override
15 | fun execute(arguments: List) {
16 |
17 | val arg = arguments[0]
18 | val text = ValueParser.getRealValue(arg)
19 |
20 | MandettaClass.instance.mandettaHandler.consoleOutput("$text\n")
21 |
22 | }
23 |
24 | }
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/function/RandomFunction.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.function
2 |
3 | import com.vitorblog.compiler.dao.VariableDao
4 | import com.vitorblog.compiler.model.Function
5 | import com.vitorblog.compiler.model.Variable
6 | import kotlin.random.Random
7 |
8 | class RandomFunction : Function {
9 |
10 | override val name = "random"
11 | override val args = 1
12 |
13 | override
14 | fun execute(arguments: List) {
15 |
16 | val arg = arguments[0]
17 | val max = if (arguments.size > 1) {
18 | arguments[1]
19 | } else {
20 | null
21 | }
22 | val variable = if (VariableDao.contains(arg)) {
23 | VariableDao[arg]!!
24 | } else {
25 | Variable("var $arg = \"\"")
26 | }
27 |
28 | variable.value = if (max != null) {
29 | Random.nextInt(max.toInt())
30 | } else {
31 | Random.nextInt()
32 | }
33 |
34 | VariableDao.add(variable)
35 |
36 | }
37 |
38 | }
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/function/SendSocketMessageFunction.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.function
2 |
3 | import com.vitorblog.compiler.dao.VariableDao
4 | import com.vitorblog.compiler.model.Function
5 | import com.vitorblog.compiler.model.Variable
6 | import java.net.Socket
7 | import kotlin.random.Random
8 |
9 | class SendSocketMessageFunction : Function {
10 |
11 | override val name = "sendSocketMessage"
12 | override val args = 2
13 |
14 | override
15 | fun execute(arguments: List) {
16 |
17 | val varName = arguments[0]
18 | val message = arguments[1]
19 |
20 | val variable = VariableDao[varName]!!
21 |
22 | val outputStream = (variable.value as Socket).getOutputStream()
23 | outputStream.write(message.replace("\"", "").toByteArray())
24 | outputStream.flush()
25 |
26 | }
27 |
28 | }
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/model/Function.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.model
2 |
3 | interface Function {
4 |
5 | val name: String
6 | val args: Int
7 |
8 | fun execute(arguments: List)
9 |
10 | }
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/model/MandettaClass.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.model
2 |
3 | import com.vitorblog.compiler.process.CodeProcess
4 | import java.io.File
5 | import java.time.Duration
6 | import java.time.Instant
7 | import java.util.function.Consumer
8 |
9 | class MandettaClass(file: File, val mandettaHandler: MandettaHandler = TerminalHandler()) {
10 |
11 | companion object {
12 | lateinit var instance: MandettaClass
13 | }
14 |
15 | val name = file.nameWithoutExtension
16 | var elapsedTime = 0
17 |
18 | val code = file.readText()
19 | val lines = file.readLines()
20 |
21 | var input: Consumer? = null
22 |
23 | init {
24 | instance = this
25 |
26 | val start = Instant.now()
27 | CodeProcess.load(lines)
28 | val finish = Instant.now()
29 |
30 | elapsedTime = (Duration.between(start, finish).toMillis()/1000.0).toInt()
31 | }
32 |
33 | }
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/model/MandettaHandler.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.model
2 |
3 | import java.util.function.Consumer
4 |
5 | interface MandettaHandler {
6 |
7 | fun consoleOutput(string: String)
8 |
9 | fun consoleInput(consumer: Consumer)
10 |
11 | }
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/model/Status.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.model
2 |
3 | enum class Status {
4 |
5 | NOTHING,
6 | IN_IF,
7 | IN_ELSE,
8 | IN_IF_TRUE,
9 | IN_ELSE_TRUE,
10 | IN_FOR,
11 | IN_REPEAT;
12 |
13 | }
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/model/TerminalHandler.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.model
2 |
3 | import java.util.function.Consumer
4 |
5 | class TerminalHandler : MandettaHandler {
6 |
7 | override
8 | fun consoleOutput(string: String) {
9 | print(string)
10 | }
11 |
12 | override
13 | fun consoleInput(consumer: Consumer) {
14 | MandettaClass.instance.input = consumer
15 | consumer.accept(readLine()!!)
16 | }
17 |
18 | }
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/model/Variable.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.model
2 |
3 | import com.vitorblog.compiler.model.exception.InvalidVarNameException
4 | import com.vitorblog.compiler.model.exception.VarNameParseException
5 | import com.vitorblog.compiler.parser.ValueParser
6 | import com.vitorblog.compiler.util.StringUtils
7 | import java.util.regex.Pattern
8 |
9 | class Variable(string: String) {
10 |
11 | var name: String
12 | var value: Any? = null
13 |
14 | init {
15 | var pattern = Pattern.compile(" (.*?) ")
16 | var matcher = pattern.matcher(string)
17 |
18 | if (matcher.find()) {
19 | name = matcher.group(0).replace(" ", "")
20 |
21 | if (StringUtils.isInvalid(name)) {
22 | throw InvalidVarNameException()
23 | }
24 | } else {
25 | throw VarNameParseException()
26 | }
27 |
28 | pattern = Pattern.compile("([^=]+)")
29 | matcher = pattern.matcher(string)
30 |
31 | value = if (matcher.find()) {
32 | val unparsedValue = string.replace("${matcher.group(1)}= ", "")
33 | ValueParser.parseValue(unparsedValue)
34 | } else {
35 | null
36 | }
37 | }
38 |
39 | }
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/model/exception/FunctionNotFoundException.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.model.exception
2 |
3 | class FunctionNotFoundException(name: String) : Exception("The function '$name' does not exist.")
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/model/exception/InvalidArgsException.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.model.exception
2 |
3 | class InvalidArgsException(name: String, args:Int) : Exception("The function '$name' need $args arguments to work.")
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/model/exception/InvalidIFException.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.model.exception
2 |
3 | class InvalidIFException(text:String) : Exception("Invalid $text in if statement")
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/model/exception/InvalidVarNameException.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.model.exception
2 |
3 | class InvalidVarNameException : Exception("The name passed is invalid.")
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/model/exception/VarNameParseException.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.model.exception
2 |
3 | import java.lang.Exception
4 |
5 | class VarNameParseException : Exception("Can't parse name of var.")
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/parser/ValueParser.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.parser
2 |
3 | import com.vitorblog.compiler.dao.VariableDao
4 | import com.vitorblog.compiler.util.StringUtils
5 | import jdk.nashorn.tools.ShellFunctions.input
6 | import java.util.*
7 | import java.util.regex.Matcher
8 | import java.util.regex.Pattern
9 | import kotlin.collections.ArrayList
10 |
11 |
12 | object ValueParser {
13 |
14 | fun parseValue(string: String): Any? {
15 | when {
16 | StringUtils.isString(string) -> {
17 | val pattern = Pattern.compile("\\{(.*?)\\}")
18 | val matcher = pattern.matcher(string)
19 | val matches = matcher.allMatches()
20 |
21 | if (matches.isNotEmpty()) {
22 |
23 | var newString = string
24 | for (match in matches) {
25 |
26 | newString = newString.replace(
27 | match,
28 | VariableDao[match.substring(1, match.length - 1)]!!.value.toString()
29 | )
30 |
31 | }
32 |
33 | return newString.substring(1, newString.length - 1)
34 |
35 | }
36 |
37 | return string.substring(1, string.length - 1)
38 | }
39 | StringUtils.isBoolean(string) -> {
40 | return string == "true"
41 | }
42 | string == "null" -> {
43 | return null
44 | }
45 | else -> {
46 | return try {
47 | string.toInt()
48 | } catch (exception: Exception) {
49 | null
50 | }
51 | }
52 | }
53 | }
54 |
55 | fun getRealValue(string: String):Any? {
56 |
57 | return if (VariableDao.contains(string)) {
58 | VariableDao[string]!!.value
59 | } else {
60 | parseValue(string)
61 | }
62 |
63 | }
64 |
65 | private
66 | fun Matcher.allMatches(): ArrayList {
67 | val arrayList = arrayListOf()
68 |
69 | while (this.find()) {
70 | arrayList.add(this.group())
71 | }
72 |
73 | return arrayList
74 | }
75 |
76 | }
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/process/CodeProcess.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.process
2 |
3 | import com.andreapivetta.kolor.red
4 | import com.vitorblog.compiler.model.MandettaClass
5 | import com.vitorblog.compiler.model.Status
6 |
7 | object CodeProcess {
8 | var actualLine = 0
9 | var status = Status.NOTHING
10 |
11 | fun load(lines: List) {
12 | for (obj in lines.withIndex()) {
13 | val line = obj.value
14 | actualLine = obj.index
15 |
16 | try {
17 |
18 | when {
19 |
20 | line.startsWith("//") -> {}
21 | (status == Status.IN_IF || status == Status.IN_ELSE)
22 | && (!line.startsWith("else") && !line.startsWith("end")) -> {}
23 |
24 | line.startsWith("var") -> {
25 |
26 | VariableProcess.load(line.replace(" ", ""))
27 |
28 | }
29 |
30 | line.startsWith("if") -> {
31 |
32 | IFProcess.loadIF(line)
33 |
34 | }
35 |
36 | line.startsWith("else") -> {
37 |
38 | IFProcess.loadElse()
39 |
40 | }
41 |
42 | line.startsWith("end") -> {
43 |
44 | status = Status.NOTHING
45 |
46 | }
47 |
48 | line.contains("(") && line.contains(")") -> {
49 |
50 | FunctionProcess.load(line.replace(" ", ""))
51 |
52 | }
53 |
54 | }
55 |
56 | } catch (exception: Exception) {
57 | MandettaClass.instance.print("Exception found at line ${actualLine + 1}: ${exception.message}\n".red())
58 | exception.printStackTrace()
59 | }
60 |
61 | }
62 | }
63 |
64 | }
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/process/FunctionProcess.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.process
2 |
3 | import com.vitorblog.compiler.dao.FunctionDao
4 | import com.vitorblog.compiler.model.Function
5 | import com.vitorblog.compiler.model.exception.FunctionNotFoundException
6 | import com.vitorblog.compiler.model.exception.InvalidArgsException
7 | import org.reflections.Reflections
8 | import org.reflections.scanners.SubTypesScanner
9 | import java.util.regex.Pattern
10 |
11 | object FunctionProcess {
12 |
13 | fun load() {
14 | val reflections = Reflections("com.vitorblog", SubTypesScanner())
15 |
16 | val functions = reflections.getSubTypesOf(Function::class.java)
17 | functions.forEach {
18 | FunctionDao.add(it.newInstance())
19 | }
20 | }
21 |
22 | fun load(line: String) {
23 | val pattern = Pattern.compile("\\((.*?)\\)")
24 | val matcher = pattern.matcher(line)
25 |
26 | if (!matcher.find()) {
27 | return
28 | }
29 |
30 | val name = line.replace(matcher.group(0), "")
31 | val arguments = matcher.group(0)
32 | .replace("(", "")
33 | .replace(")", "")
34 | .split(", ")
35 |
36 | val function = FunctionDao[name] ?: throw FunctionNotFoundException(name)
37 |
38 | if (arguments.size < function.args) {
39 | throw InvalidArgsException(name, function.args)
40 | }
41 |
42 | function.execute(arguments)
43 | }
44 |
45 | }
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/process/IFProcess.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.process
2 |
3 | import com.vitorblog.compiler.dao.VariableDao
4 | import com.vitorblog.compiler.model.Status
5 | import com.vitorblog.compiler.model.exception.InvalidIFException
6 | import com.vitorblog.compiler.parser.ValueParser
7 | import com.vitorblog.compiler.util.StringUtils
8 | import java.util.regex.Pattern
9 |
10 | object IFProcess {
11 |
12 | fun loadIF(line:String) {
13 |
14 | val pattern = Pattern.compile("\\((.*?)\\)")
15 | val matcher = pattern.matcher(line)
16 |
17 | if (!matcher.find()) {
18 | throw InvalidIFException("args")
19 | }
20 |
21 | val arguments = matcher.group(0)
22 | .removePrefix("(")
23 | .removeSuffix(")")
24 | val split = arguments.split(" ")
25 |
26 | val comparisonType = ComparisonType.byValue(split[1]) ?: throw InvalidIFException("comparison type")
27 | CodeProcess.status = if (makeComparison(split, comparisonType)) {
28 | Status.IN_IF_TRUE
29 | } else {
30 | Status.IN_IF
31 | }
32 |
33 | }
34 |
35 | fun loadElse() {
36 |
37 | CodeProcess.status = if (CodeProcess.status == Status.IN_IF) {
38 | Status.IN_ELSE_TRUE
39 | } else {
40 | Status.IN_ELSE
41 | }
42 |
43 | }
44 |
45 | private fun makeComparison(split:List, comparisonType: ComparisonType):Boolean {
46 | val firstValue = ValueParser.getRealValue(split[0])
47 | val secondValue = ValueParser.getRealValue(split[2])
48 |
49 | return when {
50 |
51 | comparisonType == ComparisonType.EQUALS
52 | && firstValue == secondValue -> {
53 |
54 | true
55 |
56 | }
57 |
58 | comparisonType == ComparisonType.BIGGER
59 | && firstValue.toString().toInt() > secondValue.toString().toInt() -> {
60 |
61 | true
62 |
63 | }
64 |
65 | comparisonType == ComparisonType.MINOR
66 | && firstValue.toString().toInt() < secondValue.toString().toInt() -> {
67 |
68 | true
69 |
70 | }
71 |
72 | comparisonType == ComparisonType.BIGGER_OR_EQUALS
73 | && firstValue.toString().toInt() >= secondValue.toString().toInt() -> {
74 |
75 | true
76 |
77 | }
78 |
79 | comparisonType == ComparisonType.MINOR_OR_EQUALS
80 | && firstValue.toString().toInt() <= secondValue.toString().toInt() -> {
81 |
82 | true
83 |
84 | }
85 |
86 | else -> false
87 |
88 | }
89 |
90 | }
91 |
92 | enum class ComparisonType(val value: String) {
93 |
94 | EQUALS("=="),
95 | NOT_EQUALS("!="),
96 | BIGGER(">"),
97 | MINOR("<"),
98 | BIGGER_OR_EQUALS(">="),
99 | MINOR_OR_EQUALS("<=");
100 |
101 | companion object {
102 |
103 | fun byValue(value: String):ComparisonType? {
104 | return values().firstOrNull { it.value == value }
105 | }
106 |
107 | }
108 |
109 | }
110 |
111 | }
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/process/VariableProcess.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.process
2 |
3 | import com.vitorblog.compiler.dao.VariableDao
4 | import com.vitorblog.compiler.model.Variable
5 |
6 | object VariableProcess {
7 |
8 | fun load(line: String) {
9 | VariableDao.add(Variable(line))
10 | }
11 |
12 | }
--------------------------------------------------------------------------------
/MandettaCompiler/src/main/kotlin/com/vitorblog/compiler/util/StringUtils.kt:
--------------------------------------------------------------------------------
1 | package com.vitorblog.compiler.util
2 |
3 | object StringUtils {
4 |
5 | private val invalidCharacters = " -=+§)(*&¨%$#@!/?€\\|°/~^][{}ºª`´.,<>©'\"".toCharArray()
6 |
7 | fun isInvalid(string: String): Boolean {
8 | var result = string.isEmpty()
9 |
10 | string.toCharArray().forEach {
11 | if (result) {
12 | return !result
13 | }
14 |
15 | result = invalidCharacters.contains(it)
16 | }
17 |
18 | return result
19 | }
20 |
21 | fun isString(string: String): Boolean {
22 | if (string.length < 2) {
23 | return false
24 | }
25 | return string.first().toString() == "\"" && string.last().toString() == "\""
26 | }
27 |
28 | fun isBoolean(string: String): Boolean {
29 | return string == "false" || string == "true"
30 | }
31 |
32 | fun isInt(string: String): Boolean {
33 | return string.toIntOrNull() == null
34 | }
35 |
36 | }
--------------------------------------------------------------------------------
/MandettaCompiler/src/test/kotlin/TestMain.kt:
--------------------------------------------------------------------------------
1 | import com.vitorblog.compiler.model.Variable
2 | import com.vitorblog.compiler.util.StringUtils
3 |
4 | object TestMain {
5 |
6 | @JvmStatic
7 | fun main(args: Array) {
8 | var variable = Variable("var iam = \"hell\"")
9 | println(variable.name)
10 | println(variable.value)
11 | println(StringUtils.isString("\""))
12 |
13 | println("--------------------------------------")
14 |
15 | variable = Variable("var none = 5")
16 | println(variable.name)
17 | println(variable.value)
18 | println(StringUtils.isString(variable.value.toString()))
19 | }
20 |
21 | }
--------------------------------------------------------------------------------
/MandettaWebsite/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | target
3 | MandettaPlugin.iml
--------------------------------------------------------------------------------
/MandettaWebsite/MandettaWebsite.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Moved to [PauloScriptOrg](https://github.com/PauloScriptOrg)
2 |
--------------------------------------------------------------------------------
/test.sus:
--------------------------------------------------------------------------------
1 | // Send the question
2 | println("What is your name?")
3 |
4 | // Open the input
5 | input(name)
6 |
7 | // Show the name
8 | print("Hello {name}")
--------------------------------------------------------------------------------