用于 C# 的 Lex/Yacc? [英] Lex/Yacc for C#?

查看:50
本文介绍了用于 C# 的 Lex/Yacc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,可能不是成熟的 Lex/Yacc.我正在实现一个命令解释器前端来管理 web 应用程序.我正在寻找一些可以接受语法定义并将其转换为直接调用我的对象上的方法的解析器的东西.类似于 ASP.NET MVC 如何确定调用哪个控制器方法,以及如何处理参数.

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.

所以,如果用户在我的命令提示符下输入create foo",它应该透明地调用一个方法:

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.

推荐答案

我不确定 Lex/Yacc 是否会有所帮助.您只需要一个基本的标记器和一个手动编写速度更快的解释器.如果您仍在解析路线,请参阅 Irony.

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.

作为旁注:您是否考虑过 PowerShell 及其命令行开关?

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

这篇关于用于 C# 的 Lex/Yacc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆