2

To make the question a little more specific. I was wondering if I could generate Rascal parseable code from the built-in grammar datastructure, which in turn is parsed rascal code of course. I would like this since it is easier readable and also a nice feature to have since it would make this part of parsing conversable.

so from an instance of this:

data Grammar = \grammar(set[Symbol] starts, map[Symbol sort, Production def] rules);

To something like this:

start syntax E 
    = E "+" T
    | T
    ;

syntax T
    = T "*" F
    | F
    ;

syntax F
    = "(" E ")"
    | "a"
    ;

1 Answers1

0

Yes, the utility can be found in 'lang:: rascal::format::Grammar'

'grammar2rascal' formats an entire grammar as a rascal program which defines the same grammar.

'topProd2rascal' maps a single rule back to its concrete definition in rascal notation.

Jurgen Vinju
  • 6,393
  • 1
  • 15
  • 26
  • 1
    Thank you! easier than expected :p I tend to get kind of lost in the different parts of the library. There is a Grammar.rsc and in analysis also, etc. The tutor didn't help me out this time, so I thought maybe stackoverflow was the easiest option – E. Apperloo Apr 30 '18 at 12:46