• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JavaCC trace code...

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!

I'm a new user to JavaCC and I could use some help if anyone is willing. So far I've written the .jj file for my code and have gotten JavaCC to generate all 7 files but now I want it to do something more and I'm not sure where to start. My parser uses a GUI. It takes the parser text in from an editable TextArea and appends the output to an uneditable TextArea. What I need my parser to do is to print out a message as it parses each token, something like this:
Expecting digit...
digit found at line 1, column 2.
The error reporting works perfectly correctly and I have the errors showing up in the TextArea for the output but how do I get JavaCC to output this kind of a message to my output TextArea? I'm not sure where to start. I've pasted the code for my .jj file below...

 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not familiar with the tool. There ought to be documentation telling you what you are returning.

Put another line in your catch(Error e) block like this:-as required here.

I have used other lexical scanners, which produce some sort of return value. You ought to have a method to add something like this:-. . . and you need to put a line in with each TOKEN: definition on the lines of "return getSymbol(INT_TYPE, Integer.parseInt(yytext()));"

As I said, there ought to be documentation with the tool on its website telling you what you are supposed to do, and there will probably be worked examples for you to study.

BTW: A digit or a character DOES NOT constitute a token.
 
Brandi Love
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I overlooked a very simple solution to this one - all you need to do if you want a trace is to set DEBUG_PARSER = true under options in the .jj file.
 
reply
    Bookmark Topic Watch Topic
  • New Topic