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

WebView with NSShadow slowdown

objective-c macos cocoa nsview

I have a webview that shows some animated boxes, but it slows down and lags horribly when I put a drop shadow in the view. Without the shadow, the webview contents animate smoothly.

Running a Batch File in the Same Directory from the VBS

batch-file vbscript runtime-error

I have a VBScript that is supposed to run a .bat or .vbs file, but it doesn't work!