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
725
votes
23 answers

Ternary operator (?:) in Bash

Is there a way to do something like this int a = (b == 5) ? c : d; using Bash?
En_t8
  • 7,595
  • 5
  • 20
  • 14
700
votes
5 answers

Command not found error in Bash variable assignment

I have this script called test.sh: #!/bin/bash STR = "Hello World" echo $STR when I run sh test.sh I get this: test.sh: line 2: STR: command not found What am I doing wrong? I look at extremely basic/beginners bash scripting tutorials online and…
Jake Wilson
  • 88,616
  • 93
  • 252
  • 370
690
votes
15 answers

Cross-reference (named anchor) in markdown

Is there markdown syntax for the equivalent of: Take me to pookie ... this is pookie
Synesso
  • 37,610
  • 35
  • 136
  • 207
654
votes
25 answers

Is it possible to insert multiple rows at a time in an SQLite database?

In MySQL you can insert multiple rows like this: INSERT INTO 'tablename' ('column1', 'column2') VALUES ('data1', 'data2'), ('data1', 'data2'), ('data1', 'data2'), ('data1', 'data2'); However, I am getting an error when I try to do…
Andrew
  • 227,796
  • 193
  • 515
  • 708
609
votes
5 answers

What are the advantages of list initialization (using curly braces)?

MyClass a1 {a}; // clearer and less error-prone than the other three MyClass a2 = {a}; MyClass a3 = a; MyClass a4(a); Why?
Oleksiy
  • 37,477
  • 22
  • 74
  • 122
581
votes
16 answers

What is the difference between '/' and '//' when used for division?

Is there a benefit to using one over the other? In Python 2, they both seem to return the same results: >>> 6/3 2 >>> 6//3 2
Ray
  • 187,153
  • 97
  • 222
  • 204
565
votes
3 answers

How to escape % in String.Format?

I am storing a SQL query in my strings.xml file and I want to use String.Format to build the final string in code. The SELECT statement uses a like, something like this: SELECT Field1, Field2 FROM mytable WHERE Field1 LIKE '%something%' In order…
Matthew
  • 11,203
  • 9
  • 38
  • 44
565
votes
15 answers

How do I pass multiple parameters into a function in PowerShell?

If I have a function which accepts more than one string parameter, the first parameter seems to get all the data assigned to it, and remaining parameters are passed in as empty. A quick test script: Function Test([string]$arg1, [string]$arg2) { …
Nasir
  • 10,935
  • 8
  • 31
  • 39
550
votes
17 answers

What does map(&:name) mean in Ruby?

I found this code in a RailsCast: def tag_names @tag_names || tags.map(&:name).join(' ') end What does the (&:name) in map(&:name) mean?
collimarco
  • 34,231
  • 36
  • 108
  • 142
549
votes
5 answers

Why is whitespace sometimes needed around metacharacters?

A few months ago I tattooed a fork bomb on my arm, and I skipped the whitespaces, because I think it looks nicer without them. But to my dismay, sometimes (not always) when I run it in a shell it doesn't start a fork bomb, but it just gives a syntax…
spydon
  • 9,372
  • 6
  • 33
  • 63
543
votes
5 answers

Why are hexadecimal numbers prefixed with 0x?

Why are hexadecimal numbers prefixed as 0x? I understand the usage of the prefix but I don't understand the significance of why 0x was chosen.
unj2
  • 52,135
  • 87
  • 247
  • 375
542
votes
11 answers

How to concatenate strings in twig

Anyone knows how to concatenate strings in twig? I want to do something like: {{ concat('http://', app.request.host) }}
stoefln
  • 14,498
  • 18
  • 79
  • 138
532
votes
9 answers

Best way to "negate" an instanceof

I was thinking if there exists a better/nicer way to negate an instanceof in Java. Actually, I'm doing something like: if(!(myObject instanceof SomeClass)) { /* do Something */ } But I think that a "beautiful" syntax to do this should exist. Does…
caarlos0
  • 20,020
  • 27
  • 85
  • 160
522
votes
6 answers

How do I modify a MySQL column to allow NULL?

MySQL 5.0.45 What is the syntax to alter a table to allow a column to be null, alternately what's wrong with this: ALTER mytable MODIFY mycolumn varchar(255) null; I interpreted the manual as just run the above and it would recreate the column,…
zmf
  • 9,095
  • 2
  • 26
  • 28
512
votes
9 answers

What is the meaning of prepended double colon "::"?

I found this line of a code in a class which I have to modify: ::Configuration * tmpCo = m_configurationDB;//pointer to current db and I don't know what exactly means the double colon prepended to the class name. Without that I would read:…
rmbianchi
  • 6,241
  • 6
  • 26
  • 27