Hi msrt92,
Everyone jumped on the errors. I believe there is something more fundamentally lacking in your programming. The first thing we need to do is chat a second. I see you have the concepts of functions, prototypes, and variables. Good... That's a great thing. You are to be commended on that point. You are well on your way.
Now I want to introduce you to the concept of programming. Something you should have been taught before you ever learned the first command. The key to programming is organization. The more organized you are, the easier you can write your code. The second thing is to agree on a protocol. A protocol, is simply a method... Strings, string functions, global variables (a very bad idea) starting anew... Yes, starting anew is a protocol. Sometimes the best of us say "Ah screw it, and we start over." It doesn't mean you suck, it doesn't mean you've failed. It simply means you have eliminated a process that doesn't work. You've learned what doesn't work, and now you can try something else. Sometimes it's simply the best move. Every programmer here has done it on more than one occasion. I need to honestly say this is the best protocol for you at this time, but it's okay, we're here with you.
Before you begin what I loving refer to as "Hack and slash" coding, You've got to have a plan.
You can't just jump in and start programming, or you'll miss things. Missed things = failed code. Let's make a list of everything this program need in a simplistic form
This program needs an array of type string.
This program needs prototypes.
This program needs to pass the array to every function by reference.
This program needs functions to search, and compare elements to find a match.
This program needs to do this.
This program needs to do that.
Okay... now you are organized.
Step #2 How will we accomplish these goals ?
1. Start with what you KNOW (not think) will work. Test it, test it again, then move on to the next goal.
1 2 3 4 5 6 7 8 9
|
#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
int main(){
string LookAhead[6] = { "int", "id" , "[" , "num" , "]" , ";" } ;
}
|
Great, we have an array of strings declared and defined. Okay, that's done.
Now on to the next goal.
We need to write a function.
1 2 3 4 5 6 7 8 9 10 11 12
|
void type ()
{
if (LookAhead[counter]=="int" || (LookAhead[counter]=="char")
{
dt();
match("id");
match("[");
match("num");
match("]");
match(";");
}
}
|
Okay so here we have 5 problems.
1st, count is a keyword, so we need to change this, Let's use 'counter' instead.
2nd, You were calling the functions with chars... eg 'int' and not strings eg "int".
3rd, We don't know the value of counter.
4th, char is not in the string we are comparing to, so it will never match
5th. We need to pass the array into the function by reference...
The first two problems I took care of... How do you suggest we fix the other 3 ?