Can someone please give me some tips / ideas on how to deal with situations where you need to look at further announcements in order to be able to do the right semantic actions at the moment? For example, this is a well-known phenomenon when someone writes an interpreter / compiler of some programming language that does not support “advanced declarations”. Take an example:
foo(123);
void foo(int i){
}
It is quite clear that we must have at least two passes. First, we analyze all the declarations of functions and get all the necessary information, such as: the quantity arguments that the function takes, their types, and then we deal with function calls and eliminating difficulties, as indicated above. If we go this way, we will have to make all these passes using some AST mechanisms / visitors. In this case, we must deal with the AST passing / using visitors, and we must say "goodbye" to all the beauty of the phoenix constructions embedded directly in our parsers.
How would you handle this?
source
share