Skip to content
Open

sql #66

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions A#/прога/A#.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

</Project>
48 changes: 48 additions & 0 deletions A#/прога/Arefmetika.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConsoleApp5;

namespace ConsoleApp5
{
public class Arefmetika
{
public String Sum(string a, string b, Dictionary<string, string> ver)
{
Convertor a1 = new Convertor();
Convertor b1 = new Convertor();
return Convert.ToString(a1.Con(a, ver) + b1.Con(b, ver));
}

public String Sub(string a, string b, Dictionary<string, string> ver)
{
Convertor a1 = new Convertor();
Convertor b1 = new Convertor();
return Convert.ToString(a1.Con(a, ver) - b1.Con(b, ver));
}

public String Div(string a, string b, Dictionary<string, string> ver)
{
Convertor a1 = new Convertor();
Convertor b1 = new Convertor();
return Convert.ToString(a1.Con(a, ver) / b1.Con(b, ver));
}

public String Mul(string a, string b, Dictionary<string, string> ver)
{
Convertor a1 = new Convertor();
Convertor b1 = new Convertor();
return Convert.ToString(a1.Con(a, ver) * b1.Con(b, ver));
}

public String res(string a, string b, Dictionary<string, string> ver)
{
Convertor a1 = new Convertor();
Convertor b1 = new Convertor();
return Convert.ToString(a1.Con(a, ver) % b1.Con(b, ver));
}

}
}
26 changes: 26 additions & 0 deletions A#/прога/Convektor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConsoleApp5;
using System.Text.RegularExpressions;

namespace ConsoleApp5
{
public class Convertor
{
public int Con(string a, Dictionary<string, string> ver)
{
foreach (string k in ver.Keys)
{

if (a == k) { return Convert.ToInt32(ver[k]); }
if (!Regex.IsMatch(a.ToString(), @"[A-Z]+$") && !Regex.IsMatch(a.ToString(), @"[a-z]+$")) { return Convert.ToInt32(a); }

}
return 0;
}

}
}
42 changes: 42 additions & 0 deletions A#/прога/Oshibki.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using ConsoleApp5;

namespace ConsoleApp5
{
public class Oshibki
{
public static string Okaziia(string a)
{

if (a.Contains("if") && !a.Contains("goto"))
{

return "Okaziia" ;
}
string[] w = a.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
for (int j = 0;j < w.Length;j++)
{
if (w[j]=="=" && j != 1 )
{
return "Okaziia" ;
}


}

if ((a.Contains(">") || a.Contains(">=") || a.Contains("<=") || a.Contains("<") || a.Contains("==") || a.Contains("!=")) && !a.Contains("if"))
{
return "Okaziia" ;
}
return"";



}
}
}
225 changes: 225 additions & 0 deletions A#/прога/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using ConsoleApp5;


namespace ConsoleApp5
{
public class Program
{
public static string LastElement(string a)
{
string[] w = a.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
return w[w.Length-1];
}
public static string IfElse(string str,Dictionary<string, string> ver)
{
//условные конструкции

Uslovie uslov = new Uslovie();


string[] w = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

for (int j = 0; j < w.Length; j++)
{
if (w[j] == ">")
{

if(uslov.More(w[j-1],w[j+1],ver) == "true") { return "true";}
else{return "fals";}

}

if (w[j] == "<")
{
if(uslov.Less(w[j-1],w[j+1],ver) == "true"){ return "true";}
else{return "fals";}

}

if (w[j] == ">=")
{
if(uslov.MoreOrEqually(w[j-1],w[j+1],ver) == "true"){ return "true"; }
else{return "fals";}

}

if (w[j] == "<=")
{
if(uslov.LessOrEqually(w[j-1],w[j+1],ver) == "true"){ return "true"; }
else{return "fals";}

}

if (w[j] == "==")
{
if(uslov.Equally (w[j-1],w[j+1],ver) == "true"){return "true"; }
else{return "fals";}

}

if (w[j] == "!=")
{
if(uslov.NotEqual(w[j-1],w[j+1],ver) == "true"){return "true"; }
else{return "fals";}

}
}
return "";



}

static void Main()
{
int km = 0;
Dictionary<string, string> variables = new Dictionary<string, string>();
Dictionary<string, int> metki = new Dictionary<string, int>();


string[] s = File.ReadAllLines("./Text.txt");

for(int i = 0; i < s.Length; i++ )
{
if(Oshibki.Okaziia(s[i]) == "Okaziia")
{
Console.WriteLine($"Оказия, ошибка в строке {i+1}");
throw new Exception();
}
}

for(int i = 0; i < s.Length; i++ )//запоменание переменных
{
string[] w = s[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

for (int j = 0; j < w.Length; j++)
{


if (w[j] == "read") { variables.Add(w[j + 1], Console.ReadLine()); break; }


if (s[i].Contains("+") || s[i].Contains("-") || s[i].Contains("/") || s[i].Contains("*")) { break; }
else
{
if (w[j] == "=" )
{
variables.Add(w[j - 1], w[j + 1]); break;
}

}

}

}
for(int i = 0; i < s.Length; i++ )//запоменание меток
{
string[] w = s[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

for (int j = 0; j < w.Length; j++)
{
if(w[j].Contains(":")){metki.Add(w[j].Trim(new char[]{':'}),i);}

}
}



while(km < s.Length)
{


if (s[km].Contains("goto") && !s[km].Contains("if"))
{

string[] word = s[km].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
for (int l =0; l <word.Length; l++)
{
if (word[l] == "goto")
{
km = metki[word[l+1]];

}
}

}

if (s[km].Contains("if"))
{
if(IfElse(s[km],variables)=="true")
{
km=metki[LastElement(s[km])];

}

}


//арефметические действия

string[] w = s[km].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

for (int j = 0; j < w.Length; j++)
{
if (w[j] == "+")
{
Arefmetika summa = new Arefmetika();
variables[w[0]] = summa.Sum(w[j - 1], w[j + 1], variables);

}
if (w[j] == "-")
{
Arefmetika subtraction = new Arefmetika();
variables[w[0]] = subtraction.Sub(w[j - 1], w[j + 1], variables);

}

if (w[j] == "/")
{
Arefmetika division = new Arefmetika();
variables[w[0]] = division.Div(w[j - 1], w[j + 1], variables);

}

if (w[j] == "*")
{
Arefmetika multiplication = new Arefmetika();
variables[w[0]] = multiplication.Mul(w[j - 1], w[j + 1], variables);

}

if (w[j] == "%")
{
Arefmetika residue = new Arefmetika();
variables[w[0]] = residue.res(w[j - 1], w[j + 1], variables);

}
}

km++;

}
//вывод переменной
for(int i=0; i< s.Length; i++)
{
if (s[i].Contains("print"))
{
string[] w = s[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
for(int j = 0;j < w.Length;j++)
{
if(w[j]=="print"){Console.WriteLine($"{w[j+1]}= {variables[w[j+1]]}");}
}
}
}

Console.ReadLine();
}

}
}
11 changes: 11 additions & 0 deletions A#/прога/Text.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
read N
R = 1
start:
if N > 1 goto step
print R
goto end
step:
R = R * N
N = N - 1
goto start
end:
Loading