473,732 Members | 2,227 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Compilers, parsing, etc...

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<_ff;
}

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
"programmat ic 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 "programmti c 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
Dec 5 '06 #1
3 3456
"Jon Slaughter" <Jo***********@ Hotmail.comwrot e:
>Is there anything like yacc or spirit for C#? What is the "standard" method
for parsing grammars in C#?
Antlr. You effectively end up using it like spirit when producing
ASTs. But it has a pre-processing step first.

(Actually, what I found most enjoyable was writing my parser in F#
with F#lex and F#yacc. F# is a .net language so it interops fine with
C#. And functional languages like F# just seem infintely more suited
to manipulating ASTs than imperative/OO languages.)

--
Lucian
Dec 5 '06 #2
I don't know if it will help, but you can get a good start on a parser in C#
by consulting http://www.frontiernet.net/~fredm/dps/Contents.htm , chapter
3. That contains the main logic for a parser, in about 200 statements.
Chapter 4 will show you how to build up the parse tree (with details left to
the reader :-) ).

"Jon Slaughter" <Jo***********@ Hotmail.comwrot e in message
news:0r******** *********@newss vr27.news.prodi gy.net...
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<_ff;
}

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
"programmat ic 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 "programmti c 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

Dec 5 '06 #3
Jon Slaughter wrote:
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<_ff;
}

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
"programmat ic 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 "programmti c 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?
http://www.antlr.org/
http://grammatica.percederberg.net/index.html
http://www.ssw.uni-linz.ac.at/Coco/
http://home.earthlink.net/~slkpg/

etc.etc.

Pick a blue, red or yellow based on what you like.

Arne
Dec 9 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
9442
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $ Last-Modified: $Date: 2003/10/28 19:48:44 $ Author: A.M. Kuchling <amk@amk.ca> Status: Draft Type: Standards Track
6
2587
by: Hrvoje Blazevic | last post by:
Are there any good books on Interpreter/Compiler construction, using Python as a defining language out there? Something like Essentials of Programming Languages 2e ? I would appreciate some pointers -- Hrvoje
10
3169
by: Bill Davidson | last post by:
Hi there, Please forgive me for posting this article on multiple groups. Being new in the newsgroups, I was not sure which group would have been appropriate for my question. Sorry. My Question ----------- I am looking for a list of popular compilers and/or platforms that *do not* support native C++ exceptions. Any pointers in this
16
2906
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed loaded into cache, the slideshow doesn't look very nice. I am not sure how/when to call the slideshow() function to make sure it starts after the preload has been completed.
13
2701
by: Derek | last post by:
As I understand it there is a good amount of link compatibility among C compilers. For example, I can compile main.c with GCC and func.c with Sun One and link the objects using either linker (GNU or Sun). What I'm curious about is why this compatibility exists in the absence of a standard C ABI? What encourages C compiler vendors to agree on implementation issues such as alignment, packing, etc., such that their object
8
2192
by: pransri2006 | last post by:
Hi guys! I think all of u know about the designing of compilers. Can any body tell me about the designing of the compilers. And also tell me the difference between the compilers and Interpreter which weresically used by the computers. I want to know about the basic compiler software.
3
4385
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in the file) with the location. And for a particular section I parse only that section. The file is something like, .... DATAS
0
3193
by: JosAH | last post by:
Greetings, welcome back at the sequel of the parsers article chapter. This part is dedicated to the ExpressionParser, the largest parser class for our little language. This class parses a complete expression and just like the other parser classes calls the Generator on the fly. When the parse has completed successfully, the generated code is returned. Otherwise the parse is aborted and an exception is thrown telling the reason of the...
0
3373
by: JosAH | last post by:
Greetings, this week's article part discusses the parsers used for our little language. We will implement the parsers according to the grammar rules we defined in the second part of this article. As you will see shortly, the implementation of the parsers is an almost one-to-one translation of those grammar rules. Recursive descent parsing The grammar rules are highly recursive, i.e. one rule mentions another rule
0
8774
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9181
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.