.NET Grammar modification

J

Jon Slaughter

I'm curious as to if .NET provides any direct means to modifying its own
grammar? e.g., if say I want to had some "features" to C# which can easily
be reinterpreted back into the original C# but I do not want to have to
write a full blow parser just to change some simple thing.

Lets suppose want to add a "macro" that on the surface adds the keyword
"property" which in reality is just a shorthand for the standard properties
in C#. I know VS has abilities to do macro's but they are more like "code
inserts" than preprocessing. I want something that is transparent in that it
acts like an extended version of C# but translates directly into it(through
preprocessing).

I know many will say that one shouldn't do this but thats not the point. I
don't want to hack together a quick brute force parser to do some small
conversions but I also don't want to have to implement a full blown parser
to handle a few modifications I want to do.


To be more clear, what I want is some way to preprocess C# files in a
grammatically compatible way to add some small isomorphic features to C#.
The method will simply generate a cs file that will be treated in the normal
way. (Although there is the problem of error handling but its not that big a
deal at this point)

Thanks,
Jon
 
R

Rad [Visual C# MVP]

Hey Jon

The guys behind the Boo language did just that, and for exactly the
same reasons.

check out http://boo.codehaus.org

You might want to browse their documentation and code to see how to do
it.
 
L

Lucian Wischik

Jon Slaughter said:
I'm curious as to if .NET provides any direct means to modifying its own
grammar? e.g., if say I want to had some "features" to C# which can easily
be reinterpreted back into the original C# but I do not want to have to
write a full blow parser just to change some simple thing.

Do you really want to program in C#? I mean, C++/CLI would also be a
".net grammar modification" as per your subject line, and it loves the
kind of thing you're describing, and it interops great with C#.
(sorry, this is an off-topic answer for the csharp newsgroup...)
 
D

defcon8

I'm curious as to if .NET provides any direct means to modifying its own
grammar? e.g., if say I want to had some "features" to C# which can easily
be reinterpreted back into the original C# but I do not want to have to
write a full blow parser just to change some simple thing.

Lets suppose want to add a "macro" that on the surface adds the keyword
"property" which in reality is just a shorthand for the standard properties
in C#. I know VS has abilities to do macro's but they are more like "code
inserts" than preprocessing. I want something that is transparent in that it
acts like an extended version of C# but translates directly into it(through
preprocessing).

I know many will say that one shouldn't do this but thats not the point. I
don't want to hack together a quick brute force parser to do some small
conversions but I also don't want to have to implement a full blown parser
to handle a few modifications I want to do.

To be more clear, what I want is some way to preprocess C# files in a
grammatically compatible way to add some small isomorphic features to C#.
The method will simply generate a cs file that will be treated in the normal
way. (Although there is the problem of error handling but its not that big a
deal at this point)

Thanks,
Jon

It's called syntax and common lisp is known for the possibility of
modification and even writing itself.
 
J

Jon Slaughter

Jesse McGrew said:

This seems to be almost exactly what I want except that I'm not sure how
much it is like C#. I want something that is an extension of C# and not
something that overlaps. I'll look into it and see. Maybe they can be used
side by side and interoped transparently. If it does 99% of C# then I'll be
happy.

Thanks,
Jon
 
B

Bruce Wood

Jon said:
I'm curious as to if .NET provides any direct means to modifying its own
grammar? e.g., if say I want to had some "features" to C# which can easily
be reinterpreted back into the original C# but I do not want to have to
write a full blow parser just to change some simple thing.

Lets suppose want to add a "macro" that on the surface adds the keyword
"property" which in reality is just a shorthand for the standard properties
in C#. I know VS has abilities to do macro's but they are more like "code
inserts" than preprocessing. I want something that is transparent in that it
acts like an extended version of C# but translates directly into it(through
preprocessing).

I know many will say that one shouldn't do this but thats not the point. I
don't want to hack together a quick brute force parser to do some small
conversions but I also don't want to have to implement a full blown parser
to handle a few modifications I want to do.


To be more clear, what I want is some way to preprocess C# files in a
grammatically compatible way to add some small isomorphic features to C#.
The method will simply generate a cs file that will be treated in the normal
way. (Although there is the problem of error handling but its not that big a
deal at this point)

The short answer is that no, there is no way in C#.

The preprocessor was an often-abused feature of C and is also a feature
of C++. So far as I know it was intentionally omitted from C# because
of the potential for abuse.
 
J

Jon Harrop

Jon said:
This seems to be almost exactly what I want except that I'm not sure how
much it is like C#. I want something that is an extension of C# and not
something that overlaps. I'll look into it and see. Maybe they can be used
side by side and interoped transparently. If it does 99% of C# then I'll
be happy.

Given that you have a common-language run-time, there seems to be little
point in having an extension of C# rather than something that overlaps.

You might also like F#...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top