Translating EBNF into Irony

I am using Irony to create a parser for a scripting language, but I've come across a little problem: how do I translate an EBNF expression like this in Irony?

'(' [ Ident { ',' Ident } ] ')'

I already tried some tricks like

Chunk.Rule = (Ident | Ident + "," + Chunk);
CallArgs.Rule = '(' + Chunk + ')' | '(' + ')';

But it's ugly and I'm not even sure if that works the way it should (haven't tried it yet...). Has anyone any suggestions?

EDIT: I found out these helper methods (MakeStarList, MakePlusList) but couldn't find out how to use them, because of the complete lack of documentation of Irony... Has anyone any clue?

Answers


// Declare the non-terminals
var Ident = new NonTerminal("Ident");
var IdentList = new NonTerminal("Term");

// Rules
IdentList.Rule = ToTerm("(") + MakePlusRule(IdentList, ",", Ident) + ")";
Ident.Rule = // specify whatever Ident is (I assume you mean an identifier of some kind).

You can use the MakePlusRule helper method to define a one-or-many occurrence of some terminal. The MakePlusRule is basically just present your terminals as standard recursive list-idiom:

Ident |  IdentList + "," + Ident

It also marks the terminal as representing a list, which will tell the parser to unfold the list-tree as a convenient list of child nodes.


Need Your Help

Need line breaks in database display for jpGraph

php mysql jpgraph

I'm learning how to use jpGraph to display bar graphs. The instructions explain how to create a .txt file with the following data:

suggest me well designed opensource web apps in .net

.net design architecture

I found architecture of Blogengine.net good and interesting. Are there other very well designed opensource web apps written in .Net ?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.