You shouldn't be calling parse upon seeing
callSomething() (I presume you meant
callSomething rather than
doSomething). The difference between
callSomething is that one is a method definition while the other is a method call.
When you see a new definition, you'll want to do checks related to ensuring you can add that definition, so:
- Check if function doesn't already exist with same signature
- Ensure that method declaration is being performed in the proper scope (i.e. can methods be declared inside other method declarations?)
Assuming these checks pass, you can add it to your map and begin checking the contents of that method.
When you find a method call like
callSomething(), you should perform the following checks:
callSomething exist in your map?
- Is it being called properly (number of arguments matches signature that you have found)?
- Are arguments valid (if variable names are used, are they declared? can they be accessed at this scope?)?
- Can callSomething be called from where you are (is it private, public, protected?)?
If you find that
callSomething() is okay, then at this point what you would want to do really depends on how you wish to approach it. Strictly speaking, once you know that such a call is okay at this point, you could only save the name of the method and the arguments without going into further details. When you run your program, you will invoke the method with the arguments you should have at runtime.
If you want to go further, you could save not just the string but a link to the actual method. This would be more efficient, but if you have to manage memory, it can get confusing. I would recommend you simply hold onto the string at first. Later you can try to optimize.
Note that this is all assuming that you've lexxed your program, which means you have recognized all tokens in your program and know what they are. That isn't to say you know if they make sense together yet, which is the parsing phase. If you don't yet know what the tokens are, I suggest you first focus on getting that information first.
I hope that helps! Welcome to Programmers SE!