From: Andre B. <and...@gm...> - 2004-08-17 08:14:44
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> <title></title> </head> <body bgcolor="#ffffff" text="#000000"> Hello baptiste,<br> <br> Have you ever thought about moving the symbol extraction part also into the grammar ?<br> I've notice this idea on a parser-generator language and was wondering if the same mechanism<br> can help us to simplify the work of symboltable extraction. Currently it's not so easy to synchronize<br> the cpp_grammar.txt file and the "symboldeclarator.cpp" where symbol extraction takes place.<br> what about extending the grammar-syntax by keywords for symbol extraction. Some examples:<br> <br> <b></b><b>Entry-Point:</b><br> translation_unit = <b>:enterscope('translation-unit')</b> :node( 'translation_unit', declaration_seq ) <b>:leavescope</b>;<br> <br> <b>Declaring a class:</b><br> <br> class_head_name = :node( 'class_name',<br> optional_alternative( :node('dll_macro', id ),<br> ?( :node('nested_name_specifier', nested_name_specifier) ) <br> [:node('id', id) | template_id] ) );<br> <br> class_head = class_key ?( class_head_name ) ?( base_clause );<br> <br> class_specifier = :node( 'class_specifier', class_head <b>:declareSymbol('class',$subnode('class_name') )</b> <br> <b>:enterscope('class-scope', :subnode('class_name'))</b><br> '{' ?( member_specification ) '}' <br> <b>:leavescope</b><br> );<br> <br> <b>New scope declaration extension:</b><br> named_namespace_definition = 'namespace' id <b>:push($2)</b> namespace_body <b>:pop</b>; ## $2 means second element which is 'id'<br> <br> namespace_body = '{' <b>:enterscope($top) </b>declaration_seq <b>:leavescope </b>'}'; ## $top is the top element in element stack<br> <br> unnamed_namespace_definition = 'namespace' <b>:push('<>')</b> namespace_body <b>:pop</b>;<br> <br> namespace_definition = :node( 'named_namespace_def', named_namespace_definition )<br> | :node( 'unnamed_namespace_def', unnamed_namespace_definition )<br> ;<br> <br> I'm not sure about that push/pop mechanism, but I think we need something to propagate information across <br> none-terminal-elements.<br> <br> <b>:enterscope(<string>)<br> :enterscope(<scope-type>,<named-node>)<br> :leavescope<br> :push(<string>)<br> </b><b>:push(<number>)</b><br> <b>:push(<named-node>)<br> :pop<br> :subnode(<string>)<br> <br> </b>What do you think about this ? I haven't read through the parser-code for grammar, so I don't know about the pit falls.<br> <br> greetings from <br> André<br> <br> </body> </html> |