Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

1
vote
1answer
87 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 ...
27
votes
13answers
10k 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 ...
2
votes
7answers
917 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 ...
-2
votes
1answer
120 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 ...
1
vote
2answers
119 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 ...
3
votes
2answers
102 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;...
8
votes
3answers
435 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 ...
0
votes
1answer
93 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, ...
1
vote
0answers
83 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 ...
10
votes
2answers
381 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 ...
9
votes
2answers
866 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 ...
11
votes
2answers
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 ...
14
votes
6answers
4k 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 ...
4
votes
1answer
119 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 ...
12
votes
1answer
787 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 ...
3
votes
3answers
470 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); ...
7
votes
1answer
334 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 ...
0
votes
1answer
169 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, ...
26
votes
10answers
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 ...
14
votes
4answers
9k 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 <...
-1
votes
2answers
2k 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 ...
4
votes
1answer
361 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 ...
1
vote
1answer
603 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 ...
67
votes
10answers
16k 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 ...
-2
votes
1answer
211 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 ...
63
votes
10answers
14k 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 odd that a ...
0
votes
1answer
76 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?
5
votes
1answer
491 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 ...
0
votes
1answer
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 ...
-3
votes
2answers
449 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 ...
0
votes
2answers
2k 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....
0
votes
2answers
285 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 ...
8
votes
1answer
596 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. ...
3
votes
1answer
687 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 ...
33
votes
7answers
3k 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....
46
votes
4answers
7k 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 ...
4
votes
2answers
5k views

How to generate C++ code? (probably WITH (not FROM) Python) [closed]

For a scientific simulation I need to write some computations in C++. Since this became extremely tedious, I built myself a small code generator: In a scripting language (Python) you put together a ...
-3
votes
2answers
2k views

What is the difference between extending a class and instantiating an object of that class?

I frequently see people extending a class like this for example: public class Bananas extends Fruits { public void eatFruit(){ } } rather than public class Bananas { Fruits ...
2
votes
1answer
333 views

Enumerating the primitive recursive functions

How can I enumerate (by expression tree size, for example) all of the primitive recursive functions that map natural numbers to natural numbers in a traditional programming language like C? For ...
-1
votes
2answers
117 views

Hypothetical extension to C# property initializer syntax

In C#, when you call a constructor, you can add one or more property initializers in curly braces: var foo = new Bar() { Armpit = new Flapdoodle() { Limpet = 2 } }; What if that feature were ...
3
votes
2answers
189 views

Regular syntax — what does it mean?

I am reading "Less is exponentially more" and there is a list of advantages of Go, first of them, quote "regular syntax (don't need a symbol table to parse)". What does it mean "regular syntax"? ...
4
votes
1answer
168 views

How to approach syntax errors when developing a lexical analyser?

I am writing an interpreted domain-specific language for my application. Each statement is parsed and executed as soon as lexical analyser decides that the end of statement is reached. It's handling ...
0
votes
2answers
82 views

Is the word 'statement' in 'statement block' redundant?

Is the word 'statement' in 'statement block' redundant? In other words is a block in a program composed, by definition, of statements?
2
votes
4answers
145 views

Should actions / methods be conjugated in comments?

For example, which of the following is correct ? // Return hello -- or -- // Returns hello function greeting() { return "Hello"; } I personally never conjugate them but I am wondering how ...
0
votes
1answer
208 views

Is it a reasonable task to automatically convert ANTLR grammars to my own format?

I was working on my own parser generator tool in Clojure and then I realised I want to test it with some real programming languages. I can find a lot of existing language grammars only in antlr v4 ...
0
votes
1answer
667 views

Do any languages have syntax for promises? [closed]

I'm really glad that EcmaScript 6 has promises built into the language, but the syntax will still be quite wordy: new Promise(f).then(r => { ... }).then(r2 => ... }).catch(... I'm just ...
8
votes
1answer
892 views

quantitatively comparing AST shapes

How could one compare the shape of abstract syntax trees of similar source code programs (C, C++, Go, or anything compiled with GCC...)? I guess that plagiarism detection on source code would use ...
25
votes
6answers
3k views

Explaining new or uncommon syntax in comments [duplicate]

As per the title, should I be explaining syntax that I use in my code when I have a reasonable expectation that a developer looking at my code in the future will not be familiar with it? Short caveats ...
0
votes
2answers
1k views

Nested functions; allow or not? [closed]

Having programmed a whole lot in python, using nested functions is a good way to not clutter the namespace with small helper functions that are only used once. Now I'm programming in go, and upon ...
2
votes
2answers
2k views

How to create a 2D array at runtime in Ada? [closed]

In Ada programming, What is a best practice way to create a 2D array of a size that is specified by the user? I'm teaching myself Ada for work (after many years of C programming), and I'm having ...