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

What is the preferred convention for Perl Inheritance

In the example below, I have 3 different syntax/mechanisms for defining inheritance. All of them work. Can someone tell me which one is preferred and why (yes, I know "there is more than ..."). Also, why do I need "use WB" in 1 case and not the…
Manidip Sengupta
  • 3,573
  • 5
  • 25
  • 27
13
votes
2 answers

How to suppress variable substitution in bash heredocs

Is it possible to create a heredoc that does not become subject to variable expansion? e.g. cat <<-EOF > somefile.sh Do not print current value of $1 instead evaluate it later. EOF Update I am aware of escaping by \. My actual heredoc has many…
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560
13
votes
1 answer

Let &mut syntax

It is possible to make the following binding in Rust: let &mut a = &mut 5; But what does it mean exactly? For example, let a = &mut 5 creates an immutable binding of type &mut i32, let mut a = &mut 5 creates a mutable binding of type &mut i32. What…
Nikolai Mavrenkov
  • 1,851
  • 18
  • 21
13
votes
2 answers

In T-SQL, how to insert a new row with all values set by default?

In Microsoft SQL database, I have a table where every column have default values (either fixed values or stuff like identity or getdate()). I am trying to write an SQL statement which will insert a new row in which every cell will have a default…
Arseni Mourzenko
  • 50,338
  • 35
  • 112
  • 199
13
votes
1 answer

How to use if then else to build a string in a crystal reports formula

This is Crystal Reports 9 in Visual Studio 2003 by the way Simple question about crystal reports formula syntax: How do I build the formula's result using if then clauses? Specifically I would like something like this: dim val as string val =…
George Mauer
  • 117,483
  • 131
  • 382
  • 612
13
votes
2 answers

Does '#'-character have to be at the start of a line in the C preprocessor?

I have programmed C for quite a while now. During this time I have learned that it is a common convention to put the "#"-character that comes before preprocessor-directives at column one. Example: #include int main(void) { #ifdef…
wefwefa3
  • 3,872
  • 2
  • 29
  • 51
13
votes
2 answers

public static (const) in a generic .NET class

Is there a syntax trick to get to the constant in a generic class without specifying an (ad-hoc) type? public class MyClass{ public const string MyConstant = "fortytwo"; } // I try to avoid this type specification. var doeswork =…
LosManos
  • 7,195
  • 6
  • 56
  • 107
13
votes
1 answer

while variable is not equal to x or y bash

I'm trying to get user input. The input should be "1" or "2". for some reason I keep getting prompt even when I type 1 or 2. read -p "Your choice: " UserChoice while [[ "$UserChoice" != "1" || "2" ]] do echo…
Zvi
  • 312
  • 1
  • 3
  • 10
13
votes
1 answer

Why is `enum of enum of enum..` allowed?

I cannot understand why this even compile. I've tried with different formats and they all seem to work.. why is it legal to have an enum of enum of enum of..? interface I { enum E implements I { VAL; } class Test { I.E…
eridal
  • 1,288
  • 1
  • 11
  • 23
13
votes
4 answers

Variable variables in PHP - What is their purpose?

In PHP there's a functionality officially called "Variable Variables" where one can assign variable variables. A variable variable takes the value of one variable as the name for a new variable! For example: $name='Joe'; $$name='Smith'; // could…
sbrbot
  • 6,169
  • 6
  • 43
  • 74
13
votes
1 answer

Are the square brackets in Clojure's defn, defmacro and binding really a vector?

Are the square brackets around arguments in Clojure's defn, defmacro and binding (am I forgetting some?) really creating a vector or is it just a matter of syntax, making the arguments stand out from the rest? I'm reading Clojure in Action which…
Michiel Borkent
  • 34,228
  • 15
  • 86
  • 149
13
votes
4 answers

How to extract substring in Groovy?

I have a Groovy method that currently works but is real ugly/hacky looking: def parseId(String str) { System.out.println("str: " + str) int index = href.indexOf("repositoryId") System.out.println("index: " + index) int repoIndex =…
IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756
13
votes
3 answers

Does an unused let binding have any effect in Haskell?

I just realised that it is actually legal to write this: let _ = sum [1..100] in "Hello" The let-binding appears to do absolutely nothing. But now I'm wondering about the exact semantics here. It is possible to write a program which contains a _…
MathematicalOrchid
  • 61,854
  • 19
  • 123
  • 220
13
votes
1 answer

Is it possible to use guards in function definition in idris?

In haskell, one could write : containsTen::Num a => Eq a => [a] -> Bool containsTen (x : y : xs) | x + y == 10 = True | otherwise = False Is it possible to write something equivalent in Idris, without doing it with ifThenElse (my real case…
Molochdaa
  • 2,158
  • 1
  • 17
  • 23
13
votes
3 answers

C#: Union of two ICollections? (equivalent of Java's addAll())

I have two ICollections of which I would like to take the union. Currently, I'm doing this with a foreach loop, but that feels verbose and hideous. What is the C# equivalent of Java's addAll()? Example of this…
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699