JAVACC - Problems if coments lines

View: New views
4 Messages — Rating Filter:   Alert me  

JAVACC - Problems if coments lines

by Douglas Alves-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Good night.
First, sorry for my english.
I'm a student of Computer Scientist in Brazil.

I'm work in my monografy with JavaCC.

I'm having trouble writing a token that defines several lines of comments, as in C + +. I am using this definition:
< COMENTARIO_VARIAS_LINHAS: "/*"  (~[])*     "*/"  >

But in this case also includes (~[])* the end of the comment "*/", error occurs and the time to acknowledge the comments of several lines. If you have any suggestions, thank you now.
Regards,

 
Saudações,
          Douglas Alves

Re: JAVACC - Problems if coments lines

by J.Chris Findlay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Most comment parsing uses lexical states to achieve this without clash
with other tokens (since the longest match wins).
So when you encounter the "/*" you switch to a new state, and in that
state there are only 2 tokens defined, "*/" to return you to the
previous lexical state and ~[] to eat any other characters
_one_at_a_time_ so that the endOfComment token is always matchable.

On Wed, Apr 22, 2009 at 12:48 PM, Douglas Alves <knidel@...> wrote:

> Good night.
> First, sorry for my english.
> I'm a student of Computer Scientist in Brazil.
>
> I'm work in my monografy with JavaCC.
>
> I'm having trouble writing a token that defines several lines of comments,
> as in C + +. I am using this definition:
> < COMENTARIO_VARIAS_LINHAS: "/*"  (~[])*     "*/"  >
>
> But in this case also includes (~[])* the end of the comment "*/", error
> occurs and the time to acknowledge the comments of several lines. If you
> have any suggestions, thank you now.
> Regards,
>
>
> Saudações,
>           Douglas Alves
>



--
 - J.Chris Findlay
   (c:

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Parent Message unknown Re: JAVACC - Problems if coments lines

by Kenneth R Beesley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hola Douglas,

Desculpe meu português.

O tokenizador de JavaCC é sempre em um estado ou em outro.  Geralment,  
o tokenizador
começa no estado DEFAULT.  Depois de encontrar "/*", o tokenizador  
deve mudar (?)
de DEFAULT a um outro estado "dentro de comentário".  Por exemplo

SKIP: {
        "/*" : IN_DELIMITED_COMMENT
|     " "
| "\n"
| "\r"
| "\t"
| "\f"
}

Neste estado IN_DELIMITED_COMMENT, o tokenizador deve aceitar qualquer  
caráter,
ou sequencia de caracteres, mas depois de aceitar "*/", o estado deve  
voltar ao estado DEFAULT.


// special lexical state for skipping a delimited comment
< IN_DELIMITED_COMMENT >
SKIP: {
    // find */ and shift back to DEFAULT state
    "*/": DEFAULT
|
    // or just match and skip any character
    < ~[] >
}

Você pode ver esta solução nas FAQ http://www.engr.mun.ca/~theo/JavaCC-FAQ/javacc-faq-moz.htm

Boa sorte,

Ken


On 23 Apr 2009, at 02:17

>
> ----------------------------------------------------------------------
>
> From: Douglas Alves <knidel@...>
> Date: 21 April 2009 18:48:35 MDT
> To: users@...
> Subject: JAVACC - Problems if coments lines
>
>
> Good night.
> First, sorry for my english.
> I'm a student of Computer Scientist in Brazil.
>
> I'm work in my monografy with JavaCC.
>
> I'm having trouble writing a token that defines several lines of  
> comments, as in C + +. I am using this definition:
> < COMENTARIO_VARIAS_LINHAS: "/*"  (~[])*     "*/"  >
>
> But in this case also includes (~[])* the end of the comment "*/",  
> error occurs and the time to acknowledge the comments of several  
> lines. If you have any suggestions, thank you now.
> Regards,
>
>
> Saudações,
>           Douglas Alves
>
>


******************************
Kenneth R. Beesley, D.Phil.
P.O. Box 540475
North Salt Lake, UT
84054  USA






---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Re: JAVACC - Problems if coments lines

by J.Chris Findlay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanx for the translation and example (c:

On Fri, Apr 24, 2009 at 4:47 AM, Kenneth Reid Beesley
<krbeesley@...> wrote:

> Hola Douglas,
>
> Desculpe meu português.
>
> O tokenizador de JavaCC é sempre em um estado ou em outro.  Geralment, o
> tokenizador
> começa no estado DEFAULT.  Depois de encontrar "/*", o tokenizador deve
> mudar (?)
> de DEFAULT a um outro estado "dentro de comentário".  Por exemplo
>
> SKIP: {
>        "/*" : IN_DELIMITED_COMMENT
> |       " "
> |       "\n"
> |       "\r"
> |       "\t"
> |       "\f"
> }
>
> Neste estado IN_DELIMITED_COMMENT, o tokenizador deve aceitar qualquer
> caráter,
> ou sequencia de caracteres, mas depois de aceitar "*/", o estado deve voltar
> ao estado DEFAULT.
>
>
> // special lexical state for skipping a delimited comment
> < IN_DELIMITED_COMMENT >
> SKIP: {
>   // find */ and shift back to DEFAULT state
>   "*/": DEFAULT
> |
>   // or just match and skip any character
>   < ~[] >
> }
>
> Você pode ver esta solução nas FAQ
> http://www.engr.mun.ca/~theo/JavaCC-FAQ/javacc-faq-moz.htm
>
> Boa sorte,
>
> Ken
>
>
> On 23 Apr 2009, at 02:17
>>
>> ----------------------------------------------------------------------
>>
>> From: Douglas Alves <knidel@...>
>> Date: 21 April 2009 18:48:35 MDT
>> To: users@...
>> Subject: JAVACC - Problems if coments lines
>>
>>
>> Good night.
>> First, sorry for my english.
>> I'm a student of Computer Scientist in Brazil.
>>
>> I'm work in my monografy with JavaCC.
>>
>> I'm having trouble writing a token that defines several lines of comments,
>> as in C + +. I am using this definition:
>> < COMENTARIO_VARIAS_LINHAS: "/*"  (~[])*     "*/"  >
>>
>> But in this case also includes (~[])* the end of the comment "*/", error
>> occurs and the time to acknowledge the comments of several lines. If you
>> have any suggestions, thank you now.
>> Regards,
>>
>>
>> Saudações,
>>          Douglas Alves
>>
>>
>
>
> ******************************
> Kenneth R. Beesley, D.Phil.
> P.O. Box 540475
> North Salt Lake, UT
> 84054  USA
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>



--
 - J.Chris Findlay
   (c:

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...