HiveBrain v1.2.0
Get Started
← Back to all entries
patterncppMinor

"Nothing" interpreter/compiler

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
interpreternothingcompiler

Problem

This is an implementation of the Nothing programming language. The language spec is as follows:

Design philosophy


In the current software industry focus lays on solving complex
problems by using complicated algorithms. The language "Nothing" was
created to shift this focus from complex problems towards the
expectations of the programmer and the user. This way even the most
complicated programming challenges swiftly disappear as if they never
have existed before. Basically, the main strengths of the language
"Nothing" are:



  • to create bug-free and portable software https://esolangs.org/wiki/Nothing



  • to shift focus from complex technical solutions towards the expectation of the programmers and users




Program structure


Nothing has a very simple and straightforward structure. It is a
typeless language which does not use any of the known programming
constructs like loops, choices and the like. It is the only language
which can be considered 1GL, 2GL, 3GL, 4GL and 5GL all at the same
time.

What I would like to know:

  • Does my program conform to the language specs?



  • Does it follow the design philosophy?



  • Readability, performance, etc. Any improvements welcome



Source code:

/*
 * A 'Nothing' compiler
 * 
 * September 2010, RoPe Development Inc.
 *
 * Author: authorname
 */

#include 
#include 
#include  // EXIT_FAILURE
#include  // std::char_traits::eof

int main(int argc, char* argv[])
{
    if (argc ::eof())
    {
        std::cerr << "nothing: fatal error: program is not empty\n";
        std::cerr << "compilation terminated.";
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}


Example:

# bash
$ touch helloworld.not
$ ./nothing helloworld.not
$

Solution

This line here:

return EXIT_SUCCESS


Is equivalent to this:

return 0;


Which is automatically inserted by the compiler if it isn't found. In short, return EXIT_SUCCESS can be removed.

In addition, a few of your error messages don't include a newline at the end, as seen in this line here, and two other places:

std::cerr << "compilation terminated.";


I'd just add a newline to the end of the output string to not annoy the user when the program completes/fails, like this:

std::cerr << "compilation terminated.\n";


Instead of requiring the user to provide a file in the command line arguments, you can just do, well, nothing. This is the language Nothing after all. This means that this piece of code here:

if (argc < 2)
{
    std::cerr << "nothing: fatal error: no input files\n";
    std::cerr << "compilation terminated.";
    return EXIT_FAILURE;
}


Can just become this:

if (argc < 2)
{
    return 0;
}


Other than those two nitpicks, there really isn't much else for me to review here. As far as I can tell, you've followed the language specification just fine, and produced some readable code.

Code Snippets

return EXIT_SUCCESS
std::cerr << "compilation terminated.";
std::cerr << "compilation terminated.\n";
if (argc < 2)
{
    std::cerr << "nothing: fatal error: no input files\n";
    std::cerr << "compilation terminated.";
    return EXIT_FAILURE;
}
if (argc < 2)
{
    return 0;
}

Context

StackExchange Code Review Q#102248, answer score: 8

Revisions (0)

No revisions yet.