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
2answers
91 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
110 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
123 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
78 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 ...
2
votes
2answers
117 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
127 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
73 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
127 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
52 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
208 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 ...
5
votes
1answer
144 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 ...
22
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
207 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
121 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 ...
-4
votes
3answers
323 views
Why different languages have different syntax? [duplicate]
Different programming language always/most of the time use different syntax.
For example take PHP, Java and Python.
In Php & Java semicolons are compulsory at the end of the line, yet Python ...
27
votes
1answer
2k views
Why does C++ not have a “pure” keyword for virtual functions?
I have always wondered why we code
virtual void MyFunction() = 0;
and not
pure virtual void MyFunction();
Is there a reference for the basis of this decision?
3
votes
2answers
370 views
Why was the AT&T assembly syntax designed this way?
The AT&T assembly syntax, often called the GAS syntax, keeps surprising me. For example, its parameter order:
mov $100,%eax /* Destination after source */
This just seems so counter-intuitive! ...
27
votes
4answers
3k views
Is there a performance benefit to using the method reference syntax instead of lambda syntax in Java 8?
Do method references skip the overhead of the lambda wrapper? Might they in the future?
According to the Java Tutorial on Method References:
Sometimes... a lambda expression does nothing but ...
2
votes
2answers
203 views
Make functions that imply other functions
I'm developing a game that often has repetitious code that I can't simplify.
Example of what I do normally:
Square object;
GL11.glPushMatrix(); // Pushes a matrix stack down by one. This allows us ...
4
votes
2answers
445 views
Needs (in principle) C++ parenthesis around if statement condition?
In current C++ when body of if statements contain only one command then:
Parenthesis around if condition are mandatory but block are optional. So, both examples are OK:
if ( condition ) { return 0; ...
0
votes
1answer
69 views
Why do objects created with no assignment not generate a syntax error in Python?
While working on a Python project, I realized that during my editing I had left a string floating around in the middle of my code and it didn't generate an error. For example, these few lines execute ...
0
votes
2answers
531 views
Does any other language use the uniform initialization syntax found in c++? [closed]
Are there any other languages that use the new C++11 uniform initialization syntax thoroughly throughout the entire language, or is this entirely a C++ idiom at this point?
I tried googling and ...
2
votes
1answer
167 views
What exactly is this Python statement doing?
I'm trying to port a very basic dual contouring algorithm written in Python (here) to C++. I'm not a Python programmer so some of the language syntax is a bit foreign to me.
Specifically, this block ...
0
votes
2answers
295 views
BNF parsing rule for left associativity
Can someone please assist me with the following question.
Write a BNF rule to parse into
C -> E
C -> E && E
C -> E && E && E
so that C generates as many E ...
18
votes
5answers
3k views
When does it make sense to compile my own language to C code first?
When designing an own programming language, when does it make sense to write a converter that takes the source code and converts it to C or C++ code so that I can use an existing compiler like gcc to ...
36
votes
12answers
5k views
Why do most programming languages have special keyword or syntax for declaring functions? [closed]
Most programming languages (both dynamically and statically typed languages) have special keyword and/or syntax that looks much different than declaring variables for declaring functions. I see ...
4
votes
3answers
545 views
Intentionally incorrect use of language features, specifically “ref” in C#, as a hint to colleagues
I recently came across a piece of code something like this (roughly C#):
public bool ValidateStuff(ref ArrayList listOfErrors, Stuff thingsToValidate)
{
if (!thingsToValidate.isValid() )
{
...
0
votes
4answers
107 views
Developing configuration syntax - best practise/rules/methods?
I am currently developing a small application, which checks if provided data meets certain requirements. The requirements are actually a long list, and might be changing, so I defined a syntax which ...
0
votes
2answers
496 views
Writing a superset of a programming language as a transcompiler
My idea is to write a superset of C# (but question is not language-specific), so that it source-to-source compiles (transcompiles) to C# itself (fall-through switch clauses, default method parameters ...
16
votes
2answers
5k views
Why does C use the asterisk for pointers? [closed]
I'm just now learning about C.
I find it odd that the creators chose the asterisk (*) as the symbol for pointers rather than a symbol that actually looks like a pointer (->).
Considering how ...
3
votes
2answers
686 views
Haskell syntax for type definitions: why the equality sign?
I am a bit confused by the choice of Haskell syntax for type definitions, like in
data Foo = Bar
Namely: does the equality sign here really mean an equality in some subtle sense, or is it just a ...
7
votes
7answers
2k views
Why isn't there a next operation on enums?
In most popular programming languages like Java and C# there is a way to define enums, which are essentially datatypes with a fixed set of values, e.g. DayOfWeek.
The problem is, given a value, e.g. ...
32
votes
6answers
3k views
Why isn't testing a language a supported feature at the syntax level?
You can find an endless list of blogs, articles and websites promoting the benefits of unit testing your source code. It's almost guaranteed that the developers who programmed the compilers for Java, ...
0
votes
1answer
396 views
Syntax of passing lambda
Right now, I'm working on refactoring a program that calls its parts
by polling to a more event-driven structure.
I've created sched and task classes with the sced to become a base
class of the ...
1
vote
0answers
47 views
What syntax should I use to execute functions in jQuery Terminal?
I want to add feature, to jQuery Terminal, that will allow to execute commands from the server. Right now it only have formatting syntax that look like this:
[[<list of one letter styles> ; ...
0
votes
1answer
125 views
RFC syntax definition [closed]
I would like to bring our specifications to a better level of fine-grained definition of syntaxes, semantics and the like. I read my fair share of RFCs and just love the way they define things like ...
1
vote
1answer
197 views
Why some Javascript code needs to be written in different tags and not embedded within the same
When I was using the modernizr file, I came across this problem where in I need to source a file and call the script.
<script src="js/modernizr-min.js"></script>
<script>
if ...
7
votes
4answers
10k views
Why do C# developers newline opening brackets? [closed]
I've spent most of the last several years working mainly with C# and SQL. Every programmer I've worked with over that time was in the habit of placing the opening brace of a function or control flow ...
6
votes
6answers
1k views
Would a “downcast if block” be a reasonable language feature?
Consider the following "if cast":
class A { public void f1() { ... } }
class B : A { public void f2() { ... } }
A a = foo(); // might return A or B
if ( a is B ) {
// Inside block, ...
2
votes
3answers
1k views
Typical instantiation of new object - is there a way to avoid repetitious syntax?
When learning C# (and OO concepts more generally at the same time) something I found very distracting is exemplified by the following line:
ExampleClass exampleObject = new ExampleClass();
It's the ...
1
vote
1answer
410 views
About AST construction in LL1 non recursive parser
I have implemented a LL1 parser in a non recursive approach with a explicit stack.
The following algorithm is from the Dragon Book:
set zp to point to the first symbol of w;
set X to the top stack ...
7
votes
4answers
1k views
Why are scientific programming languages so weird? [closed]
It seems to me that programming languages meant for use in science and engineering are consistently weird compared to general-purpose languages. Some examples off the top of my head:
In Matlab, each ...
24
votes
9answers
5k views
What is the benefit of having the assignment operator return a value?
I'm developing a language which I intend to replace both Javascript and PHP. (I can't see any problem with this. It's not like either of these languages have a large install base.)
One of the things ...
3
votes
3answers
920 views
Syntactic Sugar for old languages
I first learned about the existence of syntactic sugar languages, like CoffeeScript and SASS while working in Rails. This got me thinking... why do we not have well-known (if any at all) syntactic ...
14
votes
7answers
925 views
What is idiomatic use of arbitrary blocks in C?
A block is a list of statements to be executed. Examples of where blocks come up in C are after a while statement and in if statements
while( boolean expression)
statement OR block
if (boolean ...
2
votes
6answers
901 views
Stacking keywords on top of each other - poor style? [closed]
I have always wondered about this, especially in C/Java style languages. For example, consider the first 3 lines of this C# code:
lock (serviceLock)
using (var client = new ServiceClient())
try
{
...
4
votes
2answers
983 views
Variable declaration versus assignment syntax
Working on a statically typed language with type inference and streamlined syntax, and need to make final decision about syntax for variable declaration versus assignment. Specifically I'm trying to ...
-1
votes
2answers
189 views
Languages like Tcl that have configurable syntax? [duplicate]
I'm looking for a language that will let me do what I could do with Clipper years ago, and which I can do with Tcl, namely add functionality in a way other than just adding functions.
For example in ...
7
votes
3answers
293 views
Construct your solution logic in syntax or in a faster and more efficient mental model?
I am a newbie, studying programming and I came across this question today:
How can I make sure that I'm actually learning how to program rather than simply learning the details of a language?
A ...
8
votes
6answers
1k views
Optional semicolons
Most often, in a general-purpose imperative language - semicolons as statement-delimiters are either required, or completely disallowed (e.g. C and Python).
However, some languages, like JavaScript, ...