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

Richard Gildea rgildea at gmail.com
Mon Oct 15 17:28:08 PDT 2012


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