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


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


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
31 answers

What does "use strict" do in JavaScript, and what is the reasoning behind it?

Recently, I ran some of my JavaScript code through Crockford's JSLint, and it gave the following error: Problem at line 1 character 1: Missing "use strict" statement. Doing some searching, I realized that some people add "use strict"; into their…
Mark Rogers
  • 96,497
  • 18
  • 85
  • 138
41 answers

var functionName = function() {} vs function functionName() {}

I've recently started maintaining someone else's JavaScript code. I'm fixing bugs, adding features and also trying to tidy up the code and make it more consistent. The previous developer used two ways of declaring functions and I can't work out if…
Richard Garside
  • 87,839
  • 11
  • 80
  • 93
30 answers

How to concatenate string variables in Bash

In PHP, strings are concatenated together as follows: $foo = "Hello"; $foo .= " World"; Here, $foo becomes "Hello World". How is this accomplished in Bash?
  • 66,024
  • 56
  • 149
  • 197
27 answers

What does ** (double star/asterisk) and * (star/asterisk) do for parameters?

What do *args and **kwargs mean in these function definitions? def foo(x, y, *args): pass def bar(x, y, **kwargs): pass See What do ** (double star/asterisk) and * (star/asterisk) mean in a function call? for the complementary question…
  • 34,500
  • 4
  • 23
  • 13
9 answers

How do I break a string in YAML over multiple lines?

I have a very long string: Key: 'this is my very very very very very very long string' I would like to express it over multiple shorter lines, e.g., Key: 'this is my very very very ' + 'long string' I would like to use quotes as above, so…
  • 27,597
  • 6
  • 28
  • 29
20 answers

How do I iterate over a range of numbers defined by variables in Bash?

How do I iterate over a range of numbers in Bash when the range is given by a variable? I know I can do this (called "sequence expression" in the Bash documentation): for i in {1..5}; do echo $i; done Which gives: 1 2 3 4 5 Yet, how can I…
  • 22,067
  • 4
  • 21
  • 13
23 answers

Comments in Markdown

How do you write a comment in Markdown, i.e. text that is not rendered in the HTML output? I found nothing on the Markdown project.
  • 26,448
  • 9
  • 23
  • 28
10 answers

Why does ++[[]][+[]]+[+[]] return the string "10"?

This is valid and returns the string "10" in JavaScript (more examples here): console.log(++[[]][+[]]+[+[]]) Why? What is happening here?
  • 15,446
  • 19
  • 62
  • 87
27 answers

Insert into ... values ( SELECT ... FROM ... )

I am trying to INSERT INTO a table using the input from another table. Although this is entirely feasible for many database engines, I always seem to struggle to remember the correct syntax for the SQL engine of the day (MySQL, Oracle, SQL Server,…
Claude Houle
  • 41,064
  • 8
  • 33
  • 42
10 answers

What does __all__ mean in Python?

I see __all__ in files. What does it do?
  • 16,849
  • 3
  • 20
  • 19
18 answers

How do I convert a float number to a whole number in JavaScript?

I'd like to convert a float to a whole number in JavaScript. Actually, I'd like to know how to do BOTH of the standard conversions: by truncating and by rounding. And efficiently, not via converting to a string and parsing.
  • 23,999
  • 10
  • 44
  • 50
21 answers

What does "static" mean in C?

I've seen the word static used in different places in C code; is this like a static function/class in C# (where the implementation is shared across objects)?
25 answers

How to escape single quotes within single quoted strings

Let's say, you have a Bash alias like: alias rxvt='urxvt' which works fine. However: alias rxvt='urxvt -fg '#111111' -bg '#111111'' won't work, and neither will: alias rxvt='urxvt -fg \'#111111\' -bg \'#111111\'' So how do you end up matching up…
  • 14,423
  • 4
  • 20
  • 14
10 answers

How can I do a line break (line continuation) in Python?

Given: e = 'a' + 'b' + 'c' + 'd' How do I write the above in two lines? e = 'a' + 'b' + 'c' + 'd'
  • 187,153
  • 97
  • 222
  • 204
5 answers

Putting a simple if-then-else statement on one line

How do I write an if-then-else statement in Python so that it fits on one line? For example, I want a one line version of: if count == N: count = 0 else: count = N + 1 In Objective-C, I would write this as: count = count == N ? 0 : count +…
  • 146,289
  • 39
  • 203
  • 257
2 3
99 100