Fun with Matching Braces The contest is to make a program or function that takes an arbitrary string
resembling source code and checks to see if the "braces" follow the basic rules for
brace matching. That is, the number of left braces and right braces have to match, and you
can't have a right brace without a corresponding prior left brace.

You may choose to use any "brace" among ( [ { &lt;

Your program must output/return a true-y value or 'Y' if the input is legal and a false-y value or 'N' if the input is illegal.

Scoring

Your score is the number of bytes in your source minus bonuses.

Bonuses


-20 per each additional brace type handled among ( [ { &lt;
-30 if you handle multiple brace types and don't allow mismatched braces like &lt;(&gt;)
-50 points if you handle /* */ or // comments (the same way C or Java does)
-20 points if you handle both types of comments
-50 if you ignore braces inside ' and " quotes. To get the points you also have to check that quotes properly match. Eg: ("')"') is not a valid "program" but ("')") is. You do not have to worry about escaped characters. "\"" is an illegal program if you go for this bonus.


So if your program is 327 ASCII characters long, handles ( and [, doesn't check mismatching, and handles // comments and quotes, you get:

327 - 20 * 1 - 0 - 50 - 0 - 50 = 207 points

EDIT: Added bonuses for ignoring braces inside ' and " quotes
EDIT 2: Return values cannot be any string. Must be true/false 1/0 'Y'/'N' ect.
EDIT 3: Since there is some confusion, here is some pseudo-BNF to give an idea of what is expected.

Grammar for minimal program:
exprs = expr exprs
expr = ( exprs ) || not_braces* || nil

Grammar for all bonuses:
exprs = expr exprs
expr = ( exprs ) || [ exprs ] || { exprs } || &lt; exprs > || // not_newline* \n || /* not_end_comment* */ || not_braces* || nil

Note that if you do the bonuses, you will both accept and reject things that the basic program would not.
PHP, -4 (156 - 20*3 - 30 - 50 - 20)
&lt;?php $x=preg_replace(&quot;!(//.*|/\*.*\*/|[^()[\]{}&lt;&gt;])!sm&quot;,'',$argv[1]);while(strlen($x)!=strlen($x=str_replace(str_split('()[]{}&lt;&gt;',2),'',$x)));print $x?0:1;


It removes comments
It filters out all characters different than (, ), [, ], {, }, &lt;, &gt;
It replaces all (), [], {}, &lt;&gt; pairs until there are no matches
Prints 1 if the string is empty, 0 otherwise

(Edit: changed the regex; the source code is now 156 instead of 175)