J
Jon Slaughter
Is there anything like yacc or spirit for C#? What is the "standard" method
for parsing grammars in C#?
The last few days I have been looking at boost spirit and really like how it
works. What I was hoping for is a library that could take an ABNF grammar
and output C# code that represents that grammar. (A tree of classes that
contained the syntatic structure of the grammar which)
Right now a friend of mine is working on an parser and I helped him
implement the grammar in Spirit.
What I essentially did was write the grammar in spirit notation, write
classes of classes that had there fields filled with semantic actions
connected to the rules. There seems to be a duplicate of information though
and there seems to be some generalizations that could be made.
i.e.,
suppose we have the grammar
start ::= a | b | c
a ::= d | *f
b ::= *(c d)
c ::= f | *(f d)
where d and f are terminals
then the programmtic structure could be represented by
class start
{
_a a;
_b b;
_c c;
}
class _a
{
_d d;
list<_f> f;
}
class _b
{
list<{_c, _d}> cd
}
class _c
{
_f f;
list<{_f, _d}> fd
}
where by {_c, _d} I mean two classes that are "combined" in some sense. ONe
could have
struct _cd
{
_c c;
_d d;
}
typedef [type of d] _d;
typedef [type of f] _f;
to represent that.
Anyways. The point is that it would seem that one could generate a
"programmatic tree" from the grammar that would contain the data and one
then would just need a parser for it.
The problem that I'm having with bit spirit is that I'm having to code all
the actions that just stick in information into a recurively defined tree of
structures that essentially outline the grammar in the first place.
I'm not sure if one can have a "programmtic tree" like above for all
classes(it would seem any type of looping might cause problems).
I think all I want is some programmtic representation of the parsed data to
work with. While one probably can't represent all the needed information
using ABNF one probably could extend the it to handle most of the issues.
(such working with enums, etc...).
Maybe one can even represnt the rules as classes in a similar fashion I have
given above? I think this would end up following the lines of boost spirit
though except using classes/generics instead of templates.
Anyways, are there any libraries in C# that do this sorta thing?
Thanks,
Jon
for parsing grammars in C#?
The last few days I have been looking at boost spirit and really like how it
works. What I was hoping for is a library that could take an ABNF grammar
and output C# code that represents that grammar. (A tree of classes that
contained the syntatic structure of the grammar which)
Right now a friend of mine is working on an parser and I helped him
implement the grammar in Spirit.
What I essentially did was write the grammar in spirit notation, write
classes of classes that had there fields filled with semantic actions
connected to the rules. There seems to be a duplicate of information though
and there seems to be some generalizations that could be made.
i.e.,
suppose we have the grammar
start ::= a | b | c
a ::= d | *f
b ::= *(c d)
c ::= f | *(f d)
where d and f are terminals
then the programmtic structure could be represented by
class start
{
_a a;
_b b;
_c c;
}
class _a
{
_d d;
list<_f> f;
}
class _b
{
list<{_c, _d}> cd
}
class _c
{
_f f;
list<{_f, _d}> fd
}
where by {_c, _d} I mean two classes that are "combined" in some sense. ONe
could have
struct _cd
{
_c c;
_d d;
}
typedef [type of d] _d;
typedef [type of f] _f;
to represent that.
Anyways. The point is that it would seem that one could generate a
"programmatic tree" from the grammar that would contain the data and one
then would just need a parser for it.
The problem that I'm having with bit spirit is that I'm having to code all
the actions that just stick in information into a recurively defined tree of
structures that essentially outline the grammar in the first place.
I'm not sure if one can have a "programmtic tree" like above for all
classes(it would seem any type of looping might cause problems).
I think all I want is some programmtic representation of the parsed data to
work with. While one probably can't represent all the needed information
using ABNF one probably could extend the it to handle most of the issues.
(such working with enums, etc...).
Maybe one can even represnt the rules as classes in a similar fashion I have
given above? I think this would end up following the lines of boost spirit
though except using classes/generics instead of templates.
Anyways, are there any libraries in C# that do this sorta thing?
Thanks,
Jon