1

As far as I understand, using return values and element labels in ANTLR are sufficient to build an AST. e.g.

r returns [int c, String d] :   
        a='class' b=ID  ... {$c=$b; $d=$a;}

Is this kind of extension to eBNF called a S-attributed grammar?

Is it common to build ASTs that way?

I'm especially interested in unparsing an AST (not a parse tree) build from this attributed grammar. Are there any benefits from restricting the attributes to pure assignments? (no function calls e.g. $c= fun($a) ) I've explained my unparsing problem here on SO.

Community
  • 1
  • 1
Stefan K.
  • 7,701
  • 6
  • 52
  • 64
  • S-attributed grammar simply means a grammar that only uses attributes whose values come from children of nonterminals. So if you have S: A; as a grammar A could pass an attribute(value) to S but S could not pass an attribute to A. – user764754 May 01 '13 at 10:52

0 Answers0