[antlr-interest] Newbe bug: Why are these two code snippets not equivalent?

Gokulakannan Somasundaram gokul007 at gmail.com
Thu Jul 28 12:17:45 PDT 2011


I don't know for sure. Someone knowledgeable can correct me. ANTLR lexer
doesn't work correct, when you have the Semantic predicates at the
beginning. If you have it after your first token, then it might give the
required behavior.

But i follow one of the advices given to me.

a) don't have too much functionality in the lexer. Make it as simple as
possible. If you want the conditions to be considered, use it in the action
clause and change the $type of the token.

Nevertheless, i find the lexer working right even with semantic predicates
when you have k=1 setup. But unless your grammar is naturally k=1, you have
to write the semantic predicates to cover all the cases by yourself. When
you have a semantic predicate, you kind of bypass the grammar check.

Thanks.

On Fri, Jul 29, 2011 at 1:41 AM, Chris King <kingces95 at gmail.com> wrote:

> Yes that is intentional. But let's disregard that rule for a second. Should
> the introduction of that second rule under any circumstance change the
> behavior of that parser seeing as it doesnt match anything? I'm showing that
> it does and can't figure out why it would given that the predicate is always
> false. Is that a bug?
>
> Thanks,
> Chris
>
> On Jul 28, 2011, at 4:00 AM, Gokulakannan Somasundaram <gokul007 at gmail.com>
> wrote:
>
> The first rule matches empty and the second rule doesn't match anything. Is
> that "//" intentional?
>
> Gokul.
>
> On Thu, Jul 28, 2011 at 4:28 PM, chris king < <kingces95 at gmail.com>
> kingces95 at gmail.com> wrote:
>
>> Hello antlr-interest! So I'm working on my C# pre-processor and I'm trying
>> to implement the skipping #ifdefed code in the lexer when I ran across
>> this.
>> I expected
>>
>>
>> PP_SKIPPED_CHARACTERS
>>  : //{ false }? ( ~(F_NEW_LINE_CHARACTER | '#') F_INPUT_CHARACTER*
>> F_NEW_LINE )*
>>  ;
>>
>>
>> to be equivalent to
>>
>>
>> PP_SKIPPED_CHARACTERS
>>  : { false }? ( ~(F_NEW_LINE_CHARACTER | '#') F_INPUT_CHARACTER*
>> F_NEW_LINE
>> )*
>>  ;
>>
>> but I'm seeing different runtime behavior. So I guess I don't understand
>> what the { false }? syntax is all about. I know there are probably other
>> ways to implement the #ifdefed logic but could someone enlighten me as to
>> why these two bits of code are not equivalent?
>>
>> Thanks,
>> Chris
>>
>> List: <http://www.antlr.org/mailman/listinfo/antlr-interest>
>> http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe:
>> <http://www.antlr.org/mailman/options/antlr-interest/your-email-address>
>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>
>
>


More information about the antlr-interest mailing list