Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] lpg question

Hi Mike,
Thanks a lot for the answer!
I have a written a grammar that was received by adding/dropping rules
in UPC/C99 and the generated parser seems reducing rules correctly.

Now I want to reuse as much as possible the parser action classes
(C99BuildASTParserAction, BuildASTParserAction, AbstractParserAction)
in the manner that will cause the
1) Syntax highlighting
2) Code outline
3) Code completion
to work with the new language (I have the part of keyword highlighting
already working).

The problem is that the language I’m working with has no declaration
and type sections that are presented in C99. Bellow are the rules that
bypass the declaration and type rules as I’ve defined:

119  172   directive ::= align_directive               (NEW)
120  173   directive ::= ds_directive                  (NEW)
121  174   directive ::= dcb_directive                (NEW)
122  175   directive ::= dcw_directive                (NEW)
123  176   directive ::= dcl_directive                 (NEW)
124  177   directive ::= list_directive                 (NEW)
125  178   directive ::= nolist_directive              (NEW)
126  179   directive ::= global_directive             (NEW)
127  180   directive ::= const_directive              (NEW)
128  181   directive ::= register_directive           (NEW)
129  182   directive ::= reserve_directive            (NEW)
130  183   directive ::= strict_directive               (NEW)
131  184   directive ::= nonstrict_directive         (NEW)
132  185   directive ::= sync_directive               (NEW)
133  186   directive ::= nosync_directive            (NEW)
134  187   directive ::= functioncall_attr             (NEW)
135  188   directive ::= func_declarator              (NEW)
136  189   directive ::= outofline_directive           (NEW)
137  190   directive ::= struct_or_union_specifier (NEW)
138  191   directive ::= enum_specifier               (NEW)

139  93    expression_statement ::= ;
140  94    expression_statement ::= expression_in_statement ;
141  154   expression_statement ::= directive ;   (NEW)

158  213   section_definition ::= SectionDirective identifier_token
compound_statement  (NEW)

159  79    statement ::= labeled_statement
160  80    statement ::= compound_statement
161  81    statement ::= expression_statement
162  82    statement ::= selection_statement
163  83    statement ::= iteration_statement
164  84    statement ::= jump_statement
165  149   statement ::= include_directive              (NEW)
166  150   statement ::= inline_func_definition        (NEW)
167  151   statement ::= func_definition                 (NEW)
168  152   statement ::= section_definition             (NEW)
169  153   statement ::= ERROR_TOKEN

170  92    block_item ::= statement                       (NEW)
171  90    block_item_list ::= block_item
172  91    block_item_list ::= block_item_list block_item

173  211   translation_unit ::= block_item_list
174  212   translation_unit ::=
175  0     $accept ::= translation_unit
176  2     <empty> ::=

 

Hence, one of the problems I have is how to override the
BuildASTParserAction#consumeTranslationUnit method  to add/get
statements to the TranslationUnit instead of
addDeclarations/getDeclaration methods (the problem is that
INodeFactory is annotated by @noextend, @noimplement).

How to overcome this?
Thank you,
David

On Mon, Sep 14, 2009 at 5:34 PM, Mike Kucera <mkucera@xxxxxxxxxx> wrote:

Hi David,

I take it what you're trying to do is have LPG print out which reductions are actually happening during a parse so that you can debug your parser.

As far as I know there is no way to automatically get LPG to do that for you, so you need to do it yourself. You'll notice that the information you need is at the top of the *.l files. So to make it work I wrote a little script that reads the *.l files and generates a Java class that contains a giant String array where the index is the rule number and the element is the rule. Then I added a couple lines of code to the top of the ruleAction() method in the generated parser that uses the array to print out the rules that are being fired.


Mike Kucera
Software Developer
IBM Eclipse CDT Team
mkucera@xxxxxxxxxx

Inactive hide details for David Sariel ---09/14/2009 04:12:35 AM---Hello,David Sariel ---09/14/2009 04:12:35 AM---Hello,


From:

David Sariel <datosar@xxxxxxxxx>

To:

"CDT General developers list." <cdt-dev@xxxxxxxxxxx>

Date:

09/14/2009 04:12 AM

Subject:

[cdt-dev] lpg question




Hello,
yacc (bison) supports --verbose and --debug options allowing automatic
generation of debug outputs like:

Reducing via rule 93 (line 329), statement -> statement_list
...
Reducing via rule 185 (line 601), statement_list -> translation unit
...

Does lpg analogs (-verbose and -debug switches) allow the same? I'm
generating parsers with those options.
*.l files indicate that VERBOSE, DEBUG are options in effect. But
parser files generated are the same
as without -verbose and -debug, i.e. no debugging outputs were generated.

Am I missing something?

Thanks,
David
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev



_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev


GIF image

GIF image


Back to the top