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.