473,408 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

C# Grammar issues

MBR
Hello... I'm using the grammar at:

http://msdn.microsoft.com/library/de...harpspec_c.asp
as a reference in creating my own C# parser using a custom framework.
(Please let me know if there's a better group to post in.)

Some questions:
(1) Is this grammar specification known to be complete and correct?
(2) Is there a normalized LL grammar available already suited for
(backtracking) recursive decent systems?
(3) Much of the grammar can be simplified by using EBNF-style
specifications -- it would be nice to find one this way already
(5) Is there a "parameterized" version that allows for c# 2.0 and c# 3.0,
with and without managed extensions?
(6) Are there alternate sources? (I've found some incomplete grammars and
some that are already re-purposed to the point of being unreadable.)

(7) There are simple and some not so simple left-recursions in the grammar.

The simple, direct recursions can be changed to EBNF-style repetitions
without left recursion:

multiplicative-expression:
unary-expression
multiplicative-expression * unary-expression
multiplicative-expression / unary-expression
multiplicative-expression % unary-expression

becomes (I think):

multiplicative_expression ::=
(unary_expression, "*" )* , unary_expression |
(unary_expression, "/" )* , unary_expression |
(unary_expression, "%" )* , unary_expression.

But there are also some very deep recursions such as this one (of many that
can be detected):

type -->
| reference_type -->
| | array_type -->
| | | non_array_type -->
< < < < type <-- Recursive

I'm wondering if this is necessary or even correct. Unlike the direct
recursions, in some of these cases it's hard to tell what's "meant" making
re-writes difficult.

Any pointers/advice appreciated...
thanks,
mike

--
Posted via a free Usenet account from http://www.teranews.com

Mar 9 '07 #1
10 4674
This is nowhere near an answer to your question, but I'm curious to know why
you're trying to write your own C# parser.

Since this is essentially a proprietary language (submissions to ECMA
notwithstanding) the behavior of MS's parser is by definition the "official"
behavior, and the inevitable ambiguous details of implementation are far
from completely documented. So trying to come up with a functionally
equivalent parser in the absence of the internal MS code is a fool's errand.

So why waste your time? And, in fact, what's the point?

But nevertheless, this is a serious question, not a flame, and I hope you
will see your way clear to respond.

Tom Dacon
Dacon Software Consulting
"MBR" <no***@nospam.comwrote in message
news:45***********************@free.teranews.com.. .
Hello... I'm using the grammar at:
http://msdn.microsoft.com/library/de...harpspec_c.asp
as a reference in creating my own C# parser using a custom framework.
(Please let me know if there's a better group to post in.)

Some questions:
(1) Is this grammar specification known to be complete and correct?
(2) Is there a normalized LL grammar available already suited for
(backtracking) recursive decent systems?
(3) Much of the grammar can be simplified by using EBNF-style
specifications -- it would be nice to find one this way already
(5) Is there a "parameterized" version that allows for c# 2.0 and c# 3.0,
with and without managed extensions?
(6) Are there alternate sources? (I've found some incomplete grammars and
some that are already re-purposed to the point of being unreadable.)

(7) There are simple and some not so simple left-recursions in the
grammar.

The simple, direct recursions can be changed to EBNF-style repetitions
without left recursion:

multiplicative-expression:
unary-expression
multiplicative-expression * unary-expression
multiplicative-expression / unary-expression
multiplicative-expression % unary-expression

becomes (I think):

multiplicative_expression ::=
(unary_expression, "*" )* , unary_expression |
(unary_expression, "/" )* , unary_expression |
(unary_expression, "%" )* , unary_expression.

But there are also some very deep recursions such as this one (of many
that can be detected):

type -->
| reference_type -->
| | array_type -->
| | | non_array_type -->
< < < < type <-- Recursive

I'm wondering if this is necessary or even correct. Unlike the direct
recursions, in some of these cases it's hard to tell what's "meant" making
re-writes difficult.

Any pointers/advice appreciated...
thanks,
mike

--
Posted via a free Usenet account from http://www.teranews.com

Mar 9 '07 #2
MBR
"Tom Dacon" <td****@community.nospamwrote in message
news:e0**************@TK2MSFTNGP05.phx.gbl...
This is nowhere near an answer to your question, but I'm curious to know
why you're trying to write your own C# parser.

Since this is essentially a proprietary language (submissions to ECMA
notwithstanding) the behavior of MS's parser is by definition the
"official" behavior, and the inevitable ambiguous details of
implementation are far from completely documented. So trying to come up
with a functionally equivalent parser in the absence of the internal MS
code is a fool's errand.
You may be right, although I hope it's not the case - considering the ECMA
submission as you mentioned.
I knm
>
So why waste your time? And, in fact, what's the point?
There are many reasons why one would want to do such a thing: as a general
exersize, to understand various parsing systems/tradeoffs, to have a system
that exists outside of the MS development environment, to have a system that
exhibits specialized/particular behaviors that 3rd party systems don't
support, etc. -- my answer is some percentage of each of these. C# is an
initial target language (and one I use often), so that's why I'm starting
with it.

thanks
m
>
But nevertheless, this is a serious question, not a flame, and I hope you
will see your way clear to respond.

Tom Dacon
Dacon Software Consulting
"MBR" <no***@nospam.comwrote in message
news:45***********************@free.teranews.com.. .
>Hello... I'm using the grammar at:
http://msdn.microsoft.com/library/de...harpspec_c.asp
as a reference in creating my own C# parser using a custom framework.
(Please let me know if there's a better group to post in.)

Some questions:
(1) Is this grammar specification known to be complete and correct?
(2) Is there a normalized LL grammar available already suited for
(backtracking) recursive decent systems?
(3) Much of the grammar can be simplified by using EBNF-style
specifications -- it would be nice to find one this way already
(5) Is there a "parameterized" version that allows for c# 2.0 and c# 3.0,
with and without managed extensions?
(6) Are there alternate sources? (I've found some incomplete grammars and
some that are already re-purposed to the point of being unreadable.)

(7) There are simple and some not so simple left-recursions in the
grammar.

The simple, direct recursions can be changed to EBNF-style repetitions
without left recursion:

multiplicative-expression:
unary-expression
multiplicative-expression * unary-expression
multiplicative-expression / unary-expression
multiplicative-expression % unary-expression

becomes (I think):

multiplicative_expression ::=
(unary_expression, "*" )* , unary_expression |
(unary_expression, "/" )* , unary_expression |
(unary_expression, "%" )* , unary_expression.

But there are also some very deep recursions such as this one (of many
that can be detected):

type -->
| reference_type -->
| | array_type -->
| | | non_array_type -->
< < < < type <-- Recursive

I'm wondering if this is necessary or even correct. Unlike the direct
recursions, in some of these cases it's hard to tell what's "meant"
making re-writes difficult.

Any pointers/advice appreciated...
thanks,
mike

--
Posted via a free Usenet account from http://www.teranews.com



--
Posted via a free Usenet account from http://www.teranews.com

Mar 9 '07 #3
Tom Dacon <td****@community.nospamwrote:
This is nowhere near an answer to your question, but I'm curious to know why
you're trying to write your own C# parser.

Since this is essentially a proprietary language (submissions to ECMA
notwithstanding) the behavior of MS's parser is by definition the "official"
behavior, and the inevitable ambiguous details of implementation are far
from completely documented. So trying to come up with a functionally
equivalent parser in the absence of the internal MS code is a fool's errand.

So why waste your time? And, in fact, what's the point?

But nevertheless, this is a serious question, not a flame, and I hope you
will see your way clear to respond.
Would you ask the same question of the Mono team? Just as an example of
why someone might want to do it...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 9 '07 #4
Don't know if the link is the current.
I use the specs from here
http://msdn2.microsoft.com/en-us/net.../aa569283.aspx.

You can find more here (like EBNF style C# grammar)
http://dotnet.jku.at/Projects/Rotor/2.0b/HowTo.html.

Some other links you might find useful:
http://www.antlr.org/grammar/list
http://www.ssw.uni-linz.ac.at/Research/Projects/Coco/
"MBR" <no***@nospam.comha scritto nel messaggio
news:45***********************@free.teranews.com.. .
Hello... I'm using the grammar at:
http://msdn.microsoft.com/library/de...harpspec_c.asp
as a reference in creating my own C# parser using a custom framework.
(Please let me know if there's a better group to post in.)

Some questions:
(1) Is this grammar specification known to be complete and correct?
(2) Is there a normalized LL grammar available already suited for
(backtracking) recursive decent systems?
(3) Much of the grammar can be simplified by using EBNF-style
specifications -- it would be nice to find one this way already
(5) Is there a "parameterized" version that allows for c# 2.0 and c# 3.0,
with and without managed extensions?
(6) Are there alternate sources? (I've found some incomplete grammars and
some that are already re-purposed to the point of being unreadable.)

(7) There are simple and some not so simple left-recursions in the
grammar.

The simple, direct recursions can be changed to EBNF-style repetitions
without left recursion:

multiplicative-expression:
unary-expression
multiplicative-expression * unary-expression
multiplicative-expression / unary-expression
multiplicative-expression % unary-expression

becomes (I think):

multiplicative_expression ::=
(unary_expression, "*" )* , unary_expression |
(unary_expression, "/" )* , unary_expression |
(unary_expression, "%" )* , unary_expression.

But there are also some very deep recursions such as this one (of many
that can be detected):

type -->
| reference_type -->
| | array_type -->
| | | non_array_type -->
< < < < type <-- Recursive

I'm wondering if this is necessary or even correct. Unlike the direct
recursions, in some of these cases it's hard to tell what's "meant" making
re-writes difficult.

Any pointers/advice appreciated...
thanks,
mike

--
Posted via a free Usenet account from http://www.teranews.com

Mar 9 '07 #5
There are a few nice things you can make from a C# parser.
Like static analysis tools, executing C# files as script (C#.Script),
automated testing etc.

"Tom Dacon" <td****@community.nospamha scritto nel messaggio
news:e0**************@TK2MSFTNGP05.phx.gbl...
This is nowhere near an answer to your question, but I'm curious to know
why you're trying to write your own C# parser.

Since this is essentially a proprietary language (submissions to ECMA
notwithstanding) the behavior of MS's parser is by definition the
"official" behavior, and the inevitable ambiguous details of
implementation are far from completely documented. So trying to come up
with a functionally equivalent parser in the absence of the internal MS
code is a fool's errand.

So why waste your time? And, in fact, what's the point?

But nevertheless, this is a serious question, not a flame, and I hope you
will see your way clear to respond

Tom Dacon
Dacon Software Consulting
"MBR" <no***@nospam.comwrote in message
news:45***********************@free.teranews.com.. .
>Hello... I'm using the grammar at:
http://msdn.microsoft.com/library/de...harpspec_c.asp
as a reference in creating my own C# parser using a custom framework.
(Please let me know if there's a better group to post in.)

Some questions:
(1) Is this grammar specification known to be complete and correct?
(2) Is there a normalized LL grammar available already suited for
(backtracking) recursive decent systems?
(3) Much of the grammar can be simplified by using EBNF-style
specifications -- it would be nice to find one this way already
(5) Is there a "parameterized" version that allows for c# 2.0 and c# 3.0,
with and without managed extensions?
(6) Are there alternate sources? (I've found some incomplete grammars and
some that are already re-purposed to the point of being unreadable.)

(7) There are simple and some not so simple left-recursions in the
grammar.

The simple, direct recursions can be changed to EBNF-style repetitions
without left recursion:

multiplicative-expression:
unary-expression
multiplicative-expression * unary-expression
multiplicative-expression / unary-expression
multiplicative-expression % unary-expression

becomes (I think):

multiplicative_expression ::=
(unary_expression, "*" )* , unary_expression |
(unary_expression, "/" )* , unary_expression |
(unary_expression, "%" )* , unary_expression.

But there are also some very deep recursions such as this one (of many
that can be detected):

type -->
| reference_type -->
| | array_type -->
| | | non_array_type -->
< < < < type <-- Recursive

I'm wondering if this is necessary or even correct. Unlike the direct
recursions, in some of these cases it's hard to tell what's "meant"
making re-writes difficult.

Any pointers/advice appreciated...
thanks,
mike

--
Posted via a free Usenet account from http://www.teranews.com


Mar 9 '07 #6
MBR
Thanks for the response. I found most of these during my original search,
but not all.
See notes below:

"Laura T." <LT@NOWHERE.COMwrote in message
news:u4**************@TK2MSFTNGP03.phx.gbl...
Don't know if the link is the current.
I use the specs from here
http://msdn2.microsoft.com/en-us/net.../aa569283.aspx.
This is great. The microsoft link I found seems both stale and outright
wrong -- I'm not sure it addresses all the problems, but at least it doesn't
contain the one suspect recursion I noted below.
You can find more here (like EBNF style C# grammar)
http://dotnet.jku.at/Projects/Rotor/2.0b/HowTo.html.
Given the description, this is close to what I've been looking for; however,
the C# link says "Coming Soon", and all releated links seem long dead. Do
you have an alternate, active link or a copy of this grammar?
Some other links you might find useful:
http://www.antlr.org/grammar/list
http://www.ssw.uni-linz.ac.at/Research/Projects/Coco/
These are a little harder to follow in general (unless you happen to be
antlr or coco), but are a great resourse to go to when there's a specific
issue with a definition.

It looks like multiple documents will need to be harvested, but that I
should be able to get 'er done...

thanks,
m
>

"MBR" <no***@nospam.comha scritto nel messaggio
news:45***********************@free.teranews.com.. .
>Hello... I'm using the grammar at:
http://msdn.microsoft.com/library/de...harpspec_c.asp
as a reference in creating my own C# parser using a custom framework.
(Please let me know if there's a better group to post in.)

Some questions:
(1) Is this grammar specification known to be complete and correct?
(2) Is there a normalized LL grammar available already suited for
(backtracking) recursive decent systems?
(3) Much of the grammar can be simplified by using EBNF-style
specifications -- it would be nice to find one this way already
(5) Is there a "parameterized" version that allows for c# 2.0 and c# 3.0,
with and without managed extensions?
(6) Are there alternate sources? (I've found some incomplete grammars and
some that are already re-purposed to the point of being unreadable.)

(7) There are simple and some not so simple left-recursions in the
grammar.

The simple, direct recursions can be changed to EBNF-style repetitions
without left recursion:

multiplicative-expression:
unary-expression
multiplicative-expression * unary-expression
multiplicative-expression / unary-expression
multiplicative-expression % unary-expression

becomes (I think):

multiplicative_expression ::=
(unary_expression, "*" )* , unary_expression |
(unary_expression, "/" )* , unary_expression |
(unary_expression, "%" )* , unary_expression.

But there are also some very deep recursions such as this one (of many
that can be detected):

type -->
| reference_type -->
| | array_type -->
| | | non_array_type -->
< < < < type <-- Recursive
x`
I'm wondering if this is necessary or even correct. Unlike the direct
recursions, in some of these cases it's hard to tell what's "meant"
making re-writes difficult.

Any pointers/advice appreciated...
thanks,
mike

--
Posted via a free Usenet account from http://www.teranews.com



--
Posted via a free Usenet account from http://www.teranews.com

Mar 9 '07 #7
There are a few nice things you can make from a C# parser.
Like static analysis tools, executing C# files as script (C#.Script),
automated testing etc.
And a new parser from which to test out new ideas. It was in writing a C#
compiler that I was able to extend the compiler to provide new keywords that
drastically later the compiled binary... the keywords "parallel" for
executing another function or code block concurrently (automatically
providing the appropriate syncronizations, if any, and even able to
determine when to use an interlockedincrement or a reader-writer lock,
etc.), an "async" keyword for executing a function as an asyncronous
delegate instead, and a "distributed" keyword for executing the function on
another machine in parallel as a grid cluster. The "inline" keyword for
better allowing me to express that I want the contents of a function to be
inlined instead (I have a need).

I was able to provide a special extensibility point in my compiler to allow
me to extend its optimizer and language features with plugins. Using this,
I'm experimenting with DSL extensions to get LINQ like capabilities (C# 3.0
features) and other types of things so I can mix logic in ala ProLog, among
other things. Purely academic on my part, but very fascinating.

My C# parser is not the complete spec and I'm hardly a compiler guru, in
fact, my code probly stinks, but it does allow me to experiment with ideas.

Anyway, there are many reasons why one would want to write a new C# parser
or have a comlete grammer.

In my case, it was just so I can test out some ideas, though I'd like to use
it in production code some day, I do have internal utilities developed using
it but nothing production ready.
Thanks,
Shawn
Mar 10 '07 #8
Would you ask the same question of the Mono team? Just as an example of
why someone might want to do it...
Well, actually I would. In my individual and perhaps extreme minority
opinion, Mono is and always will be lame. It'll always be at least one step
behind where MS is taking DotNet, usually more, no matter how energetic and
dedicated the implementors are. I have no doubt that Miguel de Acaza is a
real smart guy (is he still involved?), and I further have no doubt that the
contributors have been enjoying the challenges of reverse-engineering all
MS's DotNet stuff and have probably learned a lot about compilers and
runtime library development and so forth.

But still. How depressing it would become in the long run, to be constantly
reacting to what someone else does, instead of building something new.You
know, DotNet was in the labs at MS for years before it ever saw the light of
day, and they've got an enormous budget for that sort of stuff. I don't know
for sure, and I'm not so interested in it as to try to follow the Mono
blogs, but I'd bet that there's a lot of burnout in the people who are doing
this.

So yeah. I would ask the same question of the Mono team.

Tom Dacon
Dacon Software Consulting
Mar 10 '07 #9

"Shawn B." <le****@html.comwrote in message
news:um**************@TK2MSFTNGP06.phx.gbl...
I was able to provide a special extensibility point in my compiler to
allow me to extend its optimizer and language features with plugins.
Using this, I'm experimenting with DSL extensions to get LINQ like
capabilities (C# 3.0 features) and other types of things so I can mix
logic in ala ProLog, among other things. Purely academic on my part, but
very fascinating.
OK. This is some cool stuff. I'm a believer.

Tom

Mar 10 '07 #10
Tom Dacon <td****@community.nospamwrote:
Would you ask the same question of the Mono team? Just as an example of
why someone might want to do it...

Well, actually I would. In my individual and perhaps extreme minority
opinion, Mono is and always will be lame. It'll always be at least one step
behind where MS is taking DotNet, usually more, no matter how energetic and
dedicated the implementors are.
Well, Mono had a release with generics in before MS had actually
released .NET 2.0, I believe...
I have no doubt that Miguel de Acaza is a
real smart guy (is he still involved?), and I further have no doubt that the
contributors have been enjoying the challenges of reverse-engineering all
MS's DotNet stuff and have probably learned a lot about compilers and
runtime library development and so forth.
They've also provided a useful platform for easier development on
Linux. That's not exactly an inconsiderable achievement.
But still. How depressing it would become in the long run, to be constantly
reacting to what someone else does, instead of building something new.You
know, DotNet was in the labs at MS for years before it ever saw the light of
day, and they've got an enormous budget for that sort of stuff. I don't know
for sure, and I'm not so interested in it as to try to follow the Mono
blogs, but I'd bet that there's a lot of burnout in the people who are doing
this.
There's more to Mono than just the stuff that MS does. GTK# is one
example, for instance.

I don't see anything useless about the Mono project though, when it
comes to aiding Linux development.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 11 '07 #11

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

Similar topics

5
by: Peri | last post by:
I'm trying to create Python parser/interpreter using ANTLR. Reading grammar from language refference I found: or_expr::= xor_expr | or_expr "|" xor_expr For me it looks like infinite recursion....
1
by: Karalius, Joseph | last post by:
Can anyone explain what is happening here? I haven't found any useful info on Google yet. Thanks in advance. mmagnet:/home/jkaralius/src/zopeplone/Python-2.3.5 # make gcc -pthread -c...
0
by: Bengt Richter | last post by:
We have where syntax in combination with suite expression syntax (bear with me, I think a good synergy will emerge ;-) ...
0
by: Chad Whitacre | last post by:
Hey all, I've been playing around with the parser module, and based on the documentation I would expect all symbols in a parse tree to be part of the grammar. For example, I find this line in...
2
by: Peter Rilling | last post by:
I am written a program that will be used to parse the lexical syntax of code files. I would like to generalize the grammar logic so that I don't hardcode any specific grammar in my program. ...
4
by: ben | last post by:
getting a bit confused with the details of how c's grammar is specified, especially when you get self-reference like in this: postfix-expression: primary-expression postfix-expression ...
3
by: junky_fellow | last post by:
I got one link to the ANSI C Grammar http://www.lysator.liu.se/c/ANSI-C-grammar-y.html However, I don't know how to understand this grammar. I am not a Computer Science Guy. Can anybody please...
14
by: Magius | last post by:
Hello, I have a question about the correctness of the language grammar for the C# 2.0 specification. I am working with the grammar specified in the June 2005 ECMA-334 standard. Basically, a...
2
by: Bhupesh Naik | last post by:
This is a query regarding my problem to make a spell and grammar check possible in text area of a web page. We have aspx pages which are used to construct letters. The browser based screens...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.