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

Semantic predicates and predicate evaluation

Expand Messages
  • Michael Schmitt
    Hello, I wish you all a happy new year! Today I wondered about the role of validating semantic predicates during guessing (i.e. while evaluating some
    Message 1 of 2 , Jan 2, 2000
    • 0 Attachment
      Hello,

      I wish you all a happy new year!

      Today I wondered about the role of validating semantic predicates during
      guessing (i.e. while evaluating some syntactic/semantic
      predicate). Interestingly, nothing about this is said in the ANTLR
      manual. Therefore, I started to investigate the code in order to find out
      what happens to exceptions thrown during the analysis of predicates. It
      seems like

      - validating semantic predicates are evaluated while processing a
      syntactic predicate
      - if a validating sem. pred. throws an exception (because the predicate
      is false) during guessing the exception is captured by the code that
      started the evaluation of the syntactic predicate

      This means a syntactic predicate can fail because of a sem.
      predicate! Excellent!

      Well, what's so nice about this? In my SDL grammar, there are rules like
      the following one:

      attributeProperty :

      ( ( local | exported )? name[ SDLName::variable ] ) =>
      variableProperty
      | fieldProperty
      ;

      variableProperty :

      ( local | exported )? name[ SDLName::variable ] ( sort )?

      ;

      In order to make the alternatives in attributeProperty deterministic, I
      have to add a syntactic predicate. However, it is not sufficient to just
      look at the syntax. It is also necessary to check the type of 'name'. So
      what you can do it adding a validating semantc predicate to 'name'.

      Terence, could you please add a few lines to the manual about the
      role of semantic predicates during predicate evaluation? Just state that
      exceptions are captured and may influence the looahead analysis. This will
      be of great help for people in order to understand ANTLR.

      Michael
    • parrt@xxxxx.xxxx
      ... Yep. A semantically invalid construct should also make the trial recognition fail. ... Glad you approve :) ... Good point. Heh, since you have it figured
      Message 2 of 2 , Jan 2, 2000
      • 0 Attachment
        Michael Schmitt writes:
        >From: Michael Schmitt <schmitt@...-luebeck.de>
        >
        >Hello,
        >
        >I wish you all a happy new year!
        >
        >Today I wondered about the role of validating semantic predicates during
        >guessing (i.e. while evaluating some syntactic/semantic
        >predicate). Interestingly, nothing about this is said in the ANTLR
        >manual. Therefore, I started to investigate the code in order to find out
        >what happens to exceptions thrown during the analysis of predicates. It
        >seems like
        >
        > - validating semantic predicates are evaluated while processing a
        > syntactic predicate
        > - if a validating sem. pred. throws an exception (because the predicate
        > is false) during guessing the exception is captured by the code that
        > started the evaluation of the syntactic predicate
        >
        >This means a syntactic predicate can fail because of a sem.
        >predicate!

        Yep. A semantically invalid construct should also make the trial
        recognition fail.

        > Excellent!

        Glad you approve :)

        >Well, what's so nice about this? In my SDL grammar, there are rules like
        >the following one:
        >
        >attributeProperty :
        >
        > ( ( local | exported )? name[ SDLName::variable ] ) =>
        > variableProperty
        > | fieldProperty
        > ;
        >
        >variableProperty :
        >
        > ( local | exported )? name[ SDLName::variable ] ( sort )?
        >
        > ;
        >
        >In order to make the alternatives in attributeProperty deterministic, I
        >have to add a syntactic predicate. However, it is not sufficient to just
        >look at the syntax. It is also necessary to check the type of 'name'. So
        >what you can do it adding a validating semantc predicate to 'name'.
        >
        >Terence, could you please add a few lines to the manual about the
        >role of semantic predicates during predicate evaluation? Just state that
        >exceptions are captured and may influence the looahead analysis. This will
        >be of great help for people in order to understand ANTLR.

        Good point. Heh, since you have it figured out with an example, how
        about posting a faq entry to http://www.jguru.com? Might as well get
        some "credit" for it. :)

        BTW, thanks for "kicking" me about the file/line stuff. I have
        modifed 2.7.0 to do emacs style "file:line: msg" messages and cleaned
        up the code to centralize the handling of file/line info. More later.

        Ter
      Your message has been successfully submitted and would be delivered to recipients shortly.