开发者

Patterns to implement this grammar into C# code

Hey guys, I'm creating this little BNF grammar and I wanted to

<template>::= <types><editors>
<types>::= <type>+
<type>::= <property>+
<property>::= <name><type>
<editors>::= <editor>+
<editor>::= <name><type>(<textfield>|<form>|<list>|<pulldown>)+
<textfield>::= <label><property>[<editable>]
<form>::= <label><property><editor>
<list>::= <label><property><item-editor>
<pulldown>::= <label><property><option>+
<option>::= <value>

One possible solution we have in mind is to create POCO's that have annotations of the XMLSerialization namespace, like this, for example:

[XMLRoot("template")]
public 开发者_如何学编程class Template{ 
    [XMLElement("types")]        
    public Types types{

    }
}

However I want to explore more solutions, what do you guys think?


If you want to implement this by yourself, look at Interpreter Design Pattern.


If you want to parse a specific input of some complexity, use ANTLR. See C# instructions to get started.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜