// Copyright Amruth N. Kumar, amruth@computer.org // Syntax: // # Unique id // Learning Objective // > // Pattern (could be multi-line) // > // Replacement (could be multi-line) // > // Explanation along with pattern referrents ($1, $2) (could be multi-line) // > // Topics: Topics for which this bug can used, comma separated. * for all // Languages: Languages for which this bug can be used, comma separated. * for all. // Type: Comma-separated two-tuples: language - type, where type is syntax, semantic or runtime error. // Last language MUST be * to signify remaining languages. // Proficiency: Comma-separated two-tuples: language - number, i.e., // number of problems correctly solved to consider the student proficient // Last language MUST be * to signify remaining languages. // Data types 1000 // integer - comma // real // char // boolean // string // enum // ... // // 100 - Arithmetic 1200 // 300 - Relational 1400 // 500 - Logical 1600 // 600 - Assignment 1800 // 1000 - Bitwise 2200 // 1100 - Miscellaneous 2400 // // 1200 - Variables 2600 // Symbolic constants 2800 // Arrays 3000 // Structures 3200 // Pointers 3400 // Reference variables 3600 // // Sequence 4000 // 1300 - Selection 4200 // 1400 - Switch 4400 // 1500 - while 4600 // 1600 - for 4800 // 1700 - do-while 5000 // 1800 - advanced loops 5200 // 2000 - functions 6000 // // 2200 - oop 7000 // ********************* Data Types - 1000 **************************** // 1000: integer; 1025: real; 1050: char; 1075: boolean // ----------------------- char 1050 ------------------------------------- // Using reluctant qualifier to force first occurrence of character to be modified # 1050 Data.Type.char.bug.doublequotes > ^(.*?)'(.{1})'(.*)$ > $1"$2"$3 > Character literal constant '$2' must be enclosed in single quotes, not double quotes. > Topics: * Languages: * Type: * - Syntax Proficiency: * - 2 // Test # 1051 Data.Type.char.bug.quotes > ^(.*?)'(.{1})'(.*)$ > $1$2$3 > Character literal constant '$2' must be enclosed in single quotes. > Topics: * Languages: * Type: * - Syntax Proficiency: * - 2 // Test // ----------------------- boolean 1075 ------------------------------------- # 1050 Data.Type.bool.bug.case > ^(.*)[^\w]true[^\w](.*)$ > $1True$2 > Boolean constant true must be written in all lower case. > Topics: * Languages: * Type: * - Syntax Proficiency: * - 2 // Test # 1051 Data.Type.bool.bug.case > ^(.*)[^\w]true[^\w](.*)$ > $1"true"$2 > Boolean constant true should not be enclosed in double quotes. > Topics: * Languages: * Type: * - Syntax Proficiency: * - 2 // Test # 1055 Data.Type.bool.bug.case > ^(.*)[^\w]false[^\w](.*)$ > $1False$2 > Boolean constant false must be written in all lower case. > Topics: * Languages: * Type: * - Syntax Proficiency: * - 2 // Test # 1056 Data.Type.bool.bug.case > ^(.*)[^\w]false[^\w](.*)$ > $1"false"$2 > Boolean constant false should not be enclosed in double quotes. > Topics: * Languages: * Type: * - Syntax Proficiency: * - 2 // Test // ********************* Arithmetic Operators - 1200 **************************** // +: 1200; -: 1225; *: 1250; /: 1275; %: 1300 // ----------------------- Addition + 1200 ------------------------------------- // Works for assignment // # 1200 // Arithmetic.bug.+.by.- // > // ^\s*(.*?)\s*=\s*(\w+)\s*\+\s*(.*)\s*;$ // > // $1 = $2 - $3; // > // $3 should be added to $2, not subtracted from it. // > // Topics: * // Languages: * // Type: * - Semantic // Proficiency: * - 2 // // Test # 1200 Arithmetic.bug.+.by.- > // ^(.*)\s+((\w+)\s+\+\s+(\w+))\s*(.*)$ ^(.*)\s+((\w+)\s+\+\s+(\w+))(.*)$ > $1 $3 - $4$5 > The operator between $3 and $4 should be addition, not subtraction. > Topics: * Languages: * Type: * - Semantic Proficiency: * - 2 // Test // ----------------------- Subtraction - 1225 ------------------------------------- # 1225 Arithmetic.bug.-.Commutative > ^\s*(\w*)\s*=\s*(\w*)\s*-\s*(\w*)\s*;$ > $1 = $3 - $2; > $1 is calculated by subtracting $3 from $2, not $2 from $3. > Topics: * Languages: * Type: * - Semantic Proficiency: * - 2 // Test # 1226 Arithmetic.bug.-.by.+ > // ^\s*(\w*)\s*=\s*(\w*)\s*-\s*(\w*)\s*;$ // Works for assignment ^(.*)\s+((\w+)\s+-\s+(\w+))(.*)$ > $1 $3 + $4$5 > The operator between $3 and $4 should be subtraction, not addition. > Topics: * Languages: * Type: * - Semantic Proficiency: * - 2 // Test // ----------------------- Multiplication * 1250 ------------------------------------- # 1250 Arithmetic.bug.*.by.x > // ^(.*)\*(.*)$ ^(.*)\s+((\w+)\s+\*\s+(\w+))(.*)$ > $1 $3 x $4$5 > The multiplication operator between $3 and $4 should be *, not x. > Topics: * Languages: * Type: * - Syntax Proficiency: * - 1 // Bug: this will not work with pointers # 1251 Arithmetic.bug.*.by./ > // ^\s*(.*?)\s*=\s*(\w+)\s*\*\s*(.*)\s*;$ ^(.*)\s+((\w+)\s+\*\s+(\w+))(.*)$ > $1 $3 / $4$5 > The operator between $3 and $4 should be multiplication, not division. > Topics: * Languages: * Type: * - Semantic Proficiency: * - 2 // Test // ----------------------- Division * 1275 ------------------------------------- # 1275 Arithmetic.bug./.Commutative > ^\s*(\w*)\s*=\s*(\w*)\s*/[^/\*]\s*(\w*)\s*;$ > $1 = $3 / $2; > $1 is calculated as $2 divided by $3, not $3 divided by $2. > Topics: * Languages: * Type: * - Semantic Proficiency: * - 2 // Test # 1276 Arithmetic.bug./.by.% > // ^\s*(.*?)\s*=\s*(\w+)\s*/[^/\*]\s*(.*)\s*;$ ^(.*)\s+((\w+)\s+/\s+(\w+))(.*)$ > $1 $3 % $4$5 > The operator between $3 and $4 should be division, not modulus. > Topics: * Languages: * Type: * - Semantic Proficiency: * - 2 # 1277 Arithmetic.bug./.by.* > // ^\s*(.*?)\s*=\s*(\w+)\s*/[^/\*]\s*(.*)\s*;$ ^(.*)\s+((\w+)\s+/\s+(\w+))(.*)$ > $1 $3 * $4$5 > The operator between $3 and $4 should be division, not multiplication. > Topics: * Languages: * Type: * - Semantic Proficiency: * - 2 // ----------------------- Remainder % 1300 ------------------------------------- // // Works for assignment expression, not expressions in while loop condition // # 1300 // Arithmetic.bug.%.by./ // > // ^\s*(.*?)\s*=\s*(\w+)\s*%\s*(.*)\s*;$ // > // $1 = $2 / $3; // > // The remainder of $2 divided by $3 should be assigned to $1, not the quotient. // > // Topics: * // Languages: * // Type: * - Semantic // Proficiency: * - 2 # 1300 Arithmetic.bug.%.by./ > // ^(.*)\s+((\w+)\s*%\s*(\w+))\s*(.*)$ // ^(.*)\s+((\w+)\s+%\s+(\w*?))\s*(.*)$ ^(.*)\s+((\w+)\s+%\s+(\w+))(.*)$ > $1 $3 / $4$5 > The operator between $3 and $4 should be remainder (%), not division(/). > Topics: * Languages: * Type: * - Semantic Proficiency: * - 2 # 1301 Arithmetic.bug.%.by.* > // ^(.*)\s+((\w+)\s*%\s*(\w+))\s*(.*)$ ^(.*)\s+((\w+)\s+%\s+(\w+))(.*)$ > $1 $3 * $4$5 > The operator between $3 and $4 should be remainder (%), not multiplication. > Topics: * Languages: * Type: * - Semantic Proficiency: * - 2 // ********************* Relational Operators - 1400 **************************** // <: 1400; <=: 1425; >: 1450; >=: 1475; ==: 1500; !=: 1525 // ------------------------ Less Than < (1400) ------------------------------------------- # 1400 Relational.bug.<.by.<=.if > // ^(\s*(for|while|if)\s*\(.*[^<])<([^<=].*)$ ^(\s*if\s*\(\s*(\w+)\s*)<(\s*(\w+)\s*\))$ > $1<=$3 > The if clause should be executed when $2 is less than $4, not also when $2 is equal to $4. > Topics: Selection Languages: * Type: * - Semantic Proficiency: * - 2 // OK, <<, <=, <<= will NOT trip this up # 1401 Relational.bug.<.by.>.if > ^(\s*if\s*\(\s*(\w+)\s*)<(\s*(\w+)\s*\))$ > $1>$3 > The if clause should be executed when $2 is less than $4, not greater than $4. > Topics: Selection Languages: * Type: * - Semantic Proficiency: * - 2 // OK, <<, <=, <<= will NOT trip this up # 1405 Relational.bug.<.by.<=.while > ^\s*while\s*\(\s*(\w+)\s*<\s*(\w+)\s*\)(.*)$ > while( $1 <= $2 )$3 > The loop should be executed when $1 is less than $2 > Topics: Pretest, PostTest Languages: * Type: * - Semantic Proficiency: * - 2 # 1406 Relational.bug.<.by.>.while > ^\s*while\s*\(\s*(\w+)\s*<\s*(\w+)\s*\)(.*)$ > while( $1 > $2 )$3 > The loop should be executed when $1 is less than $2 > Topics: Pretest, PostTest Languages: * Type: * - Semantic Proficiency: * - 2 // This will NOT match for loop, need a separate bug for for loop // 1410 # 1410 Relational.bug.<.by.<= > ^\s*(\w+)\s*[^<]<[^<=]\s*(\w+);$ > $1 <= $2; > $1 should be less than $2, not less than or equal to $2. > Topics: Counter Languages: * Type: * - Semantic Proficiency: * - 2 // OK, <<, <=, <<= will NOT trip this up # 1411 Relational.bug.<.by.> > ^\s*(\w+)\s*[^<]<[^<=]\s*(\w+);$ > $1 > $2; > $1 should be less than $2, not greater than $2. > Topics: Counter Languages: * Type: * - Semantic Proficiency: * - 2 // OK, <<, <=, <<= will NOT trip this up // -------------------------- Less Than or Equal To <= (1425) ---------------------------------- # 1425 Relational.bug.<=.space > // ^(\s*(while|if)\s*\(.*[^<])<=(.*)$ ^(.*[^<])<=(.*)$ > $1< =$2 > Space is not allowed within the relational operator <=. > // Topics: Selection, Pretest, PostTest Topics: * Languages: * Type: * - Syntax Proficiency: * - 1 // Test # 1430 Relational.bug.<=.by.<.if > ^(\s*if\s*\(\s*(\w+)\s*)<=(\s*(\w+)\s*\))$ > $1<$3 > The if clause should be executed even when $2 is equal to $4. > Topics: Selection Languages: * Type: * - Semantic Proficiency: * - 2 // OK, <<= will NOT trip this up # 1431 Relational.bug.<=.by.>=.if > ^(\s*if\s*\(\s*(\w+)\s*)<=(\s*(\w+)\s*\))$ > $1>=$3 > The if clause should be executed when $2 is less than or equal to $4. > Topics: Selection Languages: * Type: * - Semantic Proficiency: * - 2 // OK, <<= will NOT trip this up # 1435 Relational.bug.<=.by.<.while > ^\s*while\s*\(\s*(\w+)\s*<=\s*(\w+)\s*\)(.*)$ > while( $1 < $2 )$3 > The loop should be executed when $1 is less than or equal to $2 > Topics: Pretest, PostTest Languages: * Type: * - Semantic Proficiency: * - 2 # 1436 Relational.bug.<=.by.>=.while > ^\s*while\s*\(\s*(\w+)\s*<=\s*(\w+)\s*\)(.*)$ > while( $1 >= $2 )$3 > The loop should be executed when $1 is less than or equal to $2 > Topics: Pretest, PostTest Languages: * Type: * - Semantic Proficiency: * - 2 // Will not match a logical expression with relational operands # 1440 Relational.bug.<=.by.< > ^\s*(\w+)\s*[^<]<=\s*(\w+);$ > $1 < $2; > $1 should be less than or equal to $2, not less than $2. > Topics: Counter Languages: * Type: * - Semantic Proficiency: * - 2 // OK, <<, <=, <<= will NOT trip this up # 1441 Relational.bug.<=.by.>= > ^\s*(\w+)\s*[^<]<=\s*(\w+);$ > $1 >= $2; > $1 should be less than or equal to $2, not greater than or equal to $2. > Topics: Counter Languages: * Type: * - Semantic Proficiency: * - 2 // OK, <<, <=, <<= will NOT trip this up // --------------------------- Greater Than > (1450) ----------------------------------- # 1450 Relational.bug.>.by.>=.if > ^(\s*if\s*\(\s*(\w+)\s*)>(\s*(\w+)\s*\))$ > $1>=$3 > The if clause should be executed when $2 is greater than $4, not also when $2 is equal to $4. > Topics: Selection Languages: * Type: * - Semantic Proficiency: * - 2 // OK, >=, >>, >>= will NOT trip this up # 1451 Relational.bug.>.by.<.if > ^(\s*if\s*\(\s*(\w+)\s*)>(\s*(\w+)\s*\))$ > $1<$3 > The if clause should be executed when $2 is greater than $4, not less than $4. > Topics: Selection Languages: * Type: * - Semantic Proficiency: * - 2 // OK, >=, >>, >>= will NOT trip this up # 1455 Relational.bug.>.by.>=.while > ^\s*while\s*\(\s*(\w+)\s*>\s*(\w+)\s*\)(.*)$ > while( $1 >= $2 )$3 > The loop should be executed when $1 is greater than $2 > Topics: Pretest, PostTest Languages: * Type: * - Semantic Proficiency: * - 2 # 1456 Relational.bug.>.by.<.while > ^\s*while\s*\(\s*(\w+)\s*>\s*(\w+)\s*\)(.*)$ > while( $1 < $2 )$3 > The loop should be executed when $1 is greater than $2 > Topics: Pretest, PostTest Languages: * Type: * - Semantic Proficiency: * - 2 // This will NOT match for loop, need a separate bug for for loop # 1460 Relational.bug.>.by.>= > ^\s*(\w+)\s*[^>]>[^>=]\s*(\w+);$ > $1 >= $2; > $1 should be greater than $2, not greater than or equal to $2. > Topics: Counter Languages: * Type: * - Semantic Proficiency: * - 2 # 1461 Relational.bug.>.by.< > ^\s*(\w+)\s*[^>]>[^>=]\s*(\w+);$ > $1 < $2; > $1 should be greater than $2, not less than $2. > Topics: Counter Languages: * Type: * - Semantic Proficiency: * - 2 // ---------------------------- Greater Than or Equal To >= (1475) ------------------------------ # 1475 Relational.bug.>=.space > // ^(\s*(while|if)\s*\(.*[^>])>=(.*)$ ^(.*[^>])>=(.*)$ > $1> =$2 > Space is not allowed within the relational operator >=. > // Topics: Selection, Pretest, PostTest Topics: * Languages: * Type: * - Syntax Proficiency: * - 1 // Test # 1480 Relational.bug.>=.by.>.if > ^(\s*if\s*\(\s*(\w+)\s*)>=(\s*(\w+)\s*\))$ > $1>$3 > The if clause should be executed even when $2 is equal to $4. > Topics: Selection Languages: * Type: * - Semantic Proficiency: * - 2 // OK, >>= will NOT trip this up # 1481 Relational.bug.>=.by.<=.if > ^(\s*if\s*\(\s*(\w+)\s*)>=(\s*(\w+)\s*\))$ > $1<=$3 > The if clause should be executed when $2 is greater than or equal to $4. > Topics: Selection Languages: * Type: * - Semantic Proficiency: * - 2 // OK, >>= will NOT trip this up # 1485 Relational.bug.>=.by.>.while > ^\s*while\s*\(\s*(\w+)\s*>=\s*(\w+)\s*\)(.*)$ > while( $1 > $2 )$3 > The loop should be executed when $1 is greater than or equal to $2 > Topics: Pretest, PostTest Languages: * Type: * - Semantic Proficiency: * - 2 # 1486 Relational.bug.>=.by.<=.while > ^\s*while\s*\(\s*(\w+)\s*>=\s*(\w+)\s*\)(.*)$ > while( $1 <= $2 )$3 > The loop should be executed when $1 is greater than or equal to $2 > Topics: Pretest, PostTest Languages: * Type: * - Semantic Proficiency: * - 2 // Will not match a logical expression with relational operands # 1490 Relational.bug.>=.by.> > ^\s*(\w+)\s*[^>]>=\s*(\w+);$ > $1 > $2; > $1 should be greater than or equal to $2, not greater than $2. > Topics: Counter Languages: * Type: * - Semantic Proficiency: * - 2 # 1491 Relational.bug.>=.by.<= > ^\s*(\w+)\s*[^>]>=\s*(\w+);$ > $1 <= $2; > $1 should be greater than or equal to $2, not less than or equal to $2. > Topics: Counter Languages: * Type: * - Semantic Proficiency: * - 2 // ----------------------------- Equal To == ----------------------------------------- // Using reluctant qualifier to force first comparison to be replaced # 1500 Relational.bug.==.by.= > // ^(.*?)==(.*)$ ^(.*)\s+((\w+)\s+==\s+(\w+))(.*)$ > // $1=$2 $1 $3 = $4$5 > = is assignment operator. Use == operator between $3 and $4 to compare > Topics: * Languages: * Type: Java - Syntax, * - Semantic Proficiency: Java - 2, * - 4 // Redo for if, loops? Do not - behavior not same for C++ vs Java, so // any feedback you provide will not be correct for both languages // Test // Using reluctant qualifier to force first comparison to be replaced # 1501 Relational.bug.==.space > ^(.*?)==(.*)$ > $1= =$2 > Space is not allowed within comparison operator ==. > Topics: * Languages: * Type: * - Syntax Proficiency: * - 1 // Test # 1505 Relational.bug.==.by.!=.if > // ^(\s*if\s*\(\s*(\w+)\s*)==(\s*(\w+)\s*\))$ ^(\s*if\s*\(\s*([^\(].+?)\s*)==(\s*(.+)\s*\))$ > $1!=$3 > The if clause should be executed when $2 is equal to $4. > Topics: Selection Languages: * Type: * - Semantic Proficiency: * - 2 // OK, >>= will NOT trip this up # 1510 Relational.bug.==.by.!=.while > // ^\s*while\s*\(\s*(\w+)\s*==\s*(\w+)\s*\)(.*)$ ^\s*while\s*\(\s*([^\(].+?)\s*==\s*(.+)\s*\)(.*)$ > while( $1 != $2 )$3 > The loop should be executed when $1 is equal to $2 > Topics: Pretest, PostTest Languages: * Type: * - Semantic Proficiency: * - 2 // Did not include a pattern for general expression, as used in for loop condition - // not sure it is useful // ----------------------------- Not Equal To != ----------------------------------- // Using reluctant qualifier to force first comparison to be replaced # 1525 Relational.bug.!=.space > ^(.*?)!=(.*)$ > $1! =$2 > Space is not allowed within comparison operator !=. > Topics: * Languages: * Type: * - Syntax Proficiency: * - 1 // Test # 1530 Relational.bug.!=.by.==.if > ^(\s*if\s*\(\s*([^\(].+?)\s*)!=(\s*(.+)\s*\))$ > $1==$3 > The if clause should be executed when $2 is NOT equal to $4. > Topics: Selection Languages: * Type: * - Semantic Proficiency: * - 2 // OK, >>= will NOT trip this up // We exclude parenthesized conditions for now to make explanation on the mark # 1535 Relational.bug.!=.by.==.while > // ^\s*while\s*\(\s*(\w+)\s*!=\s*(\w+)\s*\)(.*)$ ^\s*while\s*\(\s*([^\(].+?)\s*!=\s*(.+)\s*\)(.*)$ > while( $1 == $2 )$3 > The loop should be executed when $1 is NOT equal to $2 > Topics: Pretest, PostTest Languages: * Type: * - Semantic Proficiency: * - 2 // Did not include a pattern for general expression, as used in for loop condition - // not sure it is useful // ********************* Logical Operators - 1600 **************************** // &&: 1600; ||: 1625; !: 1650; ^:1675 // ----------------------------- And && ----------------------------------- # 1600 Logical.bug.&&.space > ^(\s*(while|if)\s*\(.*?)&&(.*)$ > $1& &$3 > Space is not allowed within logical operator &&. > Topics: Selection, Pretest, PostTest Languages: * Type: * - Syntax Proficiency: * - 1 // Test // Works, but explanation is less focused // # 1601 // Logical.bug.&&.by.|| // > // ^\s*(for|while|if)\s*\(\s*!\s*\(\s*(.*)&&(.*)$ // > // $1( ! ( $2\|\|$3 // > // The condition in $1 after $2 should be &&, not || // > // Topics: * // Languages: * // Type: * - Syntax // Proficiency: * - 1 // // Test // Two cases for when the entire condition is negated # 1601 Logical.bug.&&.by.|| > ^\s*(while|if)\s*\(\s*!\s*\(\s*(.*?)&&(.*)\s*\)\s*\)(.*)$ > $1( ! ( $2\|\|$3 ) )$4 > // The condition in $1 between $2 and $3 should be &&, not || The operator after $2 should be &&, not || > Topics: Selection, Pretest, PostTest Languages: * Type: * - Semantic Proficiency: * - 2 // The commented explanation works best for two conjuncts # 1602 Logical.bug.&&.by.& > ^\s*(while|if)\s*\(\s*!\s*\(\s*(.*?)&&(.*)\s*\)\s*\)(.*)$ > $1( ! ( $2&$3 ) )$4 > // The condition in $1 between $2 and $3 should be logical &&, not bitwise & The operator after $2 should be logical &&, not bitwise & > Topics: Selection, Pretest, PostTest Languages: * Type: * - Semantic Proficiency: * - 1 // The commented explanation works best for two conjuncts // Two cases for when the entire condition is not negated # 1603 Logical.bug.&&.by.|| > ^\s*(while|if)\s*\(\s*([^!].*?)&&(.*)\s*\)(.*)$ > $1( $2\|\|$3 )$4 > // The condition in $1 between $2 and $3 should be &&, not & The operator after $2 should be &&, not || > Topics: Selection, Pretest, PostTest Languages: * Type: * - Semantic Proficiency: * - 2 // Test # 1604 Logical.bug.&&.by.& > ^\s*(while|if)\s*\(\s*([^!].*?)&&(.*)\s*\)(.*)$ > $1( $2&$3 )$4 > // The condition in $1 between $2 and $3 should be &&, not & The operator after $2 should be logical &&, not bitwise & > Topics: Selection, Pretest, PostTest Languages: * Type: * - Semantic Proficiency: * - 1 // Test // ----------------------------- Or || ----------------------------------- # 1625 Logical.bug.||.space > ^(\s*(while|if)\s*\(.*?)\|\|(.*)$ > $1\| \|$3 > Space is not allowed within logical operator ||. > Topics: Selection, Pretest, PostTest Languages: * Type: * - Syntax Proficiency: * - 1 // Test // Two cases for when the entire condition is negated # 1626 Logical.bug.||.by.&& > ^\s*(while|if)\s*\(\s*!\s*\(\s*(.*?)\|\|(.*)\s*\)\s*\)(.*)$ > $1( ! ( $2&&$3 ) )$4 > // The condition in $1 between $2 and $3 should be ||, not && The operator after $2 should be ||, not && > Topics: Selection, Pretest, PostTest Languages: * Type: * - Semantic Proficiency: * - 2 // The commented explanation works best for two conjuncts # 1627 Logical.bug.||.by.| > ^\s*(while|if)\s*\(\s*!\s*\(\s*(.*?)\|\|(.*)\s*\)\s*\)(.*)$ > $1( ! ( $2\|$3 ) )$4 > // The condition in $1 between $2 and $3 should be logical ||, not bitwise | The operator after $2 should be logical ||, not bitwise | > Topics: Selection, Pretest, PostTest Languages: * Type: * - Semantic Proficiency: * - 1 // The commented explanation works best for two conjuncts // Two cases for when the entire condition is not negated # 1628 Logical.bug.||.by.&& > ^\s*(while|if)\s*\(\s*([^!].*?)\|\|(.*)\s*\)(.*)$ > $1( $2&&$3 )$4 > // The condition in $1 between $2 and $3 should be ||, not && The operator after $2 should be ||, not && > Topics: Selection, Pretest, PostTest Languages: * Type: * - Semantic Proficiency: * - 2 // Test # 1629 Logical.bug.||.by.| > ^\s*(while|if)\s*\(\s*([^!].*?)\|\|(.*)\s*\)(.*)$ > $1( $2\|$3 )$4 > // The condition in $1 between $2 and $3 should be ||, not | The operator after $2 should be logical ||, not bitwise | > Topics: Selection, Pretest, PostTest Languages: * Type: * - Semantic Proficiency: * - 1 // Test // ----------------------------- Not ! ----------------------------------- // When applied to parenthesized expression, drops parentheses also # 1650 Logical.bug.!.missing > ^\s*(while|if)\s*\((.*)\s*![^=]\s*\(\s*(.*)\s*\)(.*)\)(.*)$ > $1( $2 $3 $4 )$5 > $3 should be negated > Topics: Selection, Pretest, PostTest Languages: * Type: * - Semantic Proficiency: * - 2 // Accounts for !(a && b), !(a && b) || c, a && !( b || c) // When applied to non-parenthesized expression # 1651 Logical.bug.!.missing > ^\s*(while|if)\s*\((.*)\s*![^=]\s*([^\(].*)\)(.*)$ > $1( $2 $3 )$4 > Negation operator ! must appear before $3 > Topics: Selection, Pretest, PostTest Languages: * Type: * - Semantic Proficiency: * - 2 // ********************* Assignment Operators - 1800 **************************** // =: 1800; // +=: 1825 -=: 1850; *=: 1875; /=: 1900; %=: 1925; &=: 1950; |=: 1975; ^=: 2000; // <<=: 2025; >>=: 2050; // ++prefix: 2075; ++postfix: 2100; --prefix: 2125; --postfix: 2150 // ------------------------------ Simple Assignment - 1800 -------------------------------- # 1800 Assignment.bug.=.by.== > ^(\s*(\w+)\s*[^<>!=+-\\*/%&\|\^])=([^=].*)$ > $1==$3 > == is comparison operator. Use = operator to assign to $2 > Topics: * Languages: * Type: * - Semantic Proficiency: * - 2 // OK, ==, <=, >=, != will NOT trip this up // Re-Test # 1801 Assignment.bug.lhs.by.rhs > // ^(\s*(\w+)\s*)=([^=].*[^\s])\s*;$ ^(\s*(\w+)\s*)[^<>!=+-\\*/%&|\^]=[^=]\s*(.*)\s*;$ > $3 = $2; > Variable to which assignment is made ($2) must appear on the left hand side of the assignment operator = > Topics: * Languages: * Type: * - Semantic Proficiency: * - 2 // Re-Test // ------------------------------ Compound Assignment += - 1825 -------------------------------- # 1825 Assignment.bug.+=.space > ^(.*)\+=(.*)$ > $1+ =$2 > Space is not allowed within the assignment operator +=. > Topics: * Languages: * Type: * - Syntax Proficiency: * - 1 // ------------------------------ Compound Assignment -= - 1850 -------------------------------- # 1850 Assignment.bug.-=.space > ^(.*)-=(.*)$ > $1- =$2 > Space is not allowed within the assignment operator -=. > Topics: * Languages: * Type: * - Syntax Proficiency: * - 1 // ------------------------------ Compound Assignment *= - 1875 -------------------------------- # 1875 Assignment.bug.*=.space > ^(.*)\*=(.*)$ > $1* =$2 > Space is not allowed within the assignment operator *=. > Topics: * Languages: * Type: * - Syntax Proficiency: * - 1 // ------------------------------ Compound Assignment /= - 1900 -------------------------------- # 1900 Assignment.bug./=.space > ^(.*)/=(.*)$ > $1/ =$2 > Space is not allowed within the assignment operator /=. > Topics: * Languages: * Type: * - Syntax Proficiency: * - 1 // ------------------------------ Compound Assignment %= - 1925 -------------------------------- // ------------------------------ Compound Assignment &= - 1950 -------------------------------- // ------------------------------ Compound Assignment |= - 1975 -------------------------------- // ------------------------------ Compound Assignment ^= - 2000 -------------------------------- // ------------------------------ Compound Assignment <<= - 2025 -------------------------------- // ------------------------------ Compound Assignment >>= - 2050 -------------------------------- // ------------------------------ Prefix Increment - 2075 -------------------------------- # 2075 Assignment.Prefix.++.by.-- > ^(.*)\+\+\s*(\w+)(.*)$ > $1-- $2$3 > $2 should be incremented, not decremented. > Topics: * Languages: * Type: * - Semantic Proficiency: * - 2 # 2076 Assignment.Prefix.++.space > ^(.*)\+\+\s*(\w+)(.*)$ > $1+ + $2$3 > Space is not allowed within prefix increment operator ++. > Topics: * Languages: * Type: * - Syntax Proficiency: * - 1 // TO DO Could introduce replacing prefix ++ by postfix ++, but must make sure return value is used // and the pattern does not clash with 2075 // ------------------------------ Postfix Increment - 2100 -------------------------------- # 2100 Assignment.Postfix.++.by.-- > ^(.*)(\w+)\s*\+\+(.*)$ > $1$2 --$3 > $2 should be incremented, not decremented. > Topics: * Languages: * Type: * - Semantic Proficiency: * - 2 # 2101 Assignment.Postfix.++.space > ^(.*)(\w+)\s*\+\+(.*)$ > $1$2 + +$3 > Space is not allowed within postfix increment operator ++. > Topics: * Languages: * Type: * - Syntax Proficiency: * - 1 // TO DO Could introduce replacing postfix ++ by prefix ++, but must make sure return value is used // and the pattern does not clash with 2100 // ------------------------------ Prefix Decrement - 2125 -------------------------------- # 2125 Assignment.Prefix.--.by.++ > ^(.*)--\s*(\w+)(.*)$ > $1++ $2$3 > $2 should be decremented, not incremented. > Topics: * Languages: * Type: * - Semantic Proficiency: * - 2 # 2126 Assignment.Prefix.--.space > ^(.*)--\s*(\w+)(.*)$ > $1- - $2$3 > Space is not allowed within prefix decrement operator --. > Topics: * Languages: * Type: * - Syntax Proficiency: * - 1 // TO DO Could introduce replacing prefix -- by postfix --, but must make sure return value is used // and the pattern does not clash with 2125 // ------------------------------ Postfix Decrement - 2150 -------------------------------- # 2150 Assignment.Postfix.--.by.++ > ^(.*)(\w+)\s*--(.*)$ > $1$2 ++$3 > $2 should be decremented, not incremented. > Topics: * Languages: * Type: * - Semantic Proficiency: * - 2 # 2151 Assignment.Postfix.--.space > ^(.*)(\w+)\s*--(.*)$ > $1$2 - -$3 > Space is not allowed within postfix decrement operator --. > Topics: * Languages: * Type: * - Syntax Proficiency: * - 1 // TO DO Could introduce replacing postfix -- by prefix --, but must make sure return value is used // and the pattern does not clash with 2150 // ********************* Bitwise Operators - 2200 **************************** // &: 2200; |: 2225; ~: 2250; ^: 2275 // ********************* Miscellaneous Operators - 2400 **************************** // ,: 2400; ?:: 2425; <<: 2450, >>: 2475 # 2450 Output.bug.<<.by.>> > ^(\s*cout\s*)<<(.*)$ > $1>>$2 > Stream insertion operator used for output is << and not >> > Topics: * Languages: C++ Type: * - Syntax Proficiency: * - 2 // Test # 2451 Output.bug.<<.space > ^(\s*cout\s*)<<(.*)$ > $1< <$2 > Space is not allowed within the stream insertion operator << > Topics: * Languages: C++ Type: * - Syntax Proficiency: * - 1 // Test # 2452 Output.cout.case > ^(\s*cout\s*)<<(.*)$ > Cout <<$2 > Output stream cout is spelled in all lowercase > Topics: * Languages: C++ Type: * - Syntax Proficiency: * - 1 // Test # 2475 Input.bug.>>.by.<< > ^(\s*cin\s*)>>(.*)$ > $1<<$2 > Stream extraction operator used for input is >> and not << > Topics: * Languages: C++ Type: * - Syntax Proficiency: * - 2 // Test # 2476 Input.bug.>>.space > ^(\s*cin\s*)>>(.*)$ > $1> >$2 > Space is not allowed within the stream extraction operator >> > Topics: * Languages: C++ Type: * - Syntax Proficiency: * - 1 // Test # 2477 Input.cin.case > ^(\s*cin\s*)>>(.*)$ > Cin >>$2 > Input stream cin is spelled in all lowercase > Topics: * Languages: C++ Type: * - Syntax Proficiency: * - 1 // Test // ********************* Variables - 2600 **************************** # 2600 Declaration.bug.=.by.== > // ^((short|int|long|float|double|char|bool|boolean)\s+)(\w+[^<>!=])=([^=].*)$ ^(\s*(short|int|long|float|double|char|bool|boolean)\s+(\w+)\s*)=([^=].*)$ > $1==$4 > == is comparison operator. Use = operator to initialize $3 during declaration > Topics: * Languages: * Type: * - Semantic Proficiency: * - 2 // OK, ==, <=, >=, != will NOT trip this up // Retest # 2601 Declaration.bug.=.by.== > // ^((unsigned|signed)\s+)((short|int|long|char)\s+)(\w+[^<>!=])=([^=].*)$ ^(\s*(unsigned|signed)\s+(short|int|long|char)\s+(\w+)\s*)=([^=].*)$ > $1==$5 > == is comparison operator. Use = operator to initialize $4 during declaration > Topics: * Languages: * Type: * - Semantic Proficiency: * - 2 // OK, ==, <=, >=, != will NOT trip this up // Retest // ********************* arrays - 3000 **************************** // ********************* Pointers - 3400 **************************** // ********************* Simple Statements - 4000 **************************** # 4000 statement.simple.semimcolon.missing > ^(.*);$ > $1 > Every statement must end with a semi-colon ; > Topics: * Languages: * Type: * - Syntax Proficiency: * - 2 // Test // ********************* if/if-else Statements - 4200 **************************** // if: 4200; else: 4225; # 4200 ifElse.bug.if.semicolon > ^(\s*if\s*\(.*\))$ > $1; > Semi-colon after if is an empty statement which becomes the if clause. As a result, the statement(s) after if will be executed whether or not the condition is true. > Topics: Selection Languages: * Type: * - Semantics Proficiency: * - 2 // Technically, this can be semantic (if statement only) or syntax error (if-else statement) // Test # 4201 ifElse.bug.if.().missing > ^(\s*if\s*)\((.*)\)$ > $1 $2 > Parentheses () around the condition of if statement are missing. > Topics: Selection Languages: * Type: * - Syntax Proficiency: * - 1 // Test # 4202 ifElse.bug.if.case > ^\s*if\s*(\(.*\))$ > If $1 > if keyword must be written in all lower case. > Topics: Selection Languages: * Type: * - Syntax Proficiency: * - 1 // Test # 4203 ifElse.bug.if.colon > ^(\s*if\s*\(.*\))$ > $1: > if statement should not end with a colon. > Topics: Selection Languages: * Type: * - Syntax Proficiency: * - 2 // Test # 4225 ifElse.bug.else.semicolon > ^(\s*)else(\s*)$ > $1else;$2 > Semi-colon after else becomes the empty else clause, which is incorrect in this program. > Topics: Selection Languages: * Type: * - Semantics Proficiency: * - 2 // Test # 4226 ifElse.bug.else.case > ^(\s*)else(\s*)$ > $1Else$2 > else is a keyword that must be written in all lowercase. > Topics: Selection Languages: * Type: * - Syntax Proficiency: * - 1 // Test # 4227 ifElse.bug.else.colon > ^(\s*)else(\s*)$ > $1else:$2 > else should not end with a colon. > Topics: Selection Languages: * Type: * - Syntax Proficiency: * - 2 // Test // ********************* switch Statements - 4400 **************************** // switch: 4400; case: 4425; break: 4450; default: 4475 # 4400 Switch.bug.semicolon > ^(\s*switch\s*\(.*\))$ > $1; > The semi-colon after the switch acts as the body of the switch, resulting in a syntax error. > Topics: Switch Languages: * Type: * - Syntax Proficiency: * - 2 // Test # 4401 Switch.bug.colon > ^(\s*switch\s*\(.*\))$ > $1: > There should be no colon after the switch statement. > Topics: Switch Languages: * Type: * - Syntax Proficiency: * - 2 // Test # 4402 Switch.bug.parentheses > ^(\s*switch\s*\((.*)\))$ > switch $2 > The condition of the switch must be enclosed in parentheses. > Topics: Switch Languages: * Type: * - Syntax Proficiency: * - 2 // Test # 4403 Switch.bug.case > ^(\s*switch\s*\((.*)\))$ > Switch( $2 ) > switch should be written in all lowercase. > Topics: Switch Languages: * Type: * - Syntax Proficiency: * - 2 // Test # 4425 Switch.case.bug.colon > ^(\s*case\s*(.*):)$ > case $2 > The case statement must end with a colon. > Topics: Switch Languages: * Type: * - Syntax Proficiency: * - 2 // Test # 4426 Switch.case.bug.semicolon > ^(\s*case\s*(.*):)$ > case $2; > The case statement must end with a colon, not a semi-colon. > Topics: Switch Languages: * Type: * - Syntax Proficiency: * - 2 // Test # 4427 Switch.case.bug.space > ^(\s*case\s*(\w*):)$ > case$2: > At least one space must appear between case and $2. > Topics: Switch Languages: * Type: * - Syntax Proficiency: * - 2 // Test # 4428 Switch.case.bug.case > ^(\s*case\s*(.*):)$ > Case $2: > case should be written in all lowercase. > Topics: Switch Languages: * Type: * - Syntax Proficiency: * - 2 // Test // TO DO - Case with a value not existent in the code? # 4450 Switch.break.bug.colon > ^(\s*break\s*;)$ > break: > break statement must end with a semi-colon, not a colon. > Topics: Switch Languages: * Type: * - Syntax Proficiency: * - 2 // Test # 4451 Switch.break.bug.case > ^(\s*break\s*;)$ > Break; > break must be written in all lowercase. > Topics: Switch Languages: * Type: * - Syntax Proficiency: * - 2 // Test # 4475 Switch.default.bug.colon > ^(\s*default\s*:)$ > default > The default statement must end with a colon. > Topics: Switch Languages: * Type: * - Syntax Proficiency: * - 2 // Test # 4476 Switch.default.bug.semicolon > ^(\s*default\s*:)$ > default; > The default statement must end with a colon, not a semi-colon. > Topics: Switch Languages: * Type: * - Syntax Proficiency: * - 2 // Test # 4477 Switch.default.bug.case > ^(\s*default\s*:)$ > Default: > default must be written in all lowercase. > Topics: Switch Languages: * Type: * - Syntax Proficiency: * - 1 // Test // ********************* while loops - 4600 **************************** // This matches only while, not do-while because we provide no characters after ) # 4600 Pretest.bug.semicolon > // ^(\s*while\s*\(.*\)[^;])$ ^\s*while\s*\((.*?)\)$ > while($1); > The semi-colon after the loop makes this an infinite loop > Topics: Pretest, PostTest Languages: * Type: * - Semantic Proficiency: * - 2 // Test # 4601 Pretest.bug.case > ^\s*while\s*(.*)$ > While$1 > while must be written in all lowercase. > Topics: Pretest, PostTest Languages: * Type: * - Syntax Proficiency: * - 1 # 4602 Pretest.bug.parentheses > ^\s*while\s*\((.*)\)(.*)$ > while $1 $2 > The condition of the loop must be enclosed in parentheses. > Topics: Pretest, PostTest Languages: * Type: * - Syntax Proficiency: * - 1 // Test # 4603 Pretest.bug.colon > ^\s*while\s*\((.*)\)(.*)$ > while($1):$2 > There should be no colon after the while loop. > Topics: Pretest, PostTest Languages: * Type: * - Syntax Proficiency: * - 1 // Test // ********************* for loops - 4800 **************************** # 4800 Counter.bug.semicolon > ^\s*for\s*\((.*);$ > for($1 > A semi-colon must appear after initialization in for loop > Topics: Counter Languages: * Type: * - Syntax Proficiency: * - 1 // Test # 4801 Counter.bug.;.by.: > ^\s*for\s*\((.*);$ > for($1: > After initialization in for loop, a semi-colon must appear, and not colon. > Topics: Counter Languages: * Type: * - Syntax Proficiency: * - 1 // Test # 4802 Counter.bug.;.by., > ^\s*for\s*\((.*);$ > for($1, > After initialization in for loop, a semi-colon must appear, and not comma. > Topics: Counter Languages: * Type: * - Syntax Proficiency: * - 1 // Test # 4803 Counter.bug.case > ^\s*for\s*(\(.*)$ > For$1 > for must be written in all lowercase. > Topics: Counter Languages: * Type: * - Syntax Proficiency: * - 1 # 4804 Counter.bug.parentheses > ^\s*for\s*\((.*)$ > for $1 > Initialization expression in for loop must be enclosed in parentheses. > Topics: Counter Languages: * Type: * - Syntax Proficiency: * - 1 // Test // ********************* do-while loops - 5000 **************************** // ********************* advanced loop concepts - 5200 **************************** // ********************* functions - 6000 **************************** // ********************* OOP - 7000 ****************************