0

I am looking to abstract part of a parse tree into a map. Specifically I want something concrete like this:

syntax RecType = RECORD: "{" {(Ident "=" Num) ";"}* "}"

Where let's just say Ident and Num and str and int, respectively.

To be abstracted to something like:

public data RECTYPE = RECORD(map[str, int] rec);

Is this something is is possible? I am getting some constructor errors from this.

Thanks!

josh
  • 1,544
  • 2
  • 16
  • 27

1 Answers1

1

You have two questions:

  1. Why doesn't this definition work?
    The names for production in a grammar have to start with a lower case character, this is to avoid ambiguities in writing reject rules. (Similarly, names for Symbols have to start with an upper case character).
  2. How to translate the parse tree to an AST?
    We have an implode function which you can use to translate a parse tree to an ast. However the AST has to closely model your grammar. If I'm correct, this won't translate your key-value pairs to a map. You will have to manually write the transformation to the desired AST. (It's not that hard, check out this recipe for an example)
Davy Landman
  • 15,109
  • 6
  • 49
  • 73