Check if Parentheses Match in Source Code

This program checks if parentheses match up in a buffer that contains source code.

The source code is in a language similar to C. It supports the following:

  • Comments that start with /* and end with */, and can span multiple lines.

  • Comments that start with //, and run to the end of the line.

  • Strings that are delimited with double quote (") characters.

In addition, the following rules apply:

  • Inside a /* */ comment, // and " are ignored.

  • Inside a // comment, /*, */, and " are ignored.

  • Inside a string, comment delimiters are ignored.

  • Inside a string, the two-character sequence \" indicates an escaped double quote, ...

Get Find the Bug A Book of Incorrect Programs now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.