[antlr-interest] Changing/affecting the Lexer from the Parser?

Bernard Kaiflin bkaiflin.ruby at gmail.com
Fri Nov 9 15:53:51 PST 2012


Hi,
Which grammar are you following ?

I have fond this one :
http://documentation.softwareag.com/natural/nat627unx/pg/pg_defi_array.htm#prelim_info

which doesn't talk about "based" array indexing.

Is it possible to affect the lexer with variables in the rules that parse
> the indexing?

  There are the semantic predicates : RULE : ... {boolean expression}?

> Or does the lexer tokenize all the input before the parser starts?


 No, the lexer answers to nextToken() requests from the parser. Starting at
the character position behind the last token consumed, it chooses the rule
that matches the most input characters. If the input can match two rules, ANTLR
resolves this lexical ambiguity by matching the input string to the rule
specified first in the grammar.

The fact that the lexer follows only the lexer RULES can give the feeling
that it does not "obey" to your parser rules as you might imagine :)

HTH
Bernard


2012/11/7 Juancarlo Añez <apalala at gmail.com>

> In the Natural programming language it is possible to have "based" array
> indexing. With a declaration like this:
>
> 2 ARR(1:5)
>
> Array indexes must be of the form:
>
>    ARR(1.2:4)
>
> Alas, 1.2 is a floating point number everywhere else!
>
> Other possibilities are ARR(1.#I:#J), ARR(#I.2:4), in which .2 is a valid
> floating point number, but 1. isn't.
>
> Is it possible to affect the lexer with variables in the rules that parse
> the indexing? Or does the lexer tokenize all the input before the parser
> starts?
>
> TIA!
>
> --
> Juancarlo *Añez*
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


More information about the antlr-interest mailing list