Like Tree1Likes
  • 1 Post By TheBigH

Beginner: Help me compile this program

This is a discussion on Beginner: Help me compile this program within the C Programming forums, part of the General Programming Boards category; Hello, I'm new to C programming, I came across a question asking to a compile a program, I dont know ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    3

    Red face Beginner: Help me compile this program

    Hello, I'm new to C programming, I came across a question asking to a compile a program, I dont know how to go about doing it, if anyone can write the code so I can learn from it, would be greatly appreciated.

    Here's how it goes:

    Build a simplistic C compiler (Filename: assign1.c)

    The program will perform "one pass" of a C-source file (.c) and produce a listing file (.list). A "pass" is the sequential reading of the C-source file, one line at a time, from top to bottom. Each line read from the C-source file will be written in sequence to the listing file, prepended by the line number and colon.

    Example: 1: #include <stdio.h>
    2: int main(int argc, char *argv[])

    At the bottom of the listing file, the program will write the following data concerning the "compiled" C-source file:
    • The total number of lines in the C-source file
    • The total number of occurrences of each of the following reserved words ( "int", "float", "double", "for", "while", "if")
      • Requirement: Your method for checking all reserved words must be extensible; i.e. we should easily be able to add more words without major changes in your code.
      • Bonus: The occurrences must not occur within comments.
      • Bonus: Recognize and act upon #include
    Finally, the program will write any/all "compiler errors". In our simplistic version of a compiler, the only error you are responsible for finding is the number of unmatched curly brackets.

    As input, the program requires the name of the C-source file and the desired name of the output listing file. These two input variables are to be provided by the command-line arguments.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,310
    Start by implementing the "total number of lines in the C-source file" feature.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    Actually, start by reading our homework policy. We help people find and fix problems in code they've written, we don't do their homework for them.
    Salem likes this.
    Code:
    while(!asleep) {
       sheep++;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help beginner with program please
    By bubbles56 in forum C Programming
    Replies: 1
    Last Post: 03-23-2011, 10:37 PM
  2. Beginner C++ Help. My very first program.
    By Jechob in forum C++ Programming
    Replies: 2
    Last Post: 10-10-2010, 01:34 PM
  3. beginner c++ programmer compile errors
    By dodo10 in forum C++ Programming
    Replies: 4
    Last Post: 05-28-2008, 04:37 PM
  4. beginner attempting to compile hello world. having problems
    By MegaManZZ in forum C++ Programming
    Replies: 13
    Last Post: 12-03-2007, 03:21 PM
  5. compile error (beginner)
    By eth0 in forum C++ Programming
    Replies: 11
    Last Post: 12-30-2003, 01:15 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21