Let's say I have a struct_declaration_list of the following type. How do I reverse it?struct_declaration_list    : struct_declaration    | struct_declaration_list struct_declaration    ;P.S. Sorry I don't know the exact name of this kind of list so I can't search. I just have this grammar.
Reversing a List from a Context-Free Grammar
context free;formal grammars
Your question is not very precise. I assume you want the list of struct_declaration to start from the other end in the parse tree.Your grammar gives you a struct_declaration_list that looks like         SDL        /   \      SDL    SD     /   \   SDL   SD  /   \SDL   SD |SDIf you reverse the order in the second part of the rule, you reverse the pointers in the list, which may be understood as reversing the order.struct_declaration_list    : struct_declaration    | struct_declaration struct_declaration_list    ;Then the parse tree  looks like:   SDL  /   \ SD   SDL     /   \    SD   SDL        /   \       SD   SDL             |            SDThe left-to-right order of SD is in both cases that of their occurrence in the input string (the program).