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
13
votes
3 answers

Difference between static variable inside and outside of a function?

static int count; int main() { static int count; } Is there any difference between static variables declared inside and outside any function? (I mean the scope and visibility of the variable count)
munish
  • 4,505
  • 14
  • 53
  • 83
13
votes
3 answers

What does angle brackets “<>” mean in function declaration in Typescript?

In TypeScript code, I often will see code wrapped inside of Angle Brackets, just like HTML. I know that they are not HTML Elements, and I know that the code inside of the angle brackets are types, however; I see types written without angle-brackets…
Michael
  • 1,313
  • 11
  • 25
13
votes
2 answers

What does C++ language definition say about the extent of the static keyword?

In C++, if I have a class: class Example { static int s_One, s_Two; ... }; Does the language clearly define that s_Two is also static? In other words, does the static keyword extent go everywhere the int goes, or can it be like * and only…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
13
votes
12 answers

Why semicolon is not required after a curled bracket?

I know that a semicolon is required after a statement (I'm talking about Java, C++, and similar languages), but is not required after a curled bracket. Why so? if (a > b) printf("hello!"); // semicolon is mandatory if (a > b) { …
riox
13
votes
1 answer

What does the ($=) (dollar equals) operator do in Haskell GLUT library?

I was looking through some game code written in Haskell using the GLUT library and this operator keeps popping out everywhere. The worst part is it's completely ungooglable and I can't seem to grep out the definition of it anywhere. Could someone…
Tomas
  • 704
  • 5
  • 10
13
votes
1 answer

Why is `const int& k = i; ++i; ` possible?

I am supposed to determine whether this function is syntactically correct: int f3(int i, int j) { const int& k=i; ++i; return k; } I have tested it out and it compiles with my main function. I do not understand why this is so. Surely by calling…
user9078057
  • 271
  • 1
  • 10
13
votes
1 answer

What does an @ symbol mean in a Rust declarative macro?

I have seen the @ symbol used in macros but I cannot find mention of it in the Rust Book or in any official documentation or blog posts. For example, in this Stack Overflow answer it is used like this: macro_rules! instructions { (enum…
Peter Hall
  • 53,120
  • 14
  • 139
  • 204
13
votes
4 answers

What does a "CALLBACK" declaration in C do?

I was looking through some code from the SDL library and came across a function declared like this: LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) Now, I'm a Delphi coder. No hablo C muy bien, senor. But I remember…
Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477
13
votes
1 answer

What is the syntax: `instance.method::()`?

I read the below syntax from byteorder: rdr.read_u16::() I can't find any documentation which explains the syntax instance.method::()
周汉成
  • 1,217
  • 2
  • 13
  • 24
13
votes
5 answers

How do I put the contents of a list in a single MessageBox?

Basically, I have a list with multiple items in it and I want a single message box to display them all. The closest I have got is a message box for each item (using foreach). What I want is the equivalent of: MessageBox.Show ("List…
Wil
  • 10,234
  • 12
  • 54
  • 81
13
votes
1 answer

How do I customize the colors used by 'jq -C'?

How do I specify colors other than the defaults used for jq --color-output?
orome
  • 45,163
  • 57
  • 202
  • 418
13
votes
3 answers

How to decrypt windows administrator password in terraform?

I'm provisioning a single windows server for testing with terraform in AWS. Every time i need to decrypt my windows password with my PEM file to connect. Instead, i chose the terraform argument get_password_data and stored my password_data in…
Ravichandran
  • 427
  • 1
  • 3
  • 16
13
votes
3 answers

Is line continuation with backslash dangerous in Python?

I understand that current best practice for line continuation is to use implied continuation inside parenthesis. For example: a = (1 + 2 + 3 + 4) From PEP8 (https://www.python.org/dev/peps/pep-0008/): The preferred way of wrapping long lines…
gregrf
  • 211
  • 3
  • 8
13
votes
5 answers

Javascript Property with three dots (...)

I have a problem with code I am supposed to work with. I found a syntax I am not familiar with and I have trouble googling the documentation: export const Something = class Something { constructor(someObject = {}) { this.someObject =…
SomeStranger314
  • 327
  • 1
  • 3
  • 12
13
votes
3 answers

Can member variable and local method variable have the same name?

How would I accomplish this? class Test { private int var1; public Test(int var1) { var1 = var1; //set the member variable to what was passed in } } I'm sure there's a very obvious answer. It's just escaping me right now.
Greg
  • 45,306
  • 89
  • 231
  • 297