Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C Compiler Using C#3.0

C Compiler Using C#3.0

Scheduled Pinned Locked Moved C#
csharpquestion
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Niungareamit
    wrote on last edited by
    #1

    Hi.......... I want to develop a C Compiler using C#3.0 So is it possible??? How should i go for this????

    realJSOPR OriginalGriffO 2 Replies Last reply
    0
    • N Niungareamit

      Hi.......... I want to develop a C Compiler using C#3.0 So is it possible??? How should i go for this????

      realJSOPR Offline
      realJSOPR Offline
      realJSOP
      wrote on last edited by
      #2

      Take a class on writing compilers. I assume they still teach this in computer science courses...

      .45 ACP - because shooting twice is just silly
      -----
      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
      -----
      "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

      1 Reply Last reply
      0
      • N Niungareamit

        Hi.......... I want to develop a C Compiler using C#3.0 So is it possible??? How should i go for this????

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        Writing a C compiler is not a simple piece of work: it can be done in C#, and the actual lexical / parser / code generator design is well established. But what it won't let you do is run a program - to do that, you will need a library of back up stuff: Add, subtrcat, multiply, divide, write a character, etc., etc. It's a big job, probably a couple of man-years, but if you want to try, give google a shot with "how do I write a c compiler" and you will get thousands of hits!

        If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        N 1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          Writing a C compiler is not a simple piece of work: it can be done in C#, and the actual lexical / parser / code generator design is well established. But what it won't let you do is run a program - to do that, you will need a library of back up stuff: Add, subtrcat, multiply, divide, write a character, etc., etc. It's a big job, probably a couple of man-years, but if you want to try, give google a shot with "how do I write a c compiler" and you will get thousands of hits!

          If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.

          N Offline
          N Offline
          Niungareamit
          wrote on last edited by
          #4

          Thanks for ur reply...But i m not getting what u r trying to tell me...can u please elaborate what u r trying to say? Thank You

          OriginalGriffO 1 Reply Last reply
          0
          • N Niungareamit

            Thanks for ur reply...But i m not getting what u r trying to tell me...can u please elaborate what u r trying to say? Thank You

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #5

            Writing a C compiler is not a simple piece of work. You also need to write a large amount of background functions that the application written in C and compiled by your compiler need to work. For example, at the most basic, you must provide a function to write a character on a screen. Then to write a string. Then to cope with all the parameters of the "printf" function. And to add two ints. And to add two floats. and to subtract two ints. etc. Actually parsing the input is relatively simple, as is code generation, but I think you will have a lot to do to get a C program to run as output by your compiler. Google can help you if you do decide to do it: try to search for "How do I write a C compiler" and it will give you a lot of information.

            If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            M 1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              Writing a C compiler is not a simple piece of work. You also need to write a large amount of background functions that the application written in C and compiled by your compiler need to work. For example, at the most basic, you must provide a function to write a character on a screen. Then to write a string. Then to cope with all the parameters of the "printf" function. And to add two ints. And to add two floats. and to subtract two ints. etc. Actually parsing the input is relatively simple, as is code generation, but I think you will have a lot to do to get a C program to run as output by your compiler. Google can help you if you do decide to do it: try to search for "How do I write a C compiler" and it will give you a lot of information.

              If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.

              M Offline
              M Offline
              moon_stick
              wrote on last edited by
              #6

              I guess an easier route would actually be to create an intermediate compiler which creates IL (which is effectively what MS did). I would imagine that converting the parsed code into machine code would be something of an arduous task but creating IL would appear to be a translation between languages - parse the input code, create a parse tree, manipulate this tree so you have a syntax tree and then perform a similar process in reverse to generate the IL. By concentrating on a limited set of primitive types and operands you could probably get something basic up and running within a few days.

              Sarchasm : The gulf between the author of sarcastic wit and the person who doesn't get it.

              OriginalGriffO 1 Reply Last reply
              0
              • M moon_stick

                I guess an easier route would actually be to create an intermediate compiler which creates IL (which is effectively what MS did). I would imagine that converting the parsed code into machine code would be something of an arduous task but creating IL would appear to be a translation between languages - parse the input code, create a parse tree, manipulate this tree so you have a syntax tree and then perform a similar process in reverse to generate the IL. By concentrating on a limited set of primitive types and operands you could probably get something basic up and running within a few days.

                Sarchasm : The gulf between the author of sarcastic wit and the person who doesn't get it.

                OriginalGriffO Offline
                OriginalGriffO Offline
                OriginalGriff
                wrote on last edited by
                #7

                That certainly gets rid of a lot of work. The next problem: how do you use .NET classes with an non-OOP language like C? :-D

                If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.

                "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                M N 2 Replies Last reply
                0
                • OriginalGriffO OriginalGriff

                  That certainly gets rid of a lot of work. The next problem: how do you use .NET classes with an non-OOP language like C? :-D

                  If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.

                  M Offline
                  M Offline
                  moon_stick
                  wrote on last edited by
                  #8

                  My bad - I read the question as 'I want to write a c# compiler'... My way was definitely easier! :)

                  Sarchasm : The gulf between the author of sarcastic wit and the person who doesn't get it.

                  1 Reply Last reply
                  0
                  • OriginalGriffO OriginalGriff

                    That certainly gets rid of a lot of work. The next problem: how do you use .NET classes with an non-OOP language like C? :-D

                    If Barbie is so popular, why do you have to buy her friends? Eagles may soar, but weasels don't get sucked into jet engines. If at first you don't succeed, destroy all evidence that you tried.

                    N Offline
                    N Offline
                    N a v a n e e t h
                    wrote on last edited by
                    #9

                    OriginalGriff wrote:

                    The next problem: how do you use .NET classes with an non-OOP language like C?

                    That won't be a problem. How F# is using .NET framework classes? How C++/CLI supports non-OO programing? But it's more work for compiler writers. :)

                    Best wishes, Navaneeth

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups