Question 1
In a compiler, the phase that converts a stream of characters into a stream of meaningful tokens is called:
Lexical analysis (scanner) reads the source program character by character and groups them into logical tokens. [GATE 1989]
In a compiler, the phase that converts a stream of characters into a stream of meaningful tokens is called:
Lexical analysis (scanner) reads the source program character by character and groups them into logical tokens. [GATE 1989]
Consider the C code statement: printf("i = %d, &i = %x", i, &i); How many tokens are present in this statement?
Tokens are: 1: 'printf', 2: '(', 3: '"i = %d, &i = %x"', 4: ',', 5: 'i', 6: ',', 7: '&', 8: 'i', 9: ')', 10: ';'. Total = 10 tokens.
In a C compiler, which phase handles preprocessor directives such as #define and #include?
Preprocessor directives (#define, #include) are processed by the preprocessor before the actual compiler phases begin.
Which formal language model can recognize the regular languages typically used to specify lexical token patterns?
Lexical token patterns are typically specified using regular expressions, which define regular languages recognized by finite automata such as DFAs. A DFA is sufficient, though an NFA can also recognize the same regular languages.
Which compiler phase detects type mismatch errors, such as assigning a float value to a pointer variable without casting?
Type checking, type consistency, and scope resolution are performed during semantic analysis.