Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get all productions of ebnf #23

Open
furesoft opened this issue Jul 19, 2015 · 1 comment
Open

get all productions of ebnf #23

furesoft opened this issue Jul 19, 2015 · 1 comment

Comments

@furesoft
Copy link

hi,

how can i get all productions of an ebnf grammar (left part)?

i want to make a visual studio grammar language service

@KarmyDev
Copy link

Hi @furesoft !

I know this might be outdated, but i dont wanna leave it unanswered.

If this is what you want to get:
image
from this example EBNF grammar file:
image

then the code is very simple:

foreach(var child in grammar.Children)
{
    if (!string.IsNullOrEmpty(child.Name))
    {
        Console.WriteLine("Found grammar child:\t" + child.Name);
    }
}

In this code, you loop through grammar Children, and just reject those who dont have anything (Those are usually newlines in the EBNF source file)

By the way, you might ask what is grammar in this context. It's the new EbnfGrammar() object!

var grammar = new EbnfGrammar(EbnfStyle.Iso14977).Build(File.ReadAllText(args[0]), args[2]);

and args[2] is the start sequence keyword.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants