Is it possible to handle the same lexical token differently depending on context? The docs says there are [`Lexical Modes`](https://github.com/antlr/antlr4/blob/master/doc/lexer-rules.md#mode-pushmode-popmode-and-more) as a way to handle this, and was wondering if that approach could be used to handle this.

Here is an example. Given the following SQL statement:

```
select 1.2, 1.2e, .2, 1.e, tbl, tbl.select

```

Notice that the `SELECT` token at the beginning is a reserved keyword, but when the reserved token is preceded by a `.` it is part of a "path expression" and so is not a reserved keyword. What I want to do is -- ignoring numbers -- I want the first `select` to be captured as the `select` token and the second `select` to be captured as an `identifier`. Is this possible? Here is an example in antlr:

```
grammar DBParser;
options { caseInsensitive=true; }

statement:select_statement EOF;

select_statement
    : SELECT expr (COMMA expr)*
    ;

expr
    : NUMBER
    | IDENTIFIER
    ;

COMMA: ',';

// 1. Pick up numbers first (simplified number format for question)
NUMBER: [0-9]* '.' [0-9]* 'e'?;

// 2. Reserved Keyword section
SELECT: 'SELECT';

// 3. And if it's not a reserved keyword, pick it up as an identifier
IDENTIFIER: [A-Z_] [A-Z_0-9]*;

WHITESPACE: [ \t\r\n] -> skip;

```

And here is the parse tree, where everything is ok until the `select` after the dot. Is there a rule I can set so that I can properly parse the above at the lexing stage?

---

**Update**: A more complex example might be something like:

```
select ([{'select': 1}])[0].select;

```

Where dot access may be (and often is) after a parenthesized expression, array access, function call, etc.

[![enter image description here](https://i.stack.imgur.com/rbmil.png)](https://i.stack.imgur.com/rbmil.png)