Jump to content

Recommended Posts

Posted

For my homework assignment, which is due on Tuesday, I need to write a C program that takes the source code to another C program as input and returns as output the same C program with proper formatting. The specific C programs that will be fed into my program for the determination of my grade has been provided to me, as well as the expected output.

 

The programs are very simple and utilize a small subset of the C language. They feature the inclusion of the stdio.h, integer declarations and initializations done together, if statements (with blocks), while loops (with blocks), simple expressions, printf and return 0. An extra credit portion of the assignment includes for loops.

 

Since I did poorly on my previous assignment because the grader saw fit to define parts of the assignment that were left by my professor for students to define and also to redefine the grading standard as accepting signed (i.e. negative) values in places designated as having unsigned values, I decided to go above and beyond on this assignment and write a scanner to tokenize the input and then write a parser that would take the tokens and reassemble them into a neatly formatted C program, because my professor said that I would receive more extra credit for doing that.

 

I also want to write this program so that in the future, I can have my computer format code for me and at some point, I could use the scanner as part of a compiler I will write for my TI-84 Plus calculator so I will not have to learn BASIC to program for it.

 

I have a copy of the purple dragon book that I have been reading. I have read chapter 1, all of chapter 2 minus a few pages detailing parts of a compiler that I do not need to write right now, and most of chapter 3 (up to page 134). I want to finish my program by 10 pm EST today, so I decided to reallocate the 3 hours I have left from reading the dragon book to writing actual code.

 

I am contemplating the design of my scanner and I am wondering, should I put reserved words into the symbol table or create a separate reserved words table for them? In the token output, should I represent reserved words with where for if, I would have something like or , where for if, I would have . What about preprocessor definitions? Upon seeing #, should a good scanner put the entire line in the symbol table, or check to see what is there and in the case of include, put the contents of into the symbol table and then output ?

 

 

More...

 

View All Our Microsoft Related Feeds

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...