Hi Susan,
> The problem occurs when the correct braille output depends on context. Most isolated braille letters represent entire print words. For example, the braille letter "b" represents the word "but" when isolated but just the letter "b" itself in the word "butter" and other words containing that sequence.
This is a semantic problem and hence cannot be decided by ANTLR4 (which does syntactic processing). You will first have to parse the input as is and after that, in your semantic phase, determine what it *means* (and act accordingly). It will cause more grief if you offload your semantic processing to the parsing step, than what you solve by that.
>
> However, when I use "BUT: 'but';" as a lexer token, the lexer identifies every 'but' sequence in the input as a BUT token so I have to include that token in grammar phrases for longer words.
That’s exactly as it should be. One input sequence is mapped to a single lexer token. The input as such doesn’t know about the semantic you apply to a specific symbol.
> I could use different phrase names to tell the iisolated and longer word contexts apart and then use the phrase name to signal which hash table has the appropriate translation, e.g. 'b' or 'but'. But I'm wondering if there is a better solution.
How can that help? In both cases your input is a 'b' and lexed as such. What you have to adjust is your semantic processing of the input. Compare the incoming token with the surroundings to know what it is about. Note: since you didn’t mention that, I assume you don’t have a keyword that parse 'but‘ in addition to the isolated 'b‘ letter.
Mike
--
www.soft-gems.net