Questions tagged [syntax]

Syntax refers to the set of rules that define how to write a correctly structured program in a language. It explicitly does not deal with the program's meaning or interpretation.

Filter by
Sorted by
Tagged with
1 vote
3 answers
506 views

Is "avoid misuse in other languages" a valid reason to avoid myString=="abc" in c++?

For example, I know in c++, I can use myString=="abc" to check if 2 strings are equal. However, in Java, it is comparing if 2 objects are the same object. Also in other language, for ...
wcminipgasker2023's user avatar
0 votes
0 answers
184 views

What is it about kdb/q that makes the grammar not suitable for ANTLR style parser generators?

I want to build a code analysis tool for personal use when programming in kdb/q. In order to do this, I need to be able to parse q code into an AST. I have never written a parser before. ANTLR4 seems ...
Chechy Levas's user avatar
4 votes
1 answer
408 views

Is there a way to make Rust code more succinct?

Let's take at random a well-written piece of Rust code: let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { label: Some("Shader"), flags: wgpu::ShaderFlags::...
Zomagk's user avatar
  • 261
8 votes
1 answer
366 views

What type of syntax notation is this?

SQL Server documentation uses this notation, which is very easy to understand and consume. Is this a BNF Syntax Diagram? Or is this a different type of notation? Source: SQL server documentation page ...
user497745's user avatar
0 votes
2 answers
81 views

Does Get in Repo Imply GetById?

REST APIs in virtually all languages use methods named Get to get GetById(int id). Is it ok to use this convention for repositories? Let's say I have a Professions repository for the sake of example. ...
VSO's user avatar
  • 169
6 votes
5 answers
777 views

Reasons to use (and not to use) a repeated delimiter to escape that delimiter?

For the designer of a language syntax, what are some reasons to choose a repeated delimiter to escape that delimiter, instead of having a separate escape character to escape that delimiter. A common ...
Shiania White's user avatar
-2 votes
1 answer
182 views

Is there a common agreed upon token symbol used in computer science or common across languages?

I have seen tokens like this: var message = "Hello, {Name}"; and like this: var message = "Hello, ${name}"; and like this: var message = "Hello, @NAME"; and a few ...
1.21 gigawatts's user avatar
0 votes
3 answers
685 views

Does compiler AST include functions and classes?

In most of the examples for Abstract Syntax Trees (AST), I see no function or classes. I am wondering, if the functions and classes are represented in the AST? If no, where should the functions, ...
Kate's user avatar
  • 1
0 votes
2 answers
936 views

Logically, is there a reason why ++i++ can not be a valid expression?

I had to increment my integer twice in a loop, so I thought I would try and be clever: for (int i = 0; !sl.isEmpty(); ++i++) { ... } ++i++ however is not an assignable expression, at least in GCC. ...
Anon's user avatar
  • 3,575
0 votes
4 answers
250 views

Language design : use equals symbol = both for affectation and comparison, like in MySQL

I'm currently designing a database query language and I came to wonder what should be the best syntax for the comparison operator. Most modern languages use ==, but amongst the database languages ...
ibi0tux's user avatar
  • 241
9 votes
1 answer
799 views

Which was the first language to allow underscore in numeric literals?

Java 7+ allows to use underscores in numeric literals,which do not affect the value of the literal, yet are useful for grouping. Examples from the Java 7 documentation, entitled "Underscores in ...
David Tonhofer's user avatar
1 vote
1 answer
77 views

Lexicon for syntax patterns? [closed]

I am having trouble finding a lexicon which provides terminology for the explicit patterns that are employed when parsing syntax. I am trying to write about the niggling differences between the 10+ ...
Darf Nader's user avatar
1 vote
1 answer
400 views

What is the BNF (or BNF-like) syntax for a specific number of repetitions?

I would like to write something like <byte> ::= <bit>*8 to mean that a <byte> is a sequence of exactly 8 <bit>'s. Is there a way to do this in BNF[1][2] or a widely used ...
Ana Nimbus's user avatar
2 votes
3 answers
577 views

Is a literal out of range a syntax error or a semantic error?

I am reading more about the differences between syntax and semantics, but I am still wondering about this one. Let's assume that we have a language that only allows integers to be in the range of 0-...
Joan Vene's user avatar
1 vote
1 answer
203 views

Question about Backus-NaurForm (BNF)

To write the grammar for Whole Numbers (0,1,2...) in BNF, we may write: Number ::⇒ Digit MoreDigits MoreDigits ::⇒ MoreDigits ::⇒ Number Digit ::⇒ 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 For a ...
Promise Tochi's user avatar
32 votes
14 answers
13k views

Why don't programming languages automatically manage the synchronous/asynchronous problem?

I have not found many resources about this: I was wondering if it's possible/a good idea to be able to write asynchronous code in a synchronous way. For example, here is some JavaScript code which ...
Cinn's user avatar
  • 463
3 votes
7 answers
2k views

Why don't languages use the words "and" and "or" instead of "&&" and "||"?

When I was a beginner it took a while to learn the language syntax and the idea that languages couldn't improve after they were invented. But now we're seeing new language features added every year ...
1.21 gigawatts's user avatar
-2 votes
1 answer
224 views

Are there languages/syntaxes for representing graphs? [closed]

S-expressions are a well-known way of describing trees in high-level code. Is there something similar for describing graphs? The two closest things I've found are DOT and Ko. Both aren't quite what ...
Louis Thibault's user avatar
1 vote
3 answers
602 views

How to parse DSL file to HTML?

There's DSL format for creating and distributing dictionaries. Every dictionary article in such formats looks like this: algorithm [m0][b]al·go·rithm[/b] {{id=000001018}} [c rosybrown]\[[/c][c ...
Anatoly's user avatar
  • 258
3 votes
2 answers
119 views

What is the term for the side on which a variable type is written in a given language?

In the case that a type is specified, it could be on the left (before) or the right (after) of the variable name. For example, C, C# and Java have the type specified before the variable: int num = 5;...
rovyko's user avatar
  • 215
17 votes
5 answers
853 views

Is there a programming language where every string is a valid program?

Does there exist a Turing complete programming language such that for a fixed alphabet (say, ASCII), every possible permutation of those characters is a semantically valid program capable of being ...
mp-'s user avatar
  • 287
0 votes
1 answer
147 views

Why are new modern languages shifting to a variableName: VariableType syntax approach? [duplicate]

Modern languages like Rust, Kotlin, and TypeScript, define their syntax to declare variables as: myVariableName: VariableType As opposed to the C-like approach not so old languages like JavaScript, ...
AxiomaticNexus's user avatar
2 votes
0 answers
320 views

What obstacles should I expect in building universal Abstract Syntax Tree's manipulation tool?

I am trying to build code generation and transformation tool and hence I need software for Abstract Syntax Tree manipulation for at least three languages (Coq, Haskell, Java). So far I have managed to ...
TomR's user avatar
  • 1,003
14 votes
3 answers
1k views

Why does Forth's flexibility make a grammar inappropriate for it?

I've recently undertaken the task of writing a stack-based programming language. Before I started designing my language however, I thought it'd be a good idea to read and experiment with existing ...
Christian Dean's user avatar
12 votes
2 answers
2k views

How did the custom of using square brackets for array elements develop?

Many programming language use the syntax a[i] to refer to the i'th element of an array, sequence, or vector a - specifically, C and Pascal (from the late 1960s and early 1970s) do this. On the other ...
einpoklum's user avatar
  • 2,488
11 votes
2 answers
2k views

Is i,j = 1 really misleading? [closed]

There is a common argument about multiple variable initialisation in a one liner, that is : Consider for example int i, j = 1; which might lead some people to mistakingly believe both variables ...
Walfrat's user avatar
  • 3,466
19 votes
6 answers
8k views

One-liners vs. readability: when to stop reducing code? [closed]

Context I recently got interested into producing better formatted code. And by better I mean "following rules endorsed by enough people to consider it a good practice" (since there will never be one ...
Sudiukil's user avatar
  • 199
4 votes
1 answer
195 views

Tool for validation of new code syntax in existing language

Does a programming language team have any tool to validate their new ideas about new code syntax? As an example, let's assume the Java language team starts developing new feature, which requires new ...
DreamOnJava's user avatar
13 votes
1 answer
1k views

What does 'syntax vinegar' mean

I was reading through Groovy in Action, Second Edition and on a footnote, I found the following text Java pours “syntax vinegar” over such a construct to discourage programmers from using it. What ...
isuru-buddhika's user avatar
2 votes
3 answers
1k views

C++ - explicitly prefixing every member with public/private

Normally, a C++ class is written with public: and private: applying to a series of members: class Foo { private: int x; int y; int z; public: int getX(); int setY(int val); ...
Nayuki's user avatar
  • 184
9 votes
1 answer
670 views

What makes some things easier to parse than others?

I was just reading the Wikipedia page for WebAssembly and it says: “WebAssembly is… designed to be faster to parse than JavaScript” , which got me thinking, what makes a certain language or data ...
Adam's user avatar
  • 228
0 votes
1 answer
249 views

Implement an actor-based concurrent language in ruby?

How would one implement an actor-based concurrent language in ruby? My thought is that only the correct way of creating programs is using actors, but I'm not entirely sure on how this could be done, ...
Grimbox's user avatar
  • 377
26 votes
10 answers
7k views

Programming language where every function call/block is done in a separate thread? [closed]

I'm currently creating a programming language for fun where the idea is that every function call/new block (if clauses, loops etc) will work in a separate thread. Instead of creating new Threads the ...
Grimbox's user avatar
  • 377
27 votes
4 answers
15k views

Is colon in python blocks technically necesary?

This is really just a theoretical question by a python newbie who wants to understand more. I keep forgetting the colon after the block initial statements in python. Those are what I mean: for <...
Tomáš Zato's user avatar
-1 votes
2 answers
4k views

Why is the dot illegal in a Java identifier?

We know some of this syntax won't compile, specifically the line where I'm explicitly referring to the class name for a variable. class Main { static String Main.s1 ="output"; //won't compile ...
Niklas Rosencrantz's user avatar
3 votes
1 answer
634 views

Are there only 2 places you can declare new generic type parameters in Java?

It's confusing because type declaration and usage both use the <T> syntax. I think there are only 2 places where you can declare new generic types in Java: 1. In the definition of a class or ...
GlenPeterson's user avatar
  • 14.9k
1 vote
1 answer
1k views

Collection properties and initializer lists in .Net API design

The following is a quote from Microsoft's framework design guidelines: Collection Properties and Return Values X DO NOT provide settable collection properties. Users can replace the ...
Mikko Rantanen's user avatar
68 votes
10 answers
20k views

Why do languages require parenthesis around expressions when used with "if" and "while"?

Languages like C, Java, and C++ all require parenthesis around an entire expression when used in an if, while, or switch. if (true) { // Do something } as opposed to if true { // Do ...
Velovix's user avatar
  • 773
-2 votes
1 answer
372 views

How does accessing class level variables in java work?

I'm doing my third online course in learning java because I couldn't get over how to even start a project from scratch. There was a lesson in this new course that made me ask this question of the code ...
Rafael Cortes's user avatar
68 votes
10 answers
20k views

Syntax Design - Why use parentheses when no arguments are passed?

In many languages, the syntax function_name(arg1, arg2, ...) is used to call a function. When we want to call the function without any arguments, we must do function_name(). I find it strange that a ...
David Refoua's user avatar
  • 1,101
0 votes
1 answer
82 views

What is the difference between saying something like root->data and root.data?

As the title states, what is the difference between -> and . I thought they were the same thing?
johnson's user avatar
  • 109
5 votes
1 answer
1k views

How should a lexer deal with multi-line statements(eg. Functions definitions, Control-Flow statements)?

tl;dr-ers: How does a lexer normally deal with none-inline statements. statements that do not end with a specified statement delimiter. Such as control flow statements? I believe that I have a ...
Christian Dean's user avatar
0 votes
1 answer
2k views

When do I use square brackets around routerLink in Angular2?

In Angular 2 (currently 2.0.0-rc.6), routerLink is used as a directive to indicate a path we wish to follow in our routing, e.g. in response to clicking a link. However, in the documentation both of ...
Andrew Willems's user avatar
-3 votes
2 answers
584 views

Why the most popular general purpose languages have adopted more complex syntax? [closed]

Maybe this question is not going to mean a lot if C and C++ are put into context, but I kept wondering why later languages such as Java and specially C# haven't been made simpler in regards of their ...
Ezequiel Barbosa's user avatar
2 votes
2 answers
3k views

How to 'read' arrow functions in ES6?

I've been trying to learn some of the new features of ES6, and while most of it makes sense, I'm having trouble grasping the arrow function. I'm not asking so much why it exists as I am how to read it....
Brendan's user avatar
  • 135
0 votes
2 answers
438 views

Could Java XYZ implement (limited) Operator Overloading without breaking backwards compatibility?

Recently, I've been learning a bit more of C++ and the dangers and uses of operator overloading, and the readability boost it provides to arithmetic types (like Complex numbers). A while ago, I was ...
Alxe's user avatar
  • 113
8 votes
1 answer
960 views

Perform crossover operation on AST in genetic programming

So in general when you perform a crossover in GA, you directly flip a random section in the "genome", with the corresponding section in the other parent, and mutate it based on the mutation rate. ...
Jordan LaPrise's user avatar
4 votes
1 answer
1k views

Why closure declaration syntax in Swift is different from function declaration

let closure = { (args) -> ReturnT in ... } v.s. func function(args) -> ReturnT { ... } Why didn't Apple follow principle of Occam's razor and make closure and function declarations to be ...
kelin's user avatar
  • 151
43 votes
10 answers
8k views

Why do most mainstream languages not support "x < y < z" syntax for 3-way Boolean comparisons?

If I want to compare two numbers (or other well-ordered entities), I would do so with x < y. If I want to compare three of them, the high-school algebra student will suggest trying x < y < z....
JesseTG's user avatar
  • 657
84 votes
6 answers
18k views

Why does the type go after the variable name in modern programming languages?

Why is it that in nearly all modern programming languages (Go, Rust, Kotlin, Swift, Scala, Nim, even Python last version) types always come after the variable name in the variable declaration, and not ...
Andre Polykanine's user avatar