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 (
[
{
<
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
(
[
{
<
- -30 if you handle multiple brace types and don't allow mismatched braces like
<(>)
- -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 } || < 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.
"Hel(o"
? I assume they should be handled like your -50 for comments, but you don't specify that. \$\endgroup\$