[antlr-interest] How to use lexer getCharPositionInLine() function in Cpp target

Richard Gildea rgildea at gmail.com
Tue Oct 16 14:56:30 PDT 2012


Hi Gokul,

This does not work either, as I now get the following compiler error in the
generated lexer rule functions:

error: use of undeclared identifier 'm_ctx'

Cheers,

Richard

On 15 October 2012 17:56, Gokulakannan Somasundaram <gokul007 at gmail.com>wrote:

> You don't need to write it inside the Cpp file. Just write it in the
> grammar.
>
> Gokul.
>
>
> On Tue, Oct 16, 2012 at 8:56 AM, Gokulakannan Somasundaram <
> gokul007 at gmail.com> wrote:
>
>> Yeah. That looks like a bug. I will need to change the stg file. For now,
>> you can directly write m_ctx->getCharPositionInLine() in place of getCharPositionInLine()
>> and let me know, whether it works.
>>
>> Thanks,
>> Gokul.
>>
>> On Tue, Oct 16, 2012 at 8:28 AM, Richard Gildea <rgildea at gmail.com>wrote:
>>
>>> Hi Gokul,
>>>
>>> The problem is that the predicate also appears in one of the generated
>>> TLexerCyclicDFA functions, leading to the following compilation error:
>>>
>>> error: no member named 'getCharPositionInLine' in 'cifLexerCyclicDFA33'
>>>                             if ( (( this->getCharPositionInLine() > 0 ))
>>> )
>>>                                     ~~~~  ^
>>>
>>> Manually editing the generated code to read ctx->getCharPositionInLine()
>>> fixes the compilation.
>>>
>>> Cheers,
>>>
>>> Richard
>>>
>>>
>>> On 15 October 2012 17:13, Gokulakannan Somasundaram <gokul007 at gmail.com>wrote:
>>>
>>>> getCharPositionInLine() function is present inside Lexer. You can just
>>>> call it as similar to Java.
>>>> just replace the MACRO GETCHARPOSITIONINLINE() with
>>>> this->getCharPositionInLine() ?
>>>>
>>>> I can't understand second part of your question.
>>>>
>>>> Thanks,
>>>> Gokul.
>>>>
>>>>
>>>> On Tue, Oct 16, 2012 at 2:43 AM, Richard Gildea <rgildea at gmail.com>wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> I am attempting to convert my parser to use the Cpp target after
>>>>> previously
>>>>> using the C target for some time, and have come across a problem
>>>>> trying to
>>>>> call the function TLexer::getCharPositionInLine() inside a gated
>>>>> semantic
>>>>> predicate in one of my lexer rules. With the C target I was using a
>>>>> construct such as
>>>>>
>>>>> ({ GETCHARPOSITIONINLINE() > 0 }?=> ';')
>>>>>
>>>>> to identify a semicolon character in the first column of a line. When
>>>>> trying to use a similar construct with the Cpp target, in the generated
>>>>> code this predicate is used both inside the lexer rule, where the
>>>>> correct
>>>>> usage would be this->getCharPositionInLine(), and inside a cyclicDFA,
>>>>> where
>>>>> the usage would be ctx->getCharPositionInLine(). Is there a way to use
>>>>> such
>>>>> a predicate with the Cpp target?
>>>>>
>>>>> Cheers,
>>>>>
>>>>> Richard
>>>>>
>>>>> 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