Search code examples
c#parsingyacc

Lex/Yacc for C#?


Actually, maybe not full-blown Lex/Yacc. I'm implementing a command-interpreter front-end to administer a webapp. I'm looking for something that'll take a grammar definition and turn it into a parser that directly invokes methods on my object. Similar to how ASP.NET MVC can figure out which controller method to invoke, and how to pony up the arguments.

So, if the user types "create foo" at my command-prompt, it should transparently call a method:

private void Create(string id) { /* ... */ }

Oh, and if it could generate help text from (e.g.) attributes on those controller methods, that'd be awesome, too.


Solution

  • I'm not sure Lex/Yacc will be of any help. You'll just need a basic tokenizer and an interpreter which are faster to write by hand. If you're still into parsing route see Irony.

    As a sidenote: have you considered PowerShell and its commandlets?