1 / 12

Set 6 Debugging with Lex & Yacc

Set 6 Debugging with Lex & Yacc. DEBUGGING YOUR GRAMMAR WITH YACC Assume your Yacc defn. file is called “Test” OBTAINING THE PARSING MACHINE Employ: yacc -v Test A representation of the parsing machine will be written onto y.output.

Download Presentation

Set 6 Debugging with Lex & Yacc

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Set 6Debugging with Lex & Yacc

  2. DEBUGGING YOUR GRAMMAR WITH YACC Assume your Yacc defn. file is called “Test” OBTAINING THE PARSING MACHINE Employ: yacc -v Test A representation of the parsing machine will be written onto y.output

  3. OBTAINING A TRACE OF THE YACC PARSE (a) In your main program in Test, employ: yydebug = 1; . . yyparse(); (b) Now employ: yacc -t Test Note: The yacc options –d, -v, -t can be combined, e.g. you can employ: yacc –dvt Test

  4. SELECTING WHAT TO TRACE You can switch tracing on or off by setting yydebug to 1 or 0 respectively. A method of allowing one to control which portion(s) of the source to trace is to include among your productions for a statement: statement : switchon ‘;’ {yydebug = 1;} | switchoff ‘;’ {yydebug = 0;} ; You can then insert the above statements into you source to bracket the portions that you wish to trace.

  5. RECOVERING FROM SOURCE PROGRAM ERRORS When Yacc reaches a state of the parsing machine without a default reduction, and which has no transition defined for the next input symbol from the source program, it calls yyerror with the string argument “syntax error”.

  6. But the user’s source program may have many errors, and our compiler should attempt to report as many as possible at each run. Accordingly, we need a way of bypassing the statement containing the error, so that we can continue to parse the rest of the source program in order to detect additional errors.

  7. This is accomplished using the system word “error” within the grammar. If the Yacc defn file contains the “production”: AA : BB error CCor AA : error CC the C-program produced by Yacc will do the following on detecting a syntax error in the source:

  8. It will call yyerror to report “syntax error”

  9. It will pop items off both state no. and symbol stacks, until it has popped a state which is a BB-successor of other states, or if BB is omitted, a state which is an error-successor of other states Note 1. If we were using symbol stack as we first did in class, the above would be equivalent to popping items from both stacks until a “BB” or “error” was popped from symbol stack. Note 2. No state can be a successor of other states with respect to more than one symbol.

  10. (c) It will now perform an AA-transition from the state which is now at the top of the stack (d) It will then start inputting symbols from the source and discarding them until it has read and discarded the symbol CC. At this stage, it will resume parsing the source in the usual manner.

  11. MOST COMMON USE The most common use of the “error” symbol is in conjuction with productions for lists of statements, e.g: statement_list : statement_list statement | statement | error ‘;’ ; Productions of this kind occur in many places, including “if” statements, “while” statements etc.

  12. Assuming that all statements end in a semicolon, this in effect: pops off all the state numbers involved in reading the current statement up to the point where a syntax error was detected, and then discards all further source symbols until after a semicolon is read.

More Related