Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Compiler Tools JavaCC > Identifying unp...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 2 Topic 480 of 555
Post > Topic >>

Identifying unparsed keyword token kinds in ParseException (was:

by AC <user@[EMAIL PROTECTED] > Sep 27, 2007 at 07:21 AM

This is a multi-part message in MIME format.
--------------020406070703070401060005
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

One way to get ParseException messages to identify keyword tokens with
a <...> string:

1. Change the token expression to be something other than a simple
    string, such as changing from:
      <IF: "if">
    to:
      <IF: "i" "f">
    or to:
      <IF: "if" | "if">

    The result of this should be that after javacc is run,
    PARSERNAMEConstants.tokenImage contains "<IF>" (instead of "\"if\"").

2. Change ParseException.java to combine the
    PARSERNAMEConstants.tokenImage[tok.kind] for the token with the
    add_escapes(tok.image) (instead of just add_escapes(tok.image)).
    For example, attached changes produce <"if"=IF> (instead of "if").

Hope this helps!


Cesare Zecca wrote:

> Exception in thread "main"
> ParseException: Encountered "if" at line 1, column 5.
> Was expecting one of:
>     <PAR_OPEN> ...
>     <NUMBER_LITERAL> ...
>     "-" ...
>     <GROUP_ID> ...
>  
> Anyway, the diagnostic does not mention at all that... "if" is a
> reserved keyword.

--------------020406070703070401060005
Content-Type: text/plain;
 name="ParseException.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="ParseException.patch"

--- old/ParseException.java
+++ new/ParseException.java
@[EMAIL PROTECTED]
 -110,7 +110,7 @[EMAIL PROTECTED]
       }
       expected.append(eol).append("    ");
     }
-    String retval = "Encountered \"";
+    String retval = "Encountered ";
     Token tok = currentToken.next;
     for (int i = 0; i < maxSize; i++) {
       if (i != 0) retval += " ";
@[EMAIL PROTECTED]
 -118,10 +118,15 @[EMAIL PROTECTED]
         retval += tokenImage[0];
         break;
       }
-      retval += add_escapes(tok.image);
+      String kindImage = tokenImage[tok.kind];
+      if (!kindImage.startsWith("<")) {
+        retval += kindImage;
+      } else {
+        retval +=
"<\""+add_escapes(tok.image)+"\"="+kindImage.substring(1);
+      }
       tok = tok.next; 
     }
-    retval += "\" at line " + currentToken.next.beginLine + ", column " +
currentToken.next.beginColumn;
+    retval += " at line " + currentToken.next.beginLine + ", column " +
currentToken.next.beginColumn;
     retval += "." + eol;
     if (expectedTokenSequences.length == 1) {
       retval += "Was expecting:" + eol + "    ";

--------------020406070703070401060005--
 




 2 Posts in Topic:
Reserved keywords: diagnostic
Cesare Zecca <Cesare.Z  2007-09-26 15:17:30 
Identifying unparsed keyword token kinds in ParseException (was:
AC <user@[EMAIL PROTEC  2007-09-27 07:21:20 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Sep 7 7:42:09 CDT 2008.