1 / 12

Testing Grammars For Top Down Parsers

Testing Grammars For Top Down Parsers. By Asma M Paracha, Frantisek F. Franek Dept. of Computing & Software McMaster University Hamilton, Ont. Presentation Outline. Background Information Purdom’s Algorithm Implementation of Purdom’s Algorithm Test cases for MACS

hera
Download Presentation

Testing Grammars For Top Down Parsers

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. Testing Grammars For Top Down Parsers By Asma M Paracha, Frantisek F. Franek Dept. of Computing & Software McMaster University Hamilton, Ont

  2. Presentation Outline • Background Information • Purdom’s Algorithm • Implementation of Purdom’s Algorithm • Test cases for MACS • Conclusions & Future Work

  3. Compiler Test Case • Compiler is a computer program which accepts a source program as input and produces either an object code or error messages depending upon the source code. • Test case for a compiler should have: • A test case description • A source program • An expected output • Major Problem • Completeness of coverage • Unfeasible size of test data

  4. Testing Grammar • Grammar defines both a language and the basis of deriving elements for a language. • Grammar is considered both as a program and a specification. • Two important types of grammars: • Context free grammars • Regular grammars • Grammar should be tested to verify: • It defines the same language for which it is written • For completeness (every terminal and every rule is used) • To remove ambiguity.

  5. Context Free Grammars (CFG) • CFG is a set of recursive rewriting rules used to generate strings in various patterns. • Components of grammar: • N: Finite set of non-terminals • T: Finite set of terminals, does not intersect with N • S: Initial symbol from N (starting symbol) • P: Finite set of production rules of the form n m • No practical way to check the dynamic semantics of the language defined by CFG.

  6. Testing Parser • The process of checking a given program against the grammar rules to determine whether or not it is syntactically correct. • Test data for parser is a program which use all the production rules of underlying grammar. Testing the parser

  7. Purdom’s Algorithm • Proposed by Purdom in 1972 for testing compilers for automatically generating sentences from the grammar by using every production rule at least once. • Sentences generated are good to check most of compiler code and tables. • Only checks the syntactic aspect, no guarantee for the proper execution. • Generated sentences may be inconsistent with the contextual constraints for e.g. variable declarations, use of identifiers, type checking. • Purdom’s algorithm verifies the compiler correctness, not interested in other aspects such as: • Efficiency • Performance

  8. Testing MACS Compiler • MACS is a simple object oriented language very much similar to C++ and Java. It is used in the forth coming book of Franek on compilers. • MACS uses both LALR and LL(1) grammars and has a C++ bottom-up parser built using Bison/Flex and a Java top-down parser built using JavaCC. • MACS LL(1) grammar has 77 terminlas,90 non-terminals and 301 production rules.

  9. Implementation of Purdom’s algorithm

  10. Implementation of Purdom’s algorithm (Contd..)

  11. Results

  12. Conclusions • Parser testing is an area which needs more attention. • Purdom’s algorithm is a complete method for testing small grammars. • Test cases generated are incorporated with the semantic aspects of the language to perform the compiler validation. • Future work includes testing the most advanced features of MACS compiler.

More Related