can someone tell me why this isnt working?
a little bit of background to help. i am making a sort of language thats interpreted, not compiled down to source;
here is my if statement in main to see if thats the line:
im really new to pointers. i have tried to stay away from them but i need them i think to implement goto. if i post the whole source will you correct it for me?
bool stdFile(const string &file)
{
if (constchar* p = strrchr(file.c_str(), '.')) // find last dot
{
return strcmp(p, ".src") == 0;
}
returnfalse;
}
As for parsing your code, I think you need a tokenizer. Stroustrup has an example of a calculator in all editions of his definitive book, The C++ Programming Language. It uses a recursive decent parser to evaluate the input. I suggest you stop coding and take a look at it before you go any further.
I pass the string in by const ref so there's no run-time cost in passing it.
I use strrchr to look for the last dot in the string. If it's found, I compare the string at that location with ".src". If the strings match, I return true. Otherwise I return false.
so i realized at work that i havent written a single line of code in the product so far. i have decided to scrap this for now and continue it once i have read the c++ programming language by bajarne stroustrop and have learned more. im sorry to waste your time and i appreciate your help
The goto is implemented by moving the read position of the input stream.
When a label is read, it makes a note of where it read it, the label name and the position in the stream (the streamoff). It stores these in a map<name, position>. Line 10 declares that map type, line 16 declares the variable of that type, and line 50 adds an entry to it.
When it sees a goto, it checks the labels seen so far. If it's not there, it reads forward until it finds it. When it finds it, it moves the streams' read position with seekg() to that position.
I'd suggest not to scrap this project. A book is one more source to find the required informations, but not a panacea.
If you want I'd show you a simplified version later