Segmentation Fault.

Last edited on
stNodeType_list is never set to any size.

There are serious style problems in this code. In the same program you're mixing:
* C headers.
* C++ headers.
* UNIX headers (for no easily discernible reason).
* C++ types.
* C-style I/O.
* C-style memory allocation.
* C-style struct declarations.
* (Presumably) C-strings when <string> is being included.
* Global data pretending to be OOP objects.
* Global functions pretending to be methods.
This code is in need of heavy refactoring.
Last edited on
Long story short, I need to code a recursive descent parser with a symbol table.

Unless written very carefully, this kind of code can be a huge time sink to debug.
Personally, for production systems, I prefer to use:


which can generate C/C++ code and includes nifty tools to debug your grammar. If that is not an option and you have to maintain/fix this code, then I would:

2. throw valgrind at it:
3. write a ton of test cases, starting from very simple cases

I know you don't want to hear this, but if the code is ugly enough, it may be more time-efficient to rewrite the code.
I was under the assumption that vectors didn't need to be set to a size. I thought they "grew" with each element added. Anyways, I tried vector<stNodeType> stNodeType_list(20); but I get these errors:
main.cpp:279: error: expected identifier before numeric constant
main.cpp:279: error: expected `,' or `...' before numeric constant
main.cpp:279: error: ISO C++ forbids declaration of `parameter' with no type

SO I tried it using my struct: current_scope->stNodeType_list.resize(20); but I get these errors:
main.cpp:289: error: expected constructor, destructor, or type conversion before '->' token
main.cpp:289: error: expected `,' or `;' before '->' token

Which I'm not sure why I'm getting these errors
I thought they "grew" with each element added.
They do, but you have to actually add them in order for that to happen. Simply using operator[]() doesn't change the size.

The first set of errors is, IINM, because you tried to add the constructor parameter in the middle of the class declaration, which is illegal.
The second set is hard to tell. Did you put that code in the middle of global scope?
vector<stNodeType> stNodeType_list;
stNodeType_list.resize(int number);
// or stNodeType_list(20); 

stNodeType_list.push_back( element) ; will resize your vector to it's current size + 1
actually pushes an element to the next index

Vector<string> A;
Elements: 0.[ ''hi'' ] 1.[''ho'']



Elements : 0.["hi"] 1.["ho"] 2.["ha"]
Last edited on
Topic archived. No new replies allowed.