regarding Javacc grammar

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

regarding Javacc grammar

by Kishore1 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all;

In javaCC grammar file all keywords is defined like this:

TOKEN : /* RESERVED WORDS AND LITERALS */
{
  < ADDHANDLER: "AddHandler" >
| < ADDRESSOF: "AddressOf" >
| < ALIAS: "Alias" >
| < AND: "And" >
| < ANDALSO: "AndAlso" >
| < ANSI: "Ansi" >
| < AS: "As" >
| < ASSEMBLY: "Assembly" >
| < AUTO: "Auto" >

| < BOOLEAN: "Boolean" >
| < BYREF: "ByRef" >
| < BYTE: "Byte" >
| < BYVAL: "ByVal" >
| <BINARY: "Binary">
..........
..........
......... and so on.



But how these list can be used in this type of production:

NonEscapedIdentifier ::= < IdentifierName but not Keyword >


Please let me explain this??


Thanks In Advance

Re: re[JavaCC] garding Javacc grammar

by J.Chris Findlay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I wrote something similar once where it read something like:

IdButNotKeyword() {
} {

   (
      <keyword1>
     | <Keyword2>
     | ...
   ) {
     throw new ParseException(...);   // there is a method to get one of these filled in with the line/col numbers but I forgot what it is.
   }
   | <identifier>

}

On 7/22/08, Kishore1 <kishore_74_lko@...> wrote:

Hi all;

In javaCC grammar file all keywords is defined like this:

TOKEN : /* RESERVED WORDS AND LITERALS */
{
  < ADDHANDLER: "AddHandler" >
| < ADDRESSOF: "AddressOf" >
| < ALIAS: "Alias" >
| < AND: "And" >
| < ANDALSO: "AndAlso" >
| < ANSI: "Ansi" >
| < AS: "As" >
| < ASSEMBLY: "Assembly" >
| < AUTO: "Auto" >

| < BOOLEAN: "Boolean" >
| < BYREF: "ByRef" >
| < BYTE: "Byte" >
| < BYVAL: "ByVal" >
| <BINARY: "Binary">
..........
..........
......... and so on.


But how these list can be used in this type of production:

NonEscapedIdentifier ::= < IdentifierName but not Keyword >


Please let me explain this??


Thanks In Advance


--
View this message in context: http://www.nabble.com/regarding-Javacc-grammar-tp18586309p18586309.html
Sent from the java.net - javacc users mailing list archive at Nabble.com.


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




--
- J.Chris Findlay
   (c:

Re: re[JavaCC] garding Javacc grammar

by Kishore1 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Mr J.Chris Findlay for giving answer.

But I am not satisfied with you solution. If I have already declared all the keywords/reserveWords in TOKEN list, so why I have to declared these again in any production. Its a very tedious task.

Please anyone tell me better solution of my question.

If I have declared all the keywords/reserveWords in TOKEN list like this:

TOKEN : /* RESERVED WORDS AND LITERALS */
{
  < ADDHANDLER: "AddHandler" >
| < ADDRESSOF: "AddressOf" >
| < ALIAS: "Alias" >
| < AND: "And" >
| < ANDALSO: "AndAlso" >
| < ANSI: "Ansi" >
| < AS: "As" >
| < ASSEMBLY: "Assembly" >
| < AUTO: "Auto" >
...
...
...
}


How can I refer all keywords in a production like:
void Identifier(): {}
{
   KEYWORDS | LITERALS
}

Pls answer me if you know it
Thanks.

Re: Re: re[JavaCC] garding Javacc grammar

by J.Chris Findlay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The only real way to group tokens is to have a production that lists them.
The lexing stage is separate from the parsing stage.

On Fri, Jul 25, 2008 at 7:02 PM, Kishore1 <kishore_74_lko@...> wrote:

>
> Thanks Mr J.Chris Findlay for giving answer.
>
> But I am not satisfied with you solution. If I have already declared all the
> keywords/reserveWords in TOKEN list, so why I have to declared these again
> in any production. Its a very tedious task.
>
> Please anyone tell me better solution of my question.
>
> If I have declared all the keywords/reserveWords in TOKEN list like this:
>
> TOKEN : /* RESERVED WORDS AND LITERALS */
> {
>  < ADDHANDLER: "AddHandler" >
> | < ADDRESSOF: "AddressOf" >
> | < ALIAS: "Alias" >
> | < AND: "And" >
> | < ANDALSO: "AndAlso" >
> | < ANSI: "Ansi" >
> | < AS: "As" >
> | < ASSEMBLY: "Assembly" >
> | < AUTO: "Auto" >
> ...
> ...
> ...
> }
>
> How can I refer all keywords in a production like:
> void Identifier(): {}
> {
>   KEYWORDS | LITERALS
> }
>
> Pls answer me if you know it
> Thanks.
> --
> View this message in context: http://www.nabble.com/regarding-Javacc-grammar-tp18586309p18646290.html
> Sent from the java.net - javacc users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> 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@...

LightInTheBox - Buy quality products at wholesale price