Questions tagged [syntax]

Syntax refers to the actual language elements and symbols themselves. Questions should be tagged as syntax when the question specifically and almost completely relates to syntax alone. This tag should be used with a specific language tag

Definition

In computer science, 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. The syntax of a language defines its surface form. Text-based programming languages are based on sequences of characters, while visual programming languages are based on the spatial layout and connections between symbols (which may be textual or graphical).

The lexical grammar of a textual language specifies how characters must be chunked into tokens. Other syntax rules specify the permissible sequences of these tokens and the process of assigning meaning to these token sequences is part of semantics.

The syntactic analysis of source code usually entails the transformation of the linear sequence of tokens into a hierarchical syntax tree (abstract syntax trees are one convenient form of syntax tree). This process is called parsing, as it is in syntactic analysis in linguistics. Tools have been written that automatically generate parsers from a specification of a language grammar written in Backus-Naur form, e.g., Yacc (yet another compiler compiler).

Source: Syntax (Programming Languages) - Wikipedia

Usage

On StackOverflow, questions should be tagged as syntax when the question specifically and almost completely relates to syntax alone. Additionally, a tag should be added corresponding to the language that is being used, as the syntax only makes sense in the context of the language. Adding the correct language tag will ensure that the question will reach an audience capable of answering it.

21432 questions
1107
votes
15 answers

Are multi-line strings allowed in JSON?

Is it possible to have multi-line strings in JSON? It's mostly for visual comfort so I suppose I can just turn word wrap on in my editor, but I'm just kinda curious. I'm writing some data files in JSON format and would like to have some really long…
Anonnobody
  • 11,239
  • 2
  • 18
  • 6
1075
votes
10 answers

How do you comment out code in PowerShell?

How do you comment out code in PowerShell (1.0 or 2.0)?
labyrinth
  • 13,397
  • 7
  • 35
  • 44
988
votes
7 answers

Python integer incrementing with ++

I've always laughed to myself when I've looked back at my VB6 days and thought, "What modern language doesn't allow incrementing with double plus signs?": number++ To my surprise, I can't find anything about this in the Python docs. Must I really…
Markus Hedlund
  • 23,374
  • 22
  • 80
  • 109
956
votes
7 answers

When do we need curly braces around shell variables?

In shell scripts, when do we use {} when expanding variables? For example, I have seen the following: var=10 # Declare variable echo "${var}" # One use of the variable echo "$var" # Another use of the variable Is there a significant…
New User
  • 9,759
  • 4
  • 15
  • 8
922
votes
14 answers

What does the "at" (@) symbol do in Python?

What does the @ symbol do in Python?
AJ00200
  • 16,327
  • 7
  • 23
  • 21
922
votes
7 answers

What is the difference between single-quoted and double-quoted strings in PHP?

I'm a little confused why I see some code in PHP with string placed in single quotes and sometimes in double quotes. I just know in .NET, or the C language, if it is in a single quote, that means it is a character, not a string.
rob waminal
  • 18,117
  • 17
  • 50
  • 64
896
votes
10 answers

Are double square brackets [[ ]] preferable over single square brackets [ ] in Bash?

A coworker claimed recently in a code review that the [[ ]] construct is to be preferred over [ ] in constructs like if [ "`id -nu`" = "$someuser" ] ; then echo "I love you madly, $someuser" fi He couldn't provide a rationale. Is there one?
Leonard
  • 13,269
  • 9
  • 45
  • 72
878
votes
19 answers

All possible array initialization syntaxes

What are all the array initialization syntaxes that are possible with C#?
Joshua Girard
  • 8,850
  • 3
  • 15
  • 7
820
votes
10 answers

How to convert Set to Array?

Set seems like a nice way to create Arrays with guaranteed unique elements, but it does not expose any good way to get properties, except for generator [Set].values, which is called in an awkward way of mySet.values.next(). This would have been ok,…
c69
  • 19,951
  • 7
  • 52
  • 82
807
votes
10 answers

How do you pass a function as a parameter in C?

I want to create a function that performs a function passed by parameter on a set of data. How do you pass a function as a parameter in C?
andrewrk
  • 30,272
  • 27
  • 92
  • 113
798
votes
13 answers

What is the difference between . (dot) and $ (dollar sign)?

What is the difference between the dot (.) and the dollar sign ($)? As I understand it, they are both syntactic sugar for not needing to use parentheses.
Rabarberski
  • 23,854
  • 21
  • 74
  • 96
789
votes
8 answers

How to use double or single brackets, parentheses, curly braces

I am confused by the usage of brackets, parentheses, curly braces in Bash, as well as the difference between their double or single forms. Is there a clear explanation?
Tim
  • 1
  • 141
  • 372
  • 590
786
votes
4 answers

What do ** (double star/asterisk) and * (star/asterisk) mean in a function call?

In code like zip(*x) or f(**k), what do the * and ** respectively mean? How does Python implement that behaviour, and what are the performance implications? See also: Expanding tuples into arguments. Please use that one to close questions where OP…
762
votes
8 answers

Are (non-void) self-closing tags valid in HTML5?

The W3C validator (Wikipedia) doesn't like self-closing tags (those that end with “/>”) on non-void elements. (Void elements are those that may not ever contain any content.) Are they still valid in HTML5? Some examples of accepted void…
cdeszaq
  • 30,869
  • 25
  • 117
  • 173
744
votes
8 answers

YAML: Do I need quotes for strings in YAML?

I am trying to write a YAML dictionary for internationalisation of a Rails project. I am a little confused though, as in some files I see strings in double-quotes and in some without. A few points to consider: example 1 - all strings use double…
Alexander Popov
  • 23,073
  • 19
  • 91
  • 130