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

Tree walkers

Expand Messages
  • harnold@xxxxxx.xxx
    To all: I d like to use tree walkers to check my grammar completeness/correctness & then build some objects for me. I m bit unsure how to do this. My grammar
    Message 1 of 2 , Aug 3, 1999
    • 0 Attachment
      To all:

      I'd like to use tree walkers to check my grammar completeness/correctness &
      then build some objects for me. I'm bit unsure how to do this.

      My grammar is fairly simple. It recognizes named sections and within each
      section one or more parameters. Each parameter has a value. This value is
      either a fundamental type(int/double/string...) or a derived type(like
      struct). While I do know the section names in advance, it's not until
      runtime that I know which parameters(and their types) are legal in each
      section.

      For example, my [general] section requires parameters X, Y & Z and will
      optionally allow parameters M, N & O.

      This is ugly, what other options do I have?

      class MyTreeWalker extends TreeParser
      section: #(sectionName:Word { set global var to sectionName }
      (parameter)*);
      parameter: #(AssgnOp pname:Word value) { Is param legal? If required
      param, check it off some global list... }

      Thanks.


      Hugh
    • mzukowski@xxx.xxx
      ... Note that you can pass parameters to rules, like this: section: #(sectionName:Word (parameter[sectionName.getText()])*); parameter[String sectionName]:
      Message 2 of 2 , Aug 3, 1999
      • 0 Attachment
        > For example, my [general] section requires parameters X, Y &
        > Z and will
        > optionally allow parameters M, N & O.
        >
        > This is ugly, what other options do I have?
        >
        > class MyTreeWalker extends TreeParser
        > section: #(sectionName:Word { set global var to sectionName }
        > (parameter)*);
        > parameter: #(AssgnOp pname:Word value) { Is param legal? If required
        > param, check it off some global list... }


        Note that you can pass parameters to rules, like this:

        section: #(sectionName:Word (parameter[sectionName.getText()])*);
        parameter[String sectionName]: #(AssgnOp pname:Word value) { Is param
        legal? If required param, check it off some global list... }

        And yes, I would imagine you would build some tables describing the required
        and optional parameters and then check them off. This is probably easier
        than embedding it into the grammar.

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