I am trying to make a Parser and Interpreter or Compiler. Right now when I try to execute the test code all it shows is blank. Am I not parsing it or is something interfering or what? Can someone take a look and tell me whats not working?
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
namespace Mikebite
{
class Program
{
static void Main(string[] args)
{
try
{
string code = "";
compile("function Main {", code);
compile("x = Hello world!!", code);
compile("print x", code);
compile("input x", code);
compile("} ;", code);
Console.WriteLine(code);
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
}
}
static void compile(string line, string code)
{
string[] tokens = line.Split(' ');
for (int i = 0; i < tokens.Length; i++)
{
if (tokens[i].Contains("function"))
{
code += ":" + tokens[i+1];
i++;
}
else if (tokens[i].Contains("="))
{
code += "PUSH " + tokens[i-1] + "\n";
code += "PUSH " + tokens[i+1] + "\n";
code += "SET\n";
i++;
}
else if (tokens[i].Contains("exec"))
{
code += "GOTO " + tokens[i+1] + "\n";
i++;
}
else if (tokens[i].Contains("}"))
{
code += "RTN\n";
}
else if (tokens[i].Contains("input"))
{
code += "PUSH " + tokens[i+1] + "\nPUSH NULL\nINPUT\n";
}
else if (tokens[i].Contains("print"))
{
code += "PUSH " + tokens[i+1] + "\nPUSH NULL\nPRINT\n";
}
}
}
}
}