(a) The parts of the compiler that would be needed to implement this functionality are:
(i) Lexical Analyzer: It reads and converts the program into tokens. It converts a lexeme stream into a stream of tokens. Tokens are defined by regular expressions understandable by the lexical analyzer. Lexical analyzer is also responsible for removing white-spaces and comments. Since, the autocomplete suggestions will be based on tokens preceding to the predicting test word, token generation i.e. the functionality of this phase is essential.
(ii) Parser( Syntax and Semantics analyzer): Parser constructs the parse tree. It takes all the tokens sequentially and construct the parse tree by using Context free grammar. The automation to represent the path for which predictable test word is generated here using parse tree, a parse Stack is also required to maintain the path to each automation transition. The automation can change state through epsilon transitions or null moves or when a certain token is received.
(b) Method calls are associated with object instances in an essential way, so the analysis phase can be changed by storing relevant function names in the lexical analyzer phase. The parse tree formation in syntax and semantics analysis need to be modified in order to accommodate method calls. In the middle-end, optimization of autocomplete suggestions can be performed by using data structures like tree.
Hope this helps.
1. Modern integrated development environments (IDEs) "automatic code completion" comple- tion, gives the progra...