8 Replies Latest reply: Jan 20, 2010 6:52 PM by jschellSomeoneStoleMyAlias RSS

    javacc assistance: adding a block of arbitrary text

    843810
      Hi all

      I'm developing a statechart compiler, which takes in a textual format and generates C. This C is destined for embedded systems. Part of the frontend of the compiler is my parser.

      Most of my parser grammer is done, apart from this: allowing parsing of arbitrary text, as per this example:
      MyStateA
      {
        entry
        {
          --arbitrary C code here--
        }
      }
      So, parse the state block, which contains an entry block (all good so far). But how do I approach the arbitrary C code section? I dont want to incorporate the entire C grammer into my langauge. I've seen techniques whereby { and } braces are counted somehow, and the skip and token specs change. In this arbitrary code section, I can make the requirement that there must be prefectly paired braces within, thus the last closing one for entry can be determined.

      Can someone give me a hand with this?

      Thanks

      Rich
        • 1. Re: javacc assistance: adding a block of arbitrary text
          608410
          richid wrote:
          Can someone give me a hand with this?
          Yep, probably someone could if you asked in an appropriate forum. This is not. The java compiler doesn't use javacc, and you are not trying to compile java source code so you're unlikely to get help here. Is there a forum for javacc? if so that would be a far more appropriate place to ask.
          • 2. Re: javacc assistance: adding a block of arbitrary text
            843810
            There is not a forum for javacc on Sun Forums. A simple search in Sun Forums shows that there are many posts about javacc in this forum. Unfortunately there are many posts about javacc that are shot down by someone saying that there question is not about compilers.

            Maybe if there is a moderator listening, he could make a forum for javacc?

            Regards
            • 3. Re: javacc assistance: adding a block of arbitrary text
              843810
              Further, there isnt a decent forum for javacc at all, so it makes some sense to post this at the home of Java. The parent of the Java Compiler forum does not accept postings.

              Can you suggest a place where javacc-related can go? Do you know how to get a forum created?

              Regards
              • 4. Re: javacc assistance: adding a block of arbitrary text
                jschellSomeoneStoleMyAlias
                richid wrote:
                Can someone give me a hand with this?
                For starters that syntax won't work. Something like the following should
                MyStateA
                {
                  entry
                  <{
                    --arbitrary C code here--
                  }>
                }
                With that you should be able to define the syntax as <{.*}>

                The start/end delimeters are arbitrary but with the goal of insuring it isn't something that will show up in C code. Your syntax doesn't have that advantage.

                Why javacc versus the standard lex/yacc?
                • 5. Re: javacc assistance: adding a block of arbitrary text
                  843810
                  Thanks

                  Okay, my compiler / code generator is written in Java. Thus the output of javacc plays very well with the rest of the compiler. It is the output of my compiler that is C.

                  I currently have something like:
                  void State()
                  {}
                  {
                    ..
                    ..
                    (Entry())?
                    ..
                    ..
                  }
                  
                  void Entry()
                  {}
                  {
                    <ENTRY>
                    <LEFTBRACE>
                      (nothing here yet)
                    <RIGHTBRACE>
                  }
                  What does one do next? Do I define a token for (.*)? Then do something like x=<THAT_TOKEN> in the middle there? At some point I need to capture the actual code to place into my intermediate representation. None of the capturing parts of the input to the IR is done yet.
                  void Entry()
                  {}
                  {
                    <ENTRY>
                    <RANGLEBRACE>
                      (something)
                    <LANGLEBRACE>
                  }
                  Cheers

                  Rich
                  • 6. Re: javacc assistance: adding a block of arbitrary text
                    608410
                    richid wrote:
                    There is not a forum for javacc on Sun Forums.
                    that's because javacc is not a JDk / JSR / sun technology
                    A simple search in Sun Forums shows that there are many posts about javacc in this forum. Unfortunately there are many posts about javacc that are shot down by someone saying that there question is not about compilers.
                    Unfortunately people don't find the most appropriate forum on the net before posting.

                    >
                    Maybe if there is a moderator listening, he could make a forum for javacc?
                    unlikely on forums.sun.com
                    Regards
                    • 7. Re: javacc assistance: adding a block of arbitrary text
                      608410
                      richid wrote:
                      Further, there isnt a decent forum for javacc at all, so it makes some sense to post this at the home of Java. The parent of the Java Compiler forum does not accept postings.

                      Can you suggest a place where javacc-related can go? Do you know how to get a forum created?
                      Sure, it took me about 30 seconds to find the javacc home page (thank you Google) and then find [https://javacc.dev.java.net/servlets/ProjectMailingListList|https://javacc.dev.java.net/servlets/ProjectMailingListList] after discovering that there were no forums so mailing list is next most likely mechansim. Someone unfamiliar with java.net project home pages may be forgiven for taking 10 seconds longer.

                      I suggest the user list is most appropriate to your present need.

                      >
                      Regards
                      • 8. Re: javacc assistance: adding a block of arbitrary text
                        jschellSomeoneStoleMyAlias
                        richid wrote:
                        What does one do next? Do I define a token for (.*)? Then do something like x=<THAT_TOKEN> in the middle there? At some point I need to capture the actual code to place into my intermediate representation. None of the capturing parts of the input to the IR is done yet.
                        You take my general idea and create specific syntax for your language. I was guessing from the OP that you have in fact made some non-trivial syntax already. Thus it shouldn't be that difficult.