Syntax?

Aug 10, 2012 at 1:04am
I do not understand what syntax is. Please explain.
Aug 10, 2012 at 1:11am
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).
Aug 10, 2012 at 8:33pm
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...
Aug 10, 2012 at 8:49pm
I think that next your question shall be Symantic?:)
Last edited on Aug 10, 2012 at 8:50pm
Aug 10, 2012 at 9:11pm
syntax is a set of defined rules and standards for any given language.
Aug 10, 2012 at 9:11pm
this includes english, c++, perl, french, spanish, latin, python, etc..
Aug 10, 2012 at 9:18pm
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. 
Aug 10, 2012 at 9:24pm
closed account (j2NvC542)
Why so complicated? It's word order, people. Grammar.
Last edited on Aug 10, 2012 at 9:27pm
Aug 10, 2012 at 9:47pm
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
Aug 10, 2012 at 11:20pm
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 Aug 10, 2012 at 11:26pm
Aug 11, 2012 at 4:18pm
or you are trying to be like yoda, who has very bad english syntax
Aug 11, 2012 at 5:02pm
syntax simply means the way something(or a code) is organized.
eg: for a structure:
1
2
3
struct identifier {
    members
};
Aug 11, 2012 at 5:24pm
Syntax is a form, symantic is a meaning.:)
Aug 11, 2012 at 5:58pm
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 Aug 11, 2012 at 6:01pm
Aug 11, 2012 at 9:03pm
Syntax is to programming as to grammer is to English
Aug 11, 2012 at 11:22pm
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 Aug 11, 2012 at 11:26pm
Aug 14, 2012 at 3:57pm
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 Aug 14, 2012 at 3:58pm
Topic archived. No new replies allowed.