Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9198409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:16:31+00:00 2026-06-17T22:16:31+00:00

I use javacc 5.0 to generate a json parser with the grammar file: https://github.com/inqwell/json/blob/master/src/main/javacc/com/inqwell/json/JSON.jj

  • 0

I use javacc 5.0 to generate a json parser with the grammar file: https://github.com/inqwell/json/blob/master/src/main/javacc/com/inqwell/json/JSON.jj

But there are some errors in the generated java source code.

char escape = '\u005c\u005c';

and

switch(echar)
{
  case 'n':
    buf.append(System.getProperties().get("line.separator")); to++;
    break;

  case 'r':  buf.append('\u005cr'); to++; break;
  case 't':  buf.append('\u005ct'); to++; break;
  case 'b':  buf.append('\u005cb'); to++; break;
  case 'f':  buf.append('\u005cf'); to++; break;
  case '\u005c\u005c': buf.append('\u005c\u005c'); to++; break;
  case '"':  buf.append('"');  to++; break;
  case '\u005c'': buf.append('\u005c''); to++; break;
  case '\u005cr': to++; if (to < len && s.charAt(to) == '\u005cn') to++; break;
  case '\u005cn': to++; break;
}

And in the grammer file, they are:

char escape = '\\';

And

switch(echar)
{
  case 'n':
    buf.append(System.getProperties().get("line.separator")); to++;
    break;

  case 'r':  buf.append('\r'); to++; break;
  case 't':  buf.append('\t'); to++; break;
  case 'b':  buf.append('\b'); to++; break;
  case 'f':  buf.append('\f'); to++; break;
  case '\\': buf.append('\\'); to++; break;
  case '"':  buf.append('"');  to++; break;
  case '\'': buf.append('\''); to++; break;
  case '\r': to++; if (to < len && s.charAt(to) == '\n') to++; break;
  case '\n': to++; break;
}

These case chars should not be escaped, but how to do it?


update

The code can’t be compiled in my IDEA, please see my screenshot:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:16:32+00:00Added an answer on June 17, 2026 at 10:16 pm

    There is no error in the generated code. The literals '\\' and '\u005c\u005c' mean the same thing in Java. The reason is that unicode escapes are processed first and other escape sequences are processed later. See section 3.2 of the JLS (3rd edition) http://docs.oracle.com/javase/specs/jls/se5.0/html/lexical.html


    Edit: The following was added in response to Freewind’s comment

    theo-laptop:src theo$ javacc JSON.jj
    Java Compiler Compiler Version 5.0 (Parser Generator)
    (type "javacc" with no arguments for help)
    Reading from file JSON.jj . . .
    Note: UNICODE_INPUT option is specified. Please make sure you create the parser/lexer using a Reader with the correct character encoding.
    File "TokenMgrError.java" is being rebuilt.
    File "ParseException.java" is being rebuilt.
    File "Token.java" is being rebuilt.
    File "JavaCharStream.java" is being rebuilt.
    Parser generated successfully.
    theo-laptop:src theo$ fgrep \\u005c JSON.java
    char escape = '\u005c\u005c';
      case 'r': buf.append('\u005cr'); to++; break;
      case 't': buf.append('\u005ct'); to++; break;
      case 'b': buf.append('\u005cb'); to++; break;
      case 'f': buf.append('\u005cf'); to++; break;
      case '\u005c\u005c': buf.append('\u005c\u005c'); to++; break;
      case '\u005c'': buf.append('\u005c''); to++; break;
      case '\u005cr': to++; if (to < len && s.charAt(to) == '\u005cn') to++; break;
      case '\u005cn': to++; break;
    theo-laptop:src theo$ javac JSON.java
    theo-laptop:src theo$ javac -version
    javac 1.7.0_07
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an assignment to use JavaCC to make a Top-Down Parser with Semantic
I am teaching myself to use JavaCC in a hobby project, and have a
use C#,want to upload excel file on google doc. bellow syntax use to upload
I have a external jar file named xxx.jar. I use xxx.jar in my GWT
I am trying to implement Error Reporting and Recovery in JavaCC grammar as given
I use wsgen to generate Java SOAP stubs. Using Java basic types or also
In the following example, I'm trying to use sun.tools.javac.Main to dynamically compile a class
i have written an ant script, which runs ok and generate the .jar file
This page describes how I can use the code generator in javac to generate
I'm trying to use JavaCC to build a simple command line calculator that can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.