diff --git a/.gitignore b/.gitignore
index a1c2a23..6ec909e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,9 @@
# Compiled class file
*.class
+# Out folder
+.out/
+
# Log file
*.log
diff --git a/.idea/description.html b/.idea/description.html
new file mode 100644
index 0000000..db5f129
--- /dev/null
+++ b/.idea/description.html
@@ -0,0 +1 @@
+Simple Java application that includes a class with main() method
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..727c21e
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..1037313
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/project-template.xml b/.idea/project-template.xml
new file mode 100644
index 0000000..1f08b88
--- /dev/null
+++ b/.idea/project-template.xml
@@ -0,0 +1,3 @@
+
+ IJ_BASE_PACKAGE
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..c354770
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,227 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1537864338666
+
+
+ 1537864338666
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/REPL2.iml b/REPL2.iml
new file mode 100644
index 0000000..d5c0743
--- /dev/null
+++ b/REPL2.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Main.java b/src/Main.java
new file mode 100644
index 0000000..6f70f76
--- /dev/null
+++ b/src/Main.java
@@ -0,0 +1,169 @@
+import java.util.*;
+
+public class Main {
+ public static boolean isServiceString(String input){
+ return input.startsWith("/");
+ }
+
+
+ public static boolean answerToServiceCommand(String input){
+ boolean stop_iteration = false;
+ if (input.equals("/exit")) {
+ System.out.println("Bye!");
+ stop_iteration = true;
+
+ } else if (input.equals("/help")) {
+ System.out.println("The program serves as microcalculator\nType /exit to exit the program");
+
+ } else {
+ System.out.println("Unknown command");
+ }
+ return stop_iteration;
+ }
+
+ public static boolean isAssignment(String input) {
+ return input.matches(".+=.+");
+ }
+
+ public static boolean isValidExpression(String input) {
+ return input.matches("[A-Za-z\\d\\-+\\s]+");
+ }
+
+ public static boolean isValidIdentifier(String input) {
+ boolean a = input.matches("[A-Za-z ]+");
+ if (!a) {
+ System.out.println("Invalid identifier");
+ }
+ return a;
+ }
+
+ public static boolean isValidValue(String input){
+ boolean a = input.matches("([A-Za-z]+|\\d+)");
+ if (!a) {
+ System.out.println("Invalid value");
+ }
+ return a;
+ }
+
+ public static boolean isValidAssignment(String[] list){
+ boolean a = list.length == 2;
+ if (!a) {
+ System.out.println("Invalid assignment");
+ }
+ return a;
+ }
+
+ public static boolean isKnownVariable(String value, Map variables){
+ boolean a = variables.containsKey(value);
+ if (!a) {
+ System.out.println("Unknown variable");
+ }
+ return a;
+ }
+
+ public static void tryAssignment(String input, Map variables) {
+ String[] variableAndValue = input.split(" *= *");
+ if (isValidAssignment(variableAndValue) & isValidIdentifier(variableAndValue[0]) & isValidValue(variableAndValue[1])) {
+ boolean sussess = assign(variableAndValue, variables);
+ }
+ }
+
+ public static boolean assign(String[] variableAndValue, Map variables) {
+ int value = 0;
+ String variable = variableAndValue[0].trim();
+ String valueS = variableAndValue[1].trim();
+ try {
+ value = Integer.parseInt(valueS);
+ } catch (NumberFormatException e) {
+ if (isKnownVariable(valueS, variables)) value = variables.get(valueS);
+ else return false;
+ }
+ variables.put(variable, value);
+ return true;
+ }
+
+ public static void calculateAndPrintExpression(String input, Map variables){
+ String[] numbersAndOperators = input.split("\\s+");
+ int ans = 0;
+ int number = 0;
+ String value;
+ int nMinuses = 0;
+ boolean nextMinus = false;
+ for (int i = 0; i < numbersAndOperators.length; i++) {
+ if (i % 2 == 0) {
+ value = numbersAndOperators[i].trim();
+
+ try {
+ number = Integer.parseInt(value);
+ ans = makeCalculation(ans, number, nextMinus);
+ } catch (NumberFormatException e) {
+
+ if (isValidIdentifier(value)) {
+ if (isKnownVariable(value, variables)) {
+ number = variables.get(value);
+ ans = makeCalculation(ans, number, nextMinus);
+
+ } else {
+ break;
+ }
+
+ } else {
+ System.out.println("Invalid expression");
+ break;
+ }
+ }
+ } else {
+
+ if (numbersAndOperators[i].matches("[+\\-]+")) {
+ nMinuses = numbersAndOperators[i].replaceAll("[^\\-]", "").length();
+ nextMinus = nMinuses % 2 == 1;
+
+ } else {
+ System.out.println("Invalid expression");
+ break;
+ }
+ }
+
+ if (i == numbersAndOperators.length - 1) {
+ System.out.println(ans);
+ }
+ }
+ }
+
+ public static int makeCalculation(int ans, int number, boolean nextMinus){
+ if (nextMinus) {
+ ans -= number;
+ } else {
+ ans += number;
+ }
+ return ans;
+ }
+
+ public static void main(String[] args) {
+ Scanner scanner = new Scanner(System.in);
+ String str;
+ Map variables = new HashMap();
+ while (true) {
+ str = scanner.nextLine().trim();
+
+ if (!str.isEmpty()) {
+
+ if (isServiceString(str)) {
+ if (answerToServiceCommand(str)) {
+ break;
+ }
+
+ } else if (isAssignment(str)) {
+ tryAssignment(str, variables);
+
+ } else if (isValidExpression(str)) {
+ calculateAndPrintExpression(str, variables);
+
+ } else { // Invalid string input
+ System.out.println("Invalid expression");
+ }
+ }
+ }
+ }
+
+}
\ No newline at end of file