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
511
votes
14 answers

What's the meaning of "=>" (an arrow formed from equals & greater than) in JavaScript?

I know that the >= operator means more than or equal to, but I've seen => in some source code. What's the meaning of that operator? Here's the code: promiseTargetFile(fpParams, aSkipPrompt, relatedURI).then(aDialogAccepted => { if…
rpgs_player
  • 5,369
  • 3
  • 15
  • 18
507
votes
2 answers

How can I split a shell command over multiple lines when using an IF statement?

How can I split a command over multiple lines in the shell, when the command is part of an if statement? This works: if ! fab --fabfile=.deploy/fabfile.py --forward-agent --disable-known-hosts deploy:$target; then rc=1 …
Dmitry Minkovsky
  • 36,185
  • 26
  • 116
  • 160
489
votes
17 answers

JavaScript property access: dot notation vs. brackets?

Other than the obvious fact that the first form could use a variable and not just a string literal, is there any reason to use one over the other, and if so under which cases? In code: // Given: var foo = {'bar': 'baz'}; // Then var x =…
Mark Renouf
  • 30,697
  • 19
  • 94
  • 123
487
votes
12 answers

What is Ruby's double-colon `::`?

What is this double-colon ::? E.g. Foo::Bar. I found a definition: The :: is a unary operator that allows: constants, instance methods and class methods defined within a class or module, to be accessed from anywhere outside the class or…
Meltemi
  • 37,979
  • 50
  • 195
  • 293
485
votes
23 answers

No Multiline Lambda in Python: Why not?

I've heard it said that multiline lambdas can't be added in Python because they would clash syntactically with the other syntax constructs in Python. I was thinking about this on the bus today and realized I couldn't think of a single Python…
Imagist
  • 18,086
  • 12
  • 58
  • 77
471
votes
10 answers

What is the purpose of "&&" in a shell command?

As far as I know, using & after the command is for running it in the background. Example of & usage: tar -czf file.tar.gz dirname & But how about &&? (example)
Captain
  • 4,797
  • 4
  • 16
  • 6
465
votes
9 answers

Difference between >>> and >>

What is the difference between >>> and >> operators in Java?
Vipul
  • 4,675
  • 3
  • 16
  • 3
463
votes
21 answers

Can you use a trailing comma in a JSON object?

When manually generating a JSON object or array, it's often easier to leave a trailing comma on the last item in the object or array. For example, code to output from an array of strings might look like (in a C++ like…
Ben Combee
  • 16,831
  • 6
  • 41
  • 42
462
votes
14 answers

How do you format an unsigned long long int using printf?

#include int main() { unsigned long long int num = 285212672; //FYI: fits in 29 bits int normalInt = 5; printf("My number is %d bytes wide and its value is %ul. A normal number is %d.\n", sizeof(num), num, normalInt); …
andrewrk
  • 30,272
  • 27
  • 92
  • 113
461
votes
36 answers

How to use a dot "." to access members of dictionary?

How do I make Python dictionary members accessible via a dot "."? For example, instead of writing mydict['val'], I'd like to write mydict.val. Also I'd like to access nested dicts this way. For example mydict.mydict2.val would refer to mydict = {…
bodacydo
  • 75,521
  • 93
  • 229
  • 319
447
votes
8 answers

How to make "if not true condition"?

I would like to have the echo command executed when cat /etc/passwd | grep "sysa" is not true. What am I doing wrong? if ! [ $(cat /etc/passwd | grep "sysa") ]; then echo "ERROR - The user sysa could not be looked up" exit 2 fi
Sandra Schlichting
  • 25,050
  • 33
  • 110
  • 162
442
votes
20 answers

Is C++ context-free or context-sensitive?

I often hear claims that C++ is a context-sensitive language. Take the following example: a b(c); Is this a variable definition or a function declaration? That depends on the meaning of the symbol c. If c is a variable, then a b(c); defines a…
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
436
votes
8 answers

Is there a standardized method to swap two variables in Python?

In Python, I've seen two variable values swapped using this syntax: left, right = right, left Is this considered the standard way to swap two variable values or is there some other means by which two variables are by convention most usually…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
433
votes
14 answers

What is this weird colon-member (" : ") syntax in the constructor?

Recently I've seen an example like the following: #include class Foo { public: int bar; Foo(int num): bar(num) {}; }; int main(void) { std::cout << Foo(42).bar << std::endl; return 0; } What does this strange : bar(num) mean?…
nils
  • 4,649
  • 3
  • 19
  • 8
410
votes
3 answers

Python "raise from" usage

What's the difference between raise and raise from in Python? try: raise ValueError except Exception as e: raise IndexError which yields Traceback (most recent call last): File "tmp.py", line 2, in raise…
darkfeline
  • 9,404
  • 5
  • 31
  • 32