Loading ...
Sorry, an error occurred while loading the content.

problems with label

Expand Messages
  • Krishanu Debnath
    Hello, My grammer accepts keywords as a identifier. So I use the following identifier rule in parser. id returns [_return_type *idObj] { // initialized code }
    Message 1 of 1 , Jan 17, 2005
    • 0 Attachment
      Hello,

      My grammer accepts keywords as a identifier. So I use the following identifier
      rule in parser.

      id returns [_return_type *idObj]
      {
      // initialized code
      }
      :
      tId:ID
      {
      // retrieve the token that has been set in lexer using $setToken()
      pIdObj = (_return_type *)... //label tId is used to
      retrieve the _return_type node
      }
      // Followings are the keywords
      | tIndex:"index"
      {
      // similar C++ code except it use label 'tIndex'
      }
      | tOut:"out"
      {
      // similar C++ code except it use label 'tOut'
      }
      // Other keywords

      Now to avoid (keyword set is quite large)duplicate codes for each keyword,
      I would like to have the 'id' rule as follows ..

      id returns [_return_type *idObj]
      {
      // initialized code
      }
      :
      tId:ID
      {
      // retrieve the token that has been set in lexer using $setToken()
      pIdObj = (_return_type *)... //label tId is used to access
      the _return_type node
      }
      |
      // Followings are the keywords
      (
      tKeyword:""index"
      | tKeyword:"out"
      |
      ... // other keywords ..

      )
      {
      // C++ code using label 'tKeyword'
      }


      But Antlr reports error 'already defined label tKeyword' for this. Is there any
      options/work around available to by pass this error?

      Krishanu

      --
      "When I have to rely on inadequacy, I prefer it to be my own."
      --Richard Heathfield
    Your message has been successfully submitted and would be delivered to recipients shortly.