Syntax Error Help

Hi, I am in my first Computer Science class in college, and we are doing an exercise that asks to create syntax errors, logic errors, and runtime errors, and document what appears when we get each kind of error. I have already done everything I need for the logic and runtime errors, but my problem occurs when I create syntax errors. If I'm correct, a syntax error means that there is an error in the coding language. For example, if I remove a semicolon from the code, and attempt to run the program, the words "syntax error etc etc etc" should appear right? Well all that is appearing is the typical "error" message showing what is wrong and what line it is within. I believe I need for the actual words "Syntax error" to appear. Any ideas? Thanks.
Which compiler/environment are you programming in?

Edit: Actually, you can get a whole array of errors from missing out syntax...

Just from missing out a bracket:
C:\Users\Owner\Documents\cpp programs\tempforumhelp.cpp:5: error: expected primary-expression before 'int'
C:\Users\Owner\Documents\cpp programs\tempforumhelp.cpp:5: error: expected '}' before 'int'
C:\Users\Owner\Documents\cpp programs\tempforumhelp.cpp:5: error: expected ')' before 'int'
C:\Users\Owner\Documents\cpp programs\tempforumhelp.cpp:6: error: expected unqualified-id before 'return'
C:\Users\Owner\Documents\cpp programs\tempforumhelp.cpp:7: error: expected declaration before '}' token

All syntax errors. Hard as I try, nothing on Code::Blocks is saying 'syntax error' though (I assume because it's impossible).
Last edited on
I believe I need for the actual words "Syntax error" to appear.

I believe you're taking that too literally.

Compilers generally report two things: Errors and Warnings. Syntax errors that prevent compilation are Errors.
g++ compiler

This is the exact code I put in

#include <iostream>
using namespace std;
int main( )
// Declarations
int a, b, c;

// Input
cout << "Enter two integers\n";
cin >> a >> b;

// Processing
c = a + b;

// Output
cout << "The sum is " << c << "\n";


And when I omit a semicolon (for this example I removed the semicolon after int a, b, c;) and try to run the program this exact message appears

exercise3.cpp: In function ‘int main()’:
exercise3.cpp:9: error: expected initializer before ‘cout’
exercise3.cpp:13: error: ‘c’ was not declared in this scope

And I'm wondering if the error needs to literally say "syntax error". Maybe I am taking it too literally but in the book it appears to actually say it.
If the compiler simply siad "syntax error", that wouldn't be very helpful. Compilers detect hundreds of different syntax errors and try to give you as explicit message as they can as to what it thinks the error is or at least what it was expecting.
Topic archived. No new replies allowed.