.NET 4.x Компиляция любых команд в EXE файл - C#
Формулировка задачи:
у меня такая проблема, я пишу вобщем компилятор для своего языка (FASTER+) его пример
load var1 = 4
load var1 = var 2
out 'Hello World!' = 1
out (var1 + var2) = 1
rdKey
Я могу отслеживать любые строки и преобразовать их в код C# а вот в EXE файл не умею.
Вопрос: КАК???
(Написаный код):
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace FCompiler
{
public partial class Form1 : Form
{
OpenFileDialog openDialog = new OpenFileDialog();
SaveFileDialog saveDialog = new SaveFileDialog();
string fileName;
Random yourString = new Random();
public Form1()
{
InitializeComponent();
}
private void button4_Click(object sender, EventArgs e)
{
MessageBox.Show("Aperture Science © FASTER+ IDE Compiler®");
}
private void button1_Click(object sender, EventArgs e)
{
// "New" function
MessageBox.Show("WARNING! Unsaved files will be lost!");
richTextBox1.Text = "";
}
private void button5_Click(object sender, EventArgs e)
{
// "Open" function
openDialog.ShowDialog();
string[] fileText = File.ReadAllLines(openDialog.FileName);
// string fileTextOut = "";
// fileTextOut = fileTextOut + fileText;
// richTextBox1.Text = fileTextOut;
}
private void button2_Click(object sender, EventArgs e)
{
// "Save" function
saveDialog.ShowDialog();
File.WriteAllText(saveDialog.FileName, richTextBox1.Text, Encoding.Default);
textBox1.Text = saveDialog.FileName;
}
private void Form1_activated(object sender, EventArgs e)
{
// Когда форма активирукется исполяются команды:
openDialog.Filter = "FASTER+ Files (*.fp)|*.fp|FASTER.NET Files (*.fpnet)|*.fpnet|All files (*.*)|*.*";
openDialog.Title = "Open FASTER+ Programs";
saveDialog.Filter = "FASTER+ Files (*.fp)|*.fp|FASTER.NET Files (*.fpnet)|*.fpnet|All files (*.*)|*.*";
saveDialog.Title = "Save FASTER+ Programs";
}
private void button3_Click(object sender, EventArgs e)
{
// "Compile" function
string path = @textBox1.Text;
StreamReader reader = new StreamReader(path);
string text = reader.ReadToEnd();
string[] lines = text.Split('\n');
string line = lines[0]; //читаем 1-ю строку
compiling: if (line == "out '" + yourString + "' = 1") {
Console.WriteLine(yourString);
line = lines[+1];
goto compiling;
}
if (line == "out '" + yourString + "' = 0")
{
Console.Write(yourString);
line = lines[+1];
goto compiling;
}
if (line == "rdKey")
{
Console.ReadKey();
}
}
}
}Решение задачи: «.NET 4.x Компиляция любых команд в EXE файл»
textual
Листинг программы
parameters.ReferencedAssemblies.Add("System.Core.dll");
parameters.ReferencedAssemblies.Add("System.dll");