Talk:Syntax (computer science): Difference between revisions

From Citizendium
Jump to navigation Jump to search
imported>Ed Poor
mNo edit summary
imported>Howard C. Berkowitz
No edit summary
 
(2 intermediate revisions by one other user not shown)
Line 21: Line 21:


Or am I just mixed up about what the word ''syntax'' means? --[[User:Ed Poor|Ed Poor]] 17:04, 24 January 2009 (UTC)
Or am I just mixed up about what the word ''syntax'' means? --[[User:Ed Poor|Ed Poor]] 17:04, 24 January 2009 (UTC)
: The current article makes sense to me, but then I worked with lexers and parsers and such for many years, and can see that it might not be the greatest introduction to the subject for a newcomer. Maybe adding an example would help -- e.g., the BASIC "For" statement's syntax could be described in natural language as:  A statement beginning with the keyword FOR must next contain an IDENTIFIER, followed by the keyword =, which may be followed by an EXPRESSION (which would be defined elsewhere as.....), etc. It might also be helpful to point out that the syntax of a computer language has nothing to do with its semantics -- that is, a description of the FOR statement's syntax doesn't tell you anything about what it does; it could begin a loop, print some output, or launch a missile.
:Also, "the grammar" in computer science is often used to mean the input to the program that generates the parser -- that is, it's the file containing the formal description of a language's syntax. [[User:Bruce M.Tindall|Bruce M.Tindall]] 18:02, 24 January 2009 (UTC)
::Exactly. First, let's distinguish semantics from syntax. Depending on how formal you want to be, there's a "for", or an "iterative loop with conditional" exit in BASIC and C and FORTRAN. Their syntax is very different.  Not all languages have all kinds of semantics.
::There's syntax that an application programmer needs to write a program that the compiler will accept.  The issue of token order is blurry between syntax and semantics; not every language, if no parentheses are used, will give the same result from A=B+C/D. Even within a language, there may be syntactical AND semantic elements that a particular programmer never uses. If you don't have a good reason to use pointers in C, please don't.
::The compiler/parser programmer, however, needs to have syntax defined at a far more detailed level. So, perhaps there could be subheads on syntax for different purposes, and a link to computational semantics (or a section) if we don't have one. Language-specific syntax and semantics belong in the language article, or perhaps an article for a group of related languages. [[User:Howard C. Berkowitz|Howard C. Berkowitz]] 18:40, 24 January 2009 (UTC)

Latest revision as of 12:40, 24 January 2009

This article is basically copied from an external source and has not been approved.
Main Article
Discussion
Related Articles  [?]
Bibliography  [?]
External Links  [?]
Citable Version  [?]
 
To learn how to update the categories for this article, see here. To update categories, edit the metadata template.
 Definition The set of allowed reserved words and possible token order in a program. [d] [e]
Checklist and Archives
 Workgroup category Computers [Categories OK]
 Talk Archive none  English language variant British English

This is way too abstruse and formal. I think of syntax as the "grammar" of computer programming. Like, how do you write a loop?

Java example:

(for int i = 0; i < 10; i++) {

   System.out.println(i);
}

That will print the first ten natural numbers (0 to 9) on the user's console. The syntax to do the same thing is very similar in C or PHP. It has been said that the curly brace family of programming languages share a common syntax.

BASIC uses a different syntax to express the same idea (or do the same thing).

For i = 0 to 9

   Debug.Print i

Next i

Or am I just mixed up about what the word syntax means? --Ed Poor 17:04, 24 January 2009 (UTC)

The current article makes sense to me, but then I worked with lexers and parsers and such for many years, and can see that it might not be the greatest introduction to the subject for a newcomer. Maybe adding an example would help -- e.g., the BASIC "For" statement's syntax could be described in natural language as: A statement beginning with the keyword FOR must next contain an IDENTIFIER, followed by the keyword =, which may be followed by an EXPRESSION (which would be defined elsewhere as.....), etc. It might also be helpful to point out that the syntax of a computer language has nothing to do with its semantics -- that is, a description of the FOR statement's syntax doesn't tell you anything about what it does; it could begin a loop, print some output, or launch a missile.
Also, "the grammar" in computer science is often used to mean the input to the program that generates the parser -- that is, it's the file containing the formal description of a language's syntax. Bruce M.Tindall 18:02, 24 January 2009 (UTC)
Exactly. First, let's distinguish semantics from syntax. Depending on how formal you want to be, there's a "for", or an "iterative loop with conditional" exit in BASIC and C and FORTRAN. Their syntax is very different. Not all languages have all kinds of semantics.
There's syntax that an application programmer needs to write a program that the compiler will accept. The issue of token order is blurry between syntax and semantics; not every language, if no parentheses are used, will give the same result from A=B+C/D. Even within a language, there may be syntactical AND semantic elements that a particular programmer never uses. If you don't have a good reason to use pointers in C, please don't.
The compiler/parser programmer, however, needs to have syntax defined at a far more detailed level. So, perhaps there could be subheads on syntax for different purposes, and a link to computational semantics (or a section) if we don't have one. Language-specific syntax and semantics belong in the language article, or perhaps an article for a group of related languages. Howard C. Berkowitz 18:40, 24 January 2009 (UTC)