I have this code that generates tokens in string form based on what is matched with Regex:
public static List<Tuple<string, string>> GetTokens(string input)
{
List<Tuple<string, string>> ret = new List<Tuple<string, string>>();
Regex r = new Regex("(?<Comma>\\,)" +
"|(?<Dot>\\.)" +
"|(?<SemiColon>\\;)" +
"|(?<DoubleDot>\\:)" +
"|(?<Increment>\\+\\+)" +
"|(?<greater>\\>)" +
"|(?<smaller>\\<)" +
"|(?<Decrement>\\-\\-)" +
"|(?<SystemCommand> *deviceListCount *| *deviceList *| *devices *| *device *| *str *| *int *| *dev *| *bool *| *print *| *wait *| *device *| *if *| *while *| *loop *)" +
"|(?<OpenBracket>\\()" +
"|(?<CloseBracket>\\))" +
"|(?<DeviceCommand> *On *| *Off *| *Open *| *Close *| *Move *| *Detect *)" +
"|(?<Integer>\\d+)"+
"|(?<equals> *[=] *)" +
"|(?<String>[aA-zZ0-9 ]*)");
foreach (Match item in r.Matches(input))
{
for (int i = 1; i < item.Groups.Count; i++)
{
string v = item.Groups[i].Value;
if (v != "")
{
ret.Add(new Tuple<string, string>(r.GroupNameFromNumber(i), v));
}
}
}
return ret;
}
To start off simple, how can I use the method above to create a print command:
print(hello world)
I want to run the code with something like this:
RunCode(GetTokens("print(Hello World)"))
This code should produce the same effect as:
Console.WriteLine("Hello World");