Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace BasicBasic
- {
- class Program
- {
- static List<string> text = new List<string>();
- static string[] lines;
- static Dictionary<char, int> nums = new Dictionary<char, int>();
- //static long x = 0;
- //static long v = 0;
- //static long w = 0;
- //static long y = 0;
- //static long z = 0;
- static int i = 0;
- static int j = 0;
- string command = "";
- static char curchar;
- static char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
- static char[] digit = { '-','0','1','2','3','4','5','6','7','8','9'};
- static StringBuilder num = new StringBuilder();
- static void Main(string[] args)
- {
- ReadInput();
- DoCode();
- }
- static void DoCode()
- {
- for (i = 0; i < lines.Length; i++)
- {
- for (j = 0; j < lines[i].Length; j++)
- {
- curchar = lines[i][j];
- if (CheckForCommand())
- {
- break;
- }
- }
- }
- }
- static bool CheckForCommand()
- {
- if (nums.ContainsKey(curchar))
- {
- CheckForEqualCommand();
- return true;
- }
- if (curchar == 'I')
- {
- if (IfCommand())
- {
- THENCommand();
- }
- return true;
- }
- if (curchar == 'P')
- {
- PrintCommand();
- return true;
- }
- if (curchar == 'S')
- {
- StopCommand();
- return true;
- }
- if (curchar == 'C')
- {
- CLSCommand();
- return true;
- }
- if (curchar == 'G')
- {
- GoToCommand();
- return true;
- }
- return false;
- }
- static void GoToCommand()
- {
- for (int g = j; g < lines[i].Length; g++)
- {
- if (lines[i][g] == 'G' || lines[i][g] == 'O' || lines[i][g] == 'T' || lines[i][g] == 'O')
- {
- continue;
- }
- num.Clear();
- while(digits.Contains(lines[i][g]))
- {
- num.Append(lines[i][g]);
- g++;
- if (g >= lines[i].Length)
- {
- g--;
- break;
- }
- }
- for (int k = 0; k < lines.Length; k++)
- {
- bool isTrue = true;
- int d;
- for ( d = 0; d < num.Length; d++)
- {
- if (lines[k][d] == num[d])
- {
- }
- else
- {
- isTrue = false;
- break;
- }
- }
- if (isTrue && !digits.Contains(lines[k][d+1]))
- {
- i = k - 1;
- return;
- }
- }
- }
- }
- static void THENCommand()
- {
- for (j = j; j < lines[i].Length; j++)
- {
- curchar = lines[i][j];
- if (curchar == 'T' || curchar == 'H' || curchar == 'E' || curchar == 'N')
- {
- continue;
- }
- CheckForCommand();
- }
- }
- static void CLSCommand()
- {
- Console.Clear();
- }
- static void StopCommand()
- {
- Environment.Exit(0);
- }
- static void PrintCommand()
- {
- while (lines[i][j] != 'T')
- {
- j++;
- }
- j++;
- Console.WriteLine(nums[lines[i][j]]);
- }
- static bool IfCommand()
- {
- bool isTrue = false;
- for ( j = j ; j < lines[i].Length; j++)
- {
- char currentChar = lines[i][j];
- num.Clear();
- if (currentChar == 'T' && lines[i][j + 1] == 'H')
- {
- break;
- }
- if (currentChar == 'F')
- {
- continue;
- }
- if (lines[i][j + 1] == '=')
- {
- if (nums.ContainsKey(currentChar))
- {
- if (nums.ContainsKey(lines[i][j + 2]))
- {
- if (nums[currentChar] == nums[lines[i][j + 2]])
- {
- isTrue = true;
- }
- }
- else
- {
- while (digit.Contains(lines[i][j+2]))
- {
- num.Append(lines[i][j + 2]);
- j++;
- if (j + 2 >= lines[i].Length)
- {
- break;
- }
- }
- if (nums[currentChar] == int.Parse(num.ToString()))
- {
- isTrue = true;
- }
- }
- }
- }
- if (lines[i][j + 1] == '<')
- {
- if (nums.ContainsKey(currentChar))
- {
- if (nums.ContainsKey(lines[i][j + 2]))
- {
- if (nums[currentChar] < nums[lines[i][j + 2]])
- {
- isTrue = true;
- }
- }
- else
- {
- while (digit.Contains(lines[i][j + 2]))
- {
- num.Append(lines[i][j + 2]);
- j++;
- if (j + 2 >= lines[i].Length)
- {
- break;
- }
- }
- if (nums[currentChar] < int.Parse(num.ToString()))
- {
- isTrue = true;
- }
- }
- }
- }
- if (lines[i][j + 1] == '>')
- {
- if (nums.ContainsKey(currentChar))
- {
- if (nums.ContainsKey(lines[i][j + 2]))
- {
- if (nums[currentChar] > nums[lines[i][j + 2]])
- {
- isTrue = true;
- }
- }
- else
- {
- while (digit.Contains(lines[i][j + 2]))
- {
- num.Append(lines[i][j + 2]);
- j++;
- if (j + 2 >= lines[i].Length)
- {
- break;
- }
- }
- if (nums[currentChar] > int.Parse(num.ToString()))
- {
- isTrue = true;
- }
- }
- }
- }
- }
- return isTrue;
- }
- static void CheckForEqualCommand()
- {
- j+=2;
- num.Clear();
- int opa = lines[i].Length - 1;
- int sign = 1;
- int firstNum = 0;
- char operation = '+';
- if (nums.ContainsKey(lines[i][j]))
- {
- firstNum = nums[lines[i][j]];
- }
- else
- {
- if (lines[i][j] == '-')
- {
- sign = -1;
- j++;
- }
- while (digits.Contains(lines[i][j]))
- {
- num.Append(lines[i][j]);
- j++;
- if (j >= lines[i].Length)
- {
- break;
- }
- }
- if (j >= lines[i].Length)
- {
- nums[curchar] = int.Parse(num.ToString()) * sign;
- return;
- }
- firstNum = int.Parse(num.ToString()) * sign;
- }
- j++;
- int secondNum = 0;
- sign = 1;
- num.Clear();
- if (j>= lines[i].Length)
- {
- nums[curchar] = firstNum;
- return;
- }
- if (lines[i][j] == '+')
- {
- j++;
- }
- else if (lines[i][j] == '-')
- {
- operation = '-';
- j++;
- }
- if (nums.ContainsKey(lines[i][j]))
- {
- secondNum = nums[lines[i][j]];
- }
- else
- {
- if (lines[i][j] == '-')
- {
- sign = -1;
- j++;
- }
- while (digits.Contains(lines[i][j]))
- {
- num.Append(lines[i][j]);
- j++;
- if (j >= lines[i].Length)
- {
- break;
- }
- }
- secondNum = int.Parse(num.ToString()) * sign;
- }
- if (operation == '+')
- {
- nums[curchar] = firstNum + secondNum;
- }
- else
- {
- nums[curchar] = firstNum - secondNum;
- }
- //if (digits.Contains(lines[i][j]) && j == lines[i].Length - 1)
- //{
- // nums[curchar] = int.Parse(lines[i][j].ToString());
- //}
- //else if (nums.ContainsKey(lines[i][j]))
- //{
- // nums[curchar] = nums[lines[i][j]];
- //}
- //else if (lines[i][j] == '-' && digits.Contains(int.Parse(lines[i][j + 1].ToString())) && j + 1 == lines[i].Length - 1)
- //{
- // nums[curchar] = int.Parse(lines[i][j + 1].ToString()) * -1;
- //}
- //else if (nums.ContainsKey(lines[i][j]) && lines[i][j+ 1] == '+' && nums.ContainsKey(lines[i][j+2]))
- //{
- // //nums[curchar] =
- //}
- }
- static void ReadInput()
- {
- int counter = 0;
- text.Add(Console.ReadLine());
- while (text[counter] != "RUN")
- {
- text.Add(Console.ReadLine());
- counter++;
- }
- StringBuilder removedSpaces = new StringBuilder();
- for (int g = 0; g < text.Count; g++)
- {
- StringBuilder sb = new StringBuilder(text[g]);
- for (int b = 0; b < sb.Length; b++)
- {
- if (sb[b] != ' ')
- {
- removedSpaces.Append(sb[b]);
- }
- }
- removedSpaces.AppendLine();
- }
- lines = removedSpaces.ToString().Split(new string[] {"\r\n"},StringSplitOptions.RemoveEmptyEntries);
- nums.Add('X', 0);
- nums.Add('Y', 0);
- nums.Add('V', 0);
- nums.Add('W', 0);
- nums.Add('Z', 0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement