• R/O
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javaandroidc++linuxc#objective-ccocoa誰得qtrubybathyscaphegamephpguicwindows翻訳pythonomegattwitterframeworkbtronarduinovb.net計画中(planning stage)directxpreviewertestゲームエンジンdom

N88BASICが簡単に動くインタープリタを目指します。


コミットメタ情報

リビジョン25 (tree)
日時2018-09-30 16:01:43
作者bellyoshi

ログメッセージ

変更サマリ

差分

--- trunk/csmock/WindowsFormsApp1/WindowsFormsApp1/Form1.Designer.cs (revision 24)
+++ trunk/csmock/WindowsFormsApp1/WindowsFormsApp1/Form1.Designer.cs (revision 25)
@@ -28,40 +28,39 @@
2828 /// </summary>
2929 private void InitializeComponent()
3030 {
31- System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
3231 this.button1 = new System.Windows.Forms.Button();
33- this.textBox1 = new System.Windows.Forms.TextBox();
32+ this.txtCSsrc = new System.Windows.Forms.TextBox();
3433 this.button2 = new System.Windows.Forms.Button();
3534 this.textBox2 = new System.Windows.Forms.TextBox();
35+ this.txtAbSrc = new System.Windows.Forms.TextBox();
3636 this.SuspendLayout();
3737 //
3838 // button1
3939 //
40- this.button1.Location = new System.Drawing.Point(315, 23);
40+ this.button1.Location = new System.Drawing.Point(192, 23);
4141 this.button1.Name = "button1";
42- this.button1.Size = new System.Drawing.Size(75, 23);
42+ this.button1.Size = new System.Drawing.Size(128, 23);
4343 this.button1.TabIndex = 0;
44- this.button1.Text = "button1";
44+ this.button1.Text = "Compile and run";
4545 this.button1.UseVisualStyleBackColor = true;
4646 this.button1.Click += new System.EventHandler(this.button1_Click);
4747 //
48- // textBox1
48+ // txtCSsrc
4949 //
50- this.textBox1.Location = new System.Drawing.Point(12, 61);
51- this.textBox1.Multiline = true;
52- this.textBox1.Name = "textBox1";
53- this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both;
54- this.textBox1.Size = new System.Drawing.Size(698, 222);
55- this.textBox1.TabIndex = 1;
56- this.textBox1.Text = resources.GetString("textBox1.Text");
50+ this.txtCSsrc.Location = new System.Drawing.Point(12, 61);
51+ this.txtCSsrc.Multiline = true;
52+ this.txtCSsrc.Name = "txtCSsrc";
53+ this.txtCSsrc.ScrollBars = System.Windows.Forms.ScrollBars.Both;
54+ this.txtCSsrc.Size = new System.Drawing.Size(266, 222);
55+ this.txtCSsrc.TabIndex = 1;
5756 //
5857 // button2
5958 //
60- this.button2.Location = new System.Drawing.Point(405, 23);
59+ this.button2.Location = new System.Drawing.Point(359, 23);
6160 this.button2.Name = "button2";
6261 this.button2.Size = new System.Drawing.Size(75, 23);
6362 this.button2.TabIndex = 0;
64- this.button2.Text = "button2";
63+ this.button2.Text = "testcode";
6564 this.button2.UseVisualStyleBackColor = true;
6665 this.button2.Click += new System.EventHandler(this.button2_Click);
6766 //
@@ -74,6 +73,16 @@
7473 this.textBox2.Size = new System.Drawing.Size(698, 139);
7574 this.textBox2.TabIndex = 1;
7675 //
76+ // txtAbSrc
77+ //
78+ this.txtAbSrc.Location = new System.Drawing.Point(334, 61);
79+ this.txtAbSrc.Multiline = true;
80+ this.txtAbSrc.Name = "txtAbSrc";
81+ this.txtAbSrc.ScrollBars = System.Windows.Forms.ScrollBars.Both;
82+ this.txtAbSrc.Size = new System.Drawing.Size(266, 222);
83+ this.txtAbSrc.TabIndex = 1;
84+ this.txtAbSrc.Text = "Line(10,10)-(200,100)\r\n";
85+ //
7786 // Form1
7887 //
7988 this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
@@ -80,7 +89,8 @@
8089 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
8190 this.ClientSize = new System.Drawing.Size(727, 450);
8291 this.Controls.Add(this.textBox2);
83- this.Controls.Add(this.textBox1);
92+ this.Controls.Add(this.txtAbSrc);
93+ this.Controls.Add(this.txtCSsrc);
8494 this.Controls.Add(this.button2);
8595 this.Controls.Add(this.button1);
8696 this.Name = "Form1";
@@ -93,9 +103,10 @@
93103 #endregion
94104
95105 private System.Windows.Forms.Button button1;
96- private System.Windows.Forms.TextBox textBox1;
106+ private System.Windows.Forms.TextBox txtCSsrc;
97107 private System.Windows.Forms.Button button2;
98108 private System.Windows.Forms.TextBox textBox2;
109+ private System.Windows.Forms.TextBox txtAbSrc;
99110 }
100111 }
101112
--- trunk/csmock/WindowsFormsApp1/WindowsFormsApp1/Form1.cs (revision 24)
+++ trunk/csmock/WindowsFormsApp1/WindowsFormsApp1/Form1.cs (revision 25)
@@ -20,14 +20,38 @@
2020 {
2121 InitializeComponent();
2222 }
23+ void Run()
24+ {
25+ Process.Start("a.out.exe");
26+ }
27+ bool CompileABToCS()
28+ {
29+ string command = System.IO.Path.GetFullPath("getToken.exe");
2330
24- private void button1_Click(object sender, EventArgs e)
31+ ProcessStartInfo psInfo = new ProcessStartInfo();
2532
33+ psInfo.FileName = command; // 実行するファイル
34+ psInfo.CreateNoWindow = true; // コンソール・ウィンドウを開かない
35+ psInfo.UseShellExecute = false; // シェル機能を使用しない
36+ psInfo.RedirectStandardInput = true;
37+ psInfo.RedirectStandardOutput = true; // 標準出力をリダイレクト
38+
39+ Process p = Process.Start(psInfo); // アプリの実行開始
40+ var sw = p.StandardInput;
41+
42+ var src = txtAbSrc.Text;
43+ sw.Write(src);
44+ sw.Close();
45+ string output = p.StandardOutput.ReadToEnd(); // 標準出力の読み取り
46+ output = output.Replace("\r\r\n", "\n"); // 改行コードの修正
47+ txtCSsrc.Text = output;
48+ return true;
49+ }
50+ bool CompileCS()
2651 {
2752 var codeProvider = new CSharpCodeProvider();
2853 ICodeCompiler icc = codeProvider.CreateCompiler();
29- string Output = "Out.exe";
30- Button ButtonObject = (Button)sender;
54+ string Output = "a.out.exe";
3155
3256 textBox2.Text = "";
3357 var parameters = new CompilerParameters();
@@ -35,9 +59,9 @@
3559 parameters.GenerateExecutable = true;
3660 parameters.OutputAssembly = Output;
3761 parameters.ReferencedAssemblies.Add("ClassLibrary1.dll");
38- CompilerResults results = icc.CompileAssemblyFromSource(parameters, textBox1.Text);
39-
62+ CompilerResults results = icc.CompileAssemblyFromSource(parameters, txtCSsrc.Text);
4063
64+
4165 if (results.Errors.Count > 0)
4266 {
4367 textBox2.ForeColor = Color.Red;
@@ -55,10 +79,22 @@
5579 //Successful Compile
5680 textBox2.ForeColor = Color.Blue;
5781 textBox2.Text = "Success!";
58- //If we clicked run then launch our EXE
59- if (ButtonObject.Text == "Run") Process.Start(Output);
60-
82+ return true;
6183 }
84+ return false;
85+ }
86+ private void button1_Click(object sender, EventArgs e)
87+ {
88+ if (!CompileABToCS())
89+ {
90+ return;
91+ }
92+ if (!CompileCS())
93+ {
94+ return;
95+ }
96+ Run();
97+
6298
6399 }
64100
--- trunk/csmock/WindowsFormsApp1/getToken/compile.cs (revision 24)
+++ trunk/csmock/WindowsFormsApp1/getToken/compile.cs (revision 25)
@@ -19,16 +19,35 @@
1919 /// </summary>
2020 /// <returns>true:コンパイル成功</returns>
2121 public bool DoComple(){
22- Console.WriteLine("start compile");
22+ Console.Error.WriteLine("start compile");
2323 tg.Init();
2424 next();
25+ Header();
2526 while (! nextToken.isEof() )
2627 {
2728 statement();
2829 }
30+ Footer();
2931 return true;
3032 }
31-
33+ private void Header()
34+ {
35+ Console.WriteLine("using System;");
36+ Console.WriteLine("namespace HelloWorld");
37+ Console.WriteLine("{");
38+ Console.WriteLine("class Hello");
39+ Console.WriteLine("{");
40+ Console.WriteLine("static void Main()");
41+ Console.WriteLine("{");
42+ Console.WriteLine("var n88 = new ClassLibrary1.N88BASIC_DirectiveAgent();");
43+ }
44+ private void Footer()
45+ {
46+ Console.WriteLine("Console.Read();");
47+ Console.WriteLine("}");
48+ Console.WriteLine("}");
49+ Console.WriteLine("}");
50+ }
3251 public void statement()
3352 {
3453 switch (nextToken.TokenType)
@@ -103,7 +122,7 @@
103122 expression();//pt_end_x
104123 if(nextToken.TokenType == TokenType.Comma)
105124 {
106- Console.Write(",");
125+ Console.WriteLine(",");
107126 next();
108127 }
109128 else
@@ -158,7 +177,7 @@
158177 next();
159178 }
160179 line_end:
161- Console.WriteLine(")");
180+ Console.WriteLine(");");
162181
163182 }
164183 void expression()
@@ -256,7 +275,7 @@
256275
257276 void syntaxError()
258277 {
259- Console.WriteLine($"syntax error:line {nextToken.src_line}, col {nextToken.src_col}, {nextToken.src_str}");
278+ Console.Error.WriteLine($"syntax error:line {nextToken.src_line}, col {nextToken.src_col}, {nextToken.src_str}");
260279 }
261280 }
262281 }