Syntax?

I do not understand what syntax is. Please explain.
Syntax is the rules to C++ that define how we have to do things. For example:
int myInt; is a way of declaring an int, it follows this syntax:
datatype variablename;

Over the years, more and more syntax has been added to language to incorporate new features or syntax has been expanded to allow more options when defining things.

I don't have an actual definition of what syntax is, but maybe someone else can explain it better or even wikipedia (always seems to have the answers).
A specific way of writing a particular part of a code to declare variables,accessing functions or to accomplish any task in c++ is what i call syntax. It may not be the exact definition but u might have got the idea of it...
I think that next your question shall be Symantic?:)
Last edited on
syntax is a set of defined rules and standards for any given language.
this includes english, c++, perl, french, spanish, latin, python, etc..
The format of the program example:

1
2
3
4
5
6
7
int main()
{ // Shows where function begins
      code....
      ......
      ......
      return 0;
} // Shows where function ends. 
closed account (j2NvC542)
Why so complicated? It's word order, people. Grammar.
Last edited on
maybe someone else can explain it better or even wikipedia

Wikipedia is actually pretty easy to understand here:

"the syntax of a programming language is the set of rules that define the combinations of symbols that are considered to be correctly structured programs in that language"

it also has simple examples that contrast syntax and semantics at http://en.wikipedia.org/wiki/Syntax_(programming_languages)#Syntax_versus_semantics
Good syntax:
I do not understand what syntax is. Please explain.


Bad syntax:
not explain is .. syntax understand do Please I what


Syntax is the proper use of a language. Actually, having proper syntax is something inherent to all humans (unless a disorder is present).
Last edited on
or you are trying to be like yoda, who has very bad english syntax
syntax simply means the way something(or a code) is organized.
eg: for a structure:
1
2
3
struct identifier {
    members
};
Syntax is a form, symantic is a meaning.:)
Fine Yoda speaks. "I am good", "Good I am", and "Good am I" all use syntax properly. It's when you start to put words in the wrong order that you see bad syntax: "I good am", "Am good I". The final iteration changes the meaning, but still proper: "Am I good".

"Fine Yoda speaks" is a little confusing though, because you don't know if Yoda speaks fine or if there is something called a "Fine Yoda". We might write "Yoda speaks fine", but we could also do "Fine speaks Yoda" without issue. The problem word is the adjective, you can not have the adjective in the middle or your noun and verb.
Last edited on
Syntax is to programming as to grammer is to English
I can't quite think of a polite way to say this, but that's just not correct. Grammar defines a syntax, no matter what language. They call these programming languages for a reason. A piece of code: int x = a;, basically says "make an integer named "x" and assign it the value of "a"". You can't do int x a =; because this says "Make an integer named "x" and value of "a" assign it". That sentence doesn't make sense, it isn't following syntax rules.

Edit: My nonsense sentence makes a little bit of sense though, perhaps if we changed the grammar of c++ we could do something like that.
Last edited on
Definition taken from Webster's dictionary.
syn·tax
   [sin-taks]
noun
1.
Linguistics .
a.
the study of the rules for the formation of grammatical sentences in a language.
b.
the study of the patterns of formation of sentences and phrases from words.
c.
the rules or patterns so studied: English syntax.
Last edited on
Topic archived. No new replies allowed.