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
366
votes
8 answers

Can I use ES6's arrow function syntax with generators? (arrow notation)

That is, how do I express function *(next) {} with arrow syntax? I've tried all the combinations I could think of, and I can't find any documentation on it. (I am currently using Node.js v0.11.14.)
Ashley Coolman
  • 11,095
  • 5
  • 59
  • 81
363
votes
9 answers

Why is "extends T" allowed but not "implements T"?

Is there a special reason in Java for using always "extends" rather than "implements" for defining bounds of type parameters? For example: public interface C {} public class A{} is prohibited, but public class A{} is…
user120623
  • 3,631
  • 2
  • 17
  • 3
361
votes
21 answers

int a[] = {1,2,}; Why is a trailing comma in an initializer-list allowed?

Maybe I am not from this planet, but it would seem to me that the following should be a syntax error: int a[] = {1,2,}; //extra comma in the end But it's not. I was surprised when this code compiled on Visual Studio, but I have learnt not to trust…
Armen Tsirunyan
  • 130,161
  • 59
  • 324
  • 434
358
votes
8 answers

How do I remove javascript validation from my eclipse project?

I am using eclipse on my project and while messing around with my eclipse settings, I turned on Javascript support. Now eclipse complains that JQuery library has errors in it and is not letting me compile the project. Does anyone know how to turn…
Ritesh M Nayak
  • 8,001
  • 14
  • 49
  • 78
353
votes
1 answer

One try block with multiple excepts

In Python, is it possible to have multiple except statements for one try statement? Such as: try: #something1 #something2 except ExceptionType1: #return xyz except ExceptionType2: #return abc For the case of handling multiple…
Eva611
  • 5,964
  • 8
  • 30
  • 38
346
votes
7 answers

Understanding implicit in Scala

I was making my way through the Scala playframework tutorial and I came across this snippet of code which had me puzzled: def newTask = Action { implicit request => taskForm.bindFromRequest.fold( errors =>…
Clive
  • 3,991
  • 3
  • 17
  • 15
339
votes
5 answers

What is the syntax for a multiline string literal?

I'm having a hard time figuring out how string syntax works in Rust. Specifically, I'm trying to figure out how to make a multiple line string.
Dumbapples
  • 3,879
  • 3
  • 14
  • 10
338
votes
13 answers

How to swap text based on patterns at once with sed?

Suppose I have 'abbc' string and I want to replace: ab -> bc bc -> ab If I try two replaces the result is not what I want: echo 'abbc' | sed 's/ab/bc/g;s/bc/ab/g' abab So what sed command can I use to replace like below? echo abbc | sed…
DaniloNC
  • 3,555
  • 2
  • 16
  • 8
333
votes
13 answers

Add a property to a JavaScript object using a variable as the name?

I'm pulling items out of the DOM with jQuery and want to set a property on an object using the id of the DOM element. Example const obj = {} jQuery(itemsFromDom).each(function() { const element = jQuery(this) const name = element.attr('id') …
Todd R
  • 18,236
  • 8
  • 31
  • 39
333
votes
12 answers

Arrow operator (->) usage in C

I am reading a book called "Teach Yourself C in 21 Days" (I have already learned Java and C# so I am moving at a much faster pace). I was reading the chapter on pointers and the -> (arrow) operator came up without explanation. I think that it is…
Mohit Deshpande
  • 53,877
  • 76
  • 193
  • 251
329
votes
5 answers

What's the u prefix in a Python string?

Like in: u'Hello' My guess is that it indicates "Unicode", is that correct? If so, since when has it been available?
OscarRyz
  • 196,001
  • 113
  • 385
  • 569
324
votes
9 answers

What is the C# Using block and why should I use it?

What is the purpose of the Using block in C#? How is it different from a local variable?
Ryan Michela
  • 8,284
  • 5
  • 33
  • 47
319
votes
10 answers

How do I syntax check a Bash script without running it?

Is it possible to check a bash script syntax without executing it? Using Perl, I can run perl -c 'script name'. Is there any equivalent command for bash scripts?
Tom Feiner
  • 20,656
  • 20
  • 48
  • 51
318
votes
10 answers

Syntax of for-loop in SQL Server

What is the syntax of a for loop in TSQL?
Macho
  • 3,307
  • 3
  • 16
  • 6
316
votes
7 answers

What do parentheses surrounding an object/function/class declaration mean?

In the YUI library examples, you can find many uses of this construct: (function() { var Dom = YAHOO.util.Dom, Event = YAHOO.util.Event, layout = null, ... })(); I think the last couple of parentheses are to execute the function…
user54692
  • 3,177
  • 3
  • 17
  • 3