Hello o/
I was experimenting with writing a language implementation so bump into this new thing called "recursive descent parser" at first it seemed complex but as I programmed it everything magically worked. I will attach the code tell me if I am wrong somewhere.
namespace ContextFreeGrammarDemo
{
static class Parser
{
static string code = "aaaabbbb";
static int cursor = 0;
public static void Parse()
{
if (cursor >= code.Length)
return;
char currentChar = code[cursor];
if (currentChar == 'a')
{
Console.WriteLine("a");
cursor++;
Parse();
if (cursor < code.Length && code[cursor] == 'b')
{
Console.WriteLine("b");
cursor++;
Parse();
}
else
{
Console.WriteLine("Oopsie");
Environment.Exit(1);
}
}
}
}
class Program
{
public static void Main(string[] args)
{
Parser.Parse();
}
}
}