Mo H. Mo H. - 5 months ago 14
Java Question

Lexical Analysis for import and method calls in java

How are

import
statements and method calls tokenized in java's lexical analysis. For example:

import java.util.Scanner


is this seen as
import
,
java
,
util
,
Scanner
(4 tokens) or
import
,
java.util.Scanner
(2 tokens)

In the same line of thought, in:

Scanner input = new Scanner(System.in);
int x = input.nextInt();


is
input.nextInt()
seen as
input
,
nextInt()
(2 tokens) or
input.nextInt()
(1 token)

Answer

The statement import java.util.Scanner; is seen as follows: import, java, ., util, ., Scanner, ;

In the same line of thought input.nextInt(); is seen as: input, ., nextInt, (, ), ;