Beta .hcc to .c language compiler.
:cool: Hyper C Compiler
Printable View
Beta .hcc to .c language compiler.
:cool: Hyper C Compiler
structure:Quote:
Just as any language was created for easier to read/write programs such is hyperC. Hyper C evolves the language to the next level and brings several improvements in code writing efficiency. HyperC is designed to streamline as much as possible; abstract lower-level commands with evolved parameter objects; as well as simplify program architecture.
C
HyperCCode:for (int i=0;i<=10;i++) { };
CCode:loop 0 to 10 as i { };
HyperCCode:if (variable == value) {
} else if (variable == otherValue) {
} else { };
CCode:case variable == value {
} || variable == otherValue {
} else { };
HyperCCode:#include "somefile.txt"
CCode:"somefile.txt";
HyperCCode:printf("%s",stringVar);
Code:ink $stringVar;
You still need a great deal more explanation of both the syntax, its semantics, and exactly why for each feature if you want people to actually start using this. You have examples, but while you know exactly what's going on in your examples, you need to explain them to the reader.
Right now, it still looks like an incoherent mess to me, and this is comparing it with C which is already a mess in places.
Oh, and the other thing is that having "Microsoft Windows Operating System" as a requirement means that your project is going to die like Delphi, except that it might not even live like Delphi.
There are some very simple things that you need to explain, e.g., whether your C variant still allows omitting of braces for single statement blocks, and whether semi-colons are always required, e.g. this:
Typically wouldn't have that semi-colon at the end in C, but it appears in your HyperC example. Is that significant? Furthermore, it can be rewritten as:Code:if (variable == value) {
} else if (variable == otherValue) {
} else { };
Whereas if we tried to so the same in HyperC:Code:if (variable == value)
foo();
else if (variable == otherValue)
bar();
else
baz();
Is that still valid?Code:case variable == value
foo();
|| variable == otherValue
bar();
else
baz();
Other design issues: does using $ # and ## really help? Don't they just make things cryptic? How do you account for unsigned int, long, float, long double, wchar_t?
Why is the main function defined with @, and then possibly with @main? What about other functions? This seems like a misplaced feature: the return type and signature of the main function is hardly a stumbling block in the writing of C programs as it tends to be a write-once-forget-about-it thing.
EDIT:
I just realised I missed the example of the display function:
Why is it $@* rather than $*@? Also, does this mean that you're returning to the use of default int since main isn't declared as #@main even in its longer form?Code:$@*display($data[]) {
END EDIT
The with keyword might be good idea, but your example is for a preprocessor directive. Does it apply elsewhere? And if it does, why doesn't it have preprocessor syntax instead? Are you aware that in C, the preprocessor tends to be rather different than normal C syntax and semantics?
Here's another one:
What's the reason for the # and the $ with ink? It surely cannot be a typecast because the type of (10 + 10) is already int, and surely you don't want to cast the return value of display to char when it should be a string. So do you even need them? Surely the compiler can determine the types and generate the equivalent printf from ink, so you can just write:Code:ink #(10+10);
ink $display("Hello");
Code:ink (10+10);
ink display("Hello");
Oh, and why do you require comments to be terminated by a semi-colon? Doesn't that go against your design goal "to streamline as much as possible"?
HyperC requires every line of code end with a semicolon, as well as the end of brackets for statements.Quote:
whether your C variant still allows omitting of braces for single statement blocks
Quote:
Is this still valid?
no.Code:case variable == value
foo();
|| variable == otherValue
bar();
else
baz();
HyperC is c, you can use any type.Quote:
How do you account for unsigned int, long, float, long double, wchar_t?
Code:
float mynumber;
long double;
The standard HyperC entry point function is..Quote:
Why is the main function defined with @, and then possibly with @main?
This is equivalent to..Code:@{ };
Functions in HyperC are as follows...Code:int main(int argc, char *argv[]) { };
This is equivalent to...Code:@myfunction{ };
This allows for a custom entry point function where you might not want to use argc, and argv but your own variables.Code:void myfunction{ }
You can also use the parameter -w to use the winMain as @.
Ink is output to the console.
$ is a string, # is an integer, ## is a double.
HyperC
cCode:ink "name:" $name " number:" #number
Code:printf("name: %s number: %i",name,number)
also development of the actual code. It's not complete it's still in beta.Quote:
You still need a great deal more explanation
Here is a short video showing how to use ink, and functions.
HyperC was originally called arc.
YouTube
That doesn't answer my question pertaining to braces, and introduces another one: why does HyperC require every line of code to end in a semi-colon, including what C does not require? Doesn't this go against the design goals of HyperC?Quote:
Originally Posted by Structure
That just repeats what's already in your documentation withoit answering my question. I'm saying that your syntax sucks in relation to your stated goals for your language, and this particular syntax that I'm criticising is used in ink. You might have a good reason for it, but right now it's looking like the very boilerplate that you're trying to streamline, so my question is why do you require that # and $ be used with ink when the types can be deduced at compile time.Quote:
Originally Posted by Structure
i disagree.Quote:
your syntax sucks
So that you can easily see the value type and there is no confusion as to what is happening.Quote:
why do you require that # and $ be used with ink when the types can be deduced at compile time
This also reduces a step in the compilation process.
So rather than have your compiler do a thing that compilers are want to do, you foist that onto the user?
Turning C into Perl, one graphic character at a time.
You turned printf into ink.
What if I want to print to stderr, or indeed any other open file?
You turned if/else into case.
What if I want to use an actual switch/case ?
> code writing efficiency
When you get past the student homework phase, you're going to be spending more time reading lots of documentation, design, other code than actually writing new code.
The modern trend is creating languages which are easy to read and understand by humans. Programs are read by humans far more often than they are written by humans (if you exclude the write once, read once, throw away student assignments).
HyperC fails so miserably on the readability scale because you seem to think that the only thing that matters is keystrokes when entering the program for the first time.
I'm reminded of this.
Question 10.2
And this.
The International Obfuscated C Code Contest
That's not a bad goal, but C's printf already provides that with the format specifers. Contrast:Quote:
Originally Posted by Structure
With HyperC:Code:printf("x=%lu", x);
It is clear that for the goal of "code writing efficiency", C's printf wins against HyperC's ink while being equal in the goal of "no confusion as to what is happening" except for the special cases of int, double and char (but then the shortcuts for these are arguably cryptic, which is a minus point for the latter), i.e., HyperC's syntax sucks when measured against its stated language design goals. Whereas if HyperC left out the type requirement:Code:ink "x=" unsigned long x;
HyperC would win in the former; and while C might have a slight advantage in the latter, it can be mitigated by code hinting tools that are widely available among editors/IDEs these days, i.e., HyperC's syntax would now be good when measured with its stated design goals.Code:ink "x=" x;
Furthermore, I note that in your documentation under "variables", you state that "$ = CHAR", but in post #10 you state that "$ is a string".
next...Quote:
When you get past the student homework phase
This is an interesting concept. I would agree it sounds good and i will take a look at implementing such a thing. It actually opens up a lot of things as far as not just for ink. My only issue is being able to see the variable type quickly when looking at it.Quote:
if HyperC left out the type requirement
Aside from the confusion... like i said it's beta and i appreciate the comments.Quote:
you state that "$ = CHAR", but in post #10 you state that "$ is a string"
FYI: this works...
Code:
@{
$*str = "testing";
ink "%s", str;
};
including files:
using with ;Code::>filename.c;
with prepends to every line.
setting with to nothing escapes it.
using and ;Code:with someObject.;
name = "testing";
number = 001;
with;
and appends to every line.
setting and to nothing escapes it;
example:Code:and "\n";
ink "line 1";
ink "line 2";
ink "line 3";
and;
Code:loop 1 to 15 as i {
with ink ; and "\n";
"line %i", i;
and;with;
};
HyperC is for developersQuote:
easy to read and understand by humans
so that you are free to structure code in any way you like.Quote:
why does HyperC require every line of code to end in a semi-colon
such as long lines of multilines, even the whole project in one line if you want.
:oQuote:
you seem to think that the only thing that matters is keystrokes
interesting...Quote:
HyperC's syntax would now be good when measured with its stated design goals.
Have you forgotten that (other than specialised AI), developers are humans?Quote:
Originally Posted by Structure
Why not make them optional for such cases instead? After all, what you have described are generally coding anti-patterns or would be automated (as in the case of compressed Javascript), so they shouldn't see much use being written by developers beyond obfuscated code contests.Quote:
Originally Posted by Structure
Semicolon - WikipediaQuote:
Why not make them optional
Quote:
this was a divisive issue in programming languages from the 1960s into the 1980s.
Quote:
two statements are placed on the same line; this is legal, because the semicolon separates the two statements.
Quote:
The semicolon, as a mark separating statements, corresponds to the ordinary English usage of separating independent clauses, and gives the entire program the gross syntax of a single ordinary sentence.
You should actually make an argument supporting your own language's design goals rather than just quote wikipedia.
When compiling you can use -x to skip HyperC compilation.
This can be used to create your own compilation structures...
usingexampleCode::>filename.ext;
Code::>header.file;
int main() {
:>main.file;
};
Code:<stdio.h>;
@numbers( #one, #two) {
ink "%i\n", one;
case one != two {
case one > two {
one--;
} || two > one {
one++;
};
numbers(one,two);
};
};
@{
float n = 0;
ink "Enter Number: ";
scanf( "%f", &n );
numbers( 1, n );
};
It works.Quote:
What if I want to use an actual switch/case ?
Code:a = 1; b = 2;
case b == 2 {
switch (a) {
case 1:
ink "it works.";
break;
};
};
invalid.Quote:
ink "x=" unsigned long x;
false.Quote:
you're going to be spending more time reading lots of documentation, design, other code than actually writing new code
If this is invalid:
Why is this valid?Code:ink "x=" unsigned long x;
HyperC looks to be so inconsistent as to be unusable.Code:ink "x=" #x;
Are you familiar with expressing grammar formally? At the moment it looks like you're mostly making things up and so there's no rhyme or reason as to why some syntax is valid whereas other syntax is invalid.
These are also valid:Quote:
HyperC looks to be so inconsistent
Code:printf("x=%lu", x);
Code:ink "x=%lu", x;
no.Quote:
Are you familiar with expressing grammar formally?
I built HyperC...Quote:
making things up
Yep, that's inconsistent, and furthermore it becomes confusing: your ink functionality really provides practically nothing over printf, whereas you could have tweaked it to do easier printing that doesn't require format strings.
ink is something you can use, you don't have to.Quote:
your ink functionality really provides practically nothing over printf
HyperC is for the developer to have freedom to structure their code how they want, as well as have options for faster coding of frequently used functions/statements.
$ and # , are quick access to char and int which are used commonly imo.
with and and, are prepend/appends for less redundancy.
interesting...Quote:
you could have tweaked it to do easier printing that doesn't require format strings.
Type this 100 times:
or this 100 times:Code:for (x=1;x<=5;x++) { };
Code:loop 1 to 5 as x { };
That's poor justification for limiting a feature that could have been useful.Quote:
Originally Posted by Structure
I want to structure my code such that I can use ink for printing unsigned long variables without a format string, and such that I don't have to use semi-colons in places that C does not require ;)Quote:
Originally Posted by Structure
Import File As String:
Compile with @Entry function as winMain:Code:$*string = ":$>test.txt;";
For Loop example:Code:hcc file.hcc file.c -w
Code:loop 1 to 10 as i {
ink "%i \n", i;
};
not going to happen.Quote:
such that I don't have to use semi-colons in places that C does not require
Ok. You can now use any type with ink.Quote:
I want to structure my code such that I can use ink for printing unsigned long variables
Also valid:Code:ink [lu]variable;
Also valid:Code:ink "int: " [i]value " char: " ^chr;
Code:ink "string1: " + [s]one + "\n string2: " + [s]two;
true.Quote:
That's poor justification for limiting a feature that could have been useful.
I assumed the more options available then in return you can pick what works for you was less confusing.Quote:
furthermore it becomes confusing
When compiling there is a file you can use called: base.hed
in the same directory as hcc.exe create the file base.hed
This file is a header included in every hcc compilation at the top of the file.
HyperC does not compile this file it is imported as raw data.
base.hed
program.hccCode:#include <stdio.h>
#define ON 1
#define OFF 0
command:Code:@{ ink "Hello World"; };
Code:hcc program.hcc program.c
HyperC functionality: get *string*
This function will take input from stdin and put the input in a string.
example:
Code:<stdio.h>;<string.h>;
@{
ink "Enter Your Name: ";
get val;
ink "Hello " [s]val ".";
};
side note:
I understand the concept of not have the types, also why this would be geared toward my design premise.
I prefer to be able to see the type of variable with a quick look.Code:ink "string1: " one "\n string2: " two;
i.e:
I can quickly see that those are strings versus having to determine.Code:ink "string1: " [s]one "\n string2: " [s]two;
HyperC is currently only available as a windows executable.Quote:
"Microsoft Windows Operating System" as a requirement
Creating file structures using hyperC compiler:
The compiler has many features...
Use the -x option in hyperC.
website.hcc
compile:Code:<!DOCTYPE html>
<html lang="en">
<head>
:>head.file;
</head>
<body>
:>body.file;
</body>
</html>
Code:hcc website.hcc index.html -x
Code:<stdio.h>; <string.h>;
@{
ink "Name: "; get name;
loop 0 to strlen(name) as i {
ink ^name[i];
};
};
Distance between location1 and location2:
Code:<stdio.h>; <string.h>; <math.h>;
vector! { float x, y, z, w; };
float distance( float x1, float y1, float z1, float x2, float y2, float z2 ) {
float x,y,z,w;
x = pow(x2 - x1,2);
y = pow(y2 - y1,2);
z = pow(z2 - z1,2);
return sqrt(x + y + z);
};
@{
and = !vector;
location1; location2;
and;
with location1.; x = 0; y = 0; z = 0;
with location2.; x = 1; y = 1; z = 1;
with ink ;
"The distance \n from: ";
[f]location1.x "," [f]location1.y "," [f]location1.z "\n to: ";
[f]location2.x "," [f]location2.y "," [f]location2.z "\n is: ";
[f]distance(location1.x,location1.y,location1.z,location2.x,location2.y,location2.z);
with;
};
command prompt:
Code:<stdio.h>; <string.h>; <stdlib.h>;
with #define ;
_TRUE 1; _FALSE 0;
with;
int compare($*string1,$*string2) {
int response = _TRUE;
loop 0 to strlen(string1) as i {
case string1[i] != string2[i] {
response = _FALSE;
};
};
return response;
};
@{
menu: {
ink "Enter command: "; get command;
case compare(command,"exit") == _TRUE {
exit(1);
} || compare(command,"cls") == _TRUE {
shell "cls";
};
run menu;
};
};
This is a beta feature that is still being developed.
Passing functions to functions as callBacks:
You can currently pass 1 function only...
:cool:Code:<stdio.h>; <string.h>;
@call(int times,@callBack) {
loop 1 to times as i {
callBack(i);
};
};
@{
call(10, @(int x){
ink "Number: " [i]x "\n";
});
};
extended example:
program.hcc
argc is the amount of arguments passed.Code:<stdio.h>; <string.h>;
@call(int times,@callBack) {
loop 1 to times as i {
callBack(i);
};
};
@{
call(atoi(argv[1]), @(int x){
ink [i]x "\n";
});
};
argv[] is the array passed from the command line.
i.e:
Code:program 5
Code:program 10
BUILD.BAT
Code:@echo off
hcc %1.hcc %1.c
echo compiling...
gcc %1.c -o %1.exe
echo done.
program.hcc
:cool:Code:<stdio.h>; @{ ink "Hello World"; };
It looks like get implicitly declares the string, which leads to the question: what is the type of this string? Is it an array of char, and if so, what is its size? Is it a pointer to char with dynamically allocated memory? If so, should free be called?Quote:
Originally Posted by Structure
The string is a char[] null terminated array.Quote:
what is the type of this string? what is its size?
I believe that is a preference.Quote:
should free be called?
Code:clear value;
constructing formatted strings:
Code:<stdio.h>; <string.h>;
@{
with char ;
string1[100]; string2[100];
with float ;
a = 1.0; b = 2.0; c = 3.0;
total = 0;
with;
string1 = "a = %f, b = %f, c = %f", a, b, c;
total = (a+b+c);
string2 = "a+b+c = %f", total;
ink [s]string1 "\n" [s]string2;
};
Fibonacci Series:
Code:<stdio.h>; <string.h>;
@{
int current = 0, next = 1, temp;
ink "Enter the number of terms: "; get number;
ink "Fibonacci Series: ";
loop 1 to atoi(number) as i {
ink [i]current;
case i != atoi(number) { ink ", "; };
temp = ( current + next );
current = next; next = temp;
};
};
Feel free to download and try hcc.exe
If you are wondering about a feature or have an idea on how to improve HyperC post your thoughts.
You can find it here:
Hyper C Compiler
That's an incomplete answer. Remember, if you're reading input to be stored in an array, the size of the array must be known in advance, whether it is a fixed size array or a variable length array. So, what's the size of the array? What if a larger array is required to fit all the input? What if the input is too large for the array? Can the size of the array be customised with get?Quote:
Originally Posted by Structure
It isn't: calling free on an array of char results in undefined behaviour. As you're building on C, this means that you must either define the behaviour, or be explicit about retaining it.Quote:
Originally Posted by Structure
This is a meaningless example. When giving examples, provide context and explain both syntax and semantics. You have this same issue in your documentation, which makes HyperC hard to understand. Ideally, provide both tutorial format documentation to guide potential users, and reference style documentation to properly document syntax and semantics.Quote:
Originally Posted by Structure
By the way, you should take care about reserved words: are you really intending to make get and clear reserved words? They are so commonly used.
Obviously, I am horrible at documentation.Quote:
Ideally, provide both tutorial format documentation to guide potential users, and reference style documentation to properly document syntax and semantics.
It will be by the end of the day. :cool:Quote:
Can the size of the array be customised with get?
tbh, i can do whatever i want. I built it.Quote:
this means that you must either define the behaviour, or be explicit about retaining it.
Not saying that I'm volunteering, but one option then is to team up with someone who's better at documentation. This has the added benefit of being able to talk over stuff with someone else and hence improve your programming language.Quote:
Originally Posted by Structure
Sure, but if nobody else knows how to use the constructs of your programming language because in your arrogance as language designer you keep things to yourself, then they simply aren't going to use your programming language. If you're interested in seeing adoption, then you have to define stuff and communicate it so potential users will understand the expected semantics.Quote:
Originally Posted by Structure
It is now required that you set the size of the array.Quote:
Can the size of the array be customised with get?
i.e:
before you would use get name.Code:<stdio.h>; <string.h>;
@{
ink "Enter your name: ";
get name[100];
ink "Hello " [s]name ".";
};
now you define the size of the array: name[10];
Goals.Quote:
improve your programming language.
Possibly...Quote:
interested in seeing adoption
As far as the source goes, absolutely.Quote:
keep things to yourself
bummer.Quote:
they simply aren't going to use your programming language.
That's what these posts are for.Quote:
if nobody else knows how to use the constructs of your programming language
You can stop misquoting me now: I wrote that in reference to your reply to me that "tbh, i can do whatever i want. I built it." when I reminded you that "calling free on an array of char results in undefined behaviour" hence you "must either define the behaviour, or be explicit about retaining it", which is just common sense: if you don't say when undefined behaviour in C is defined in HyperC, who would know?
Furthermore, while it is alright to seek feedback for HyperC on this forum, you should be putting your actual HyperC documentation on its website, not here.
oops?Quote:
You can stop misquoting me now
tbh, I have no idea what this means.Quote:
if you don't say when undefined behaviour in C is defined in HyperC
Do you understand what "undefined behaviour" means in C? It's important for HyperC since you want to build HyperC on C. If you were designing HyperC from scratch instead, you might choose to ditch the notion of undefined behaviour, which primarily has value for optimisation at the cost of potential bugs.Quote:
Originally Posted by Structure
I do not. I'm self taught and still learning.Quote:
Do you understand what "undefined behaviour" means in C?
The Wikipedia article is a good starting point: undefined behaviour
It's essential knowledge for a C programmer because it is such a source of bugs, and even more so if you're designing a language that builds on C, or if you're writing a compiler that uses C as its intermediate language.
This is how i see it.Quote:
It is the responsibility of the programmer to write code that never invokes undefined behavior.
Are you saying i should try not to allow undefined behaviour?
If you program with HyperC and you cause an error how is that my fault ?Quote:
This means that the responsibility is on you to define HyperC rigorously
If HyperC is the cause of the error i will fix it.
FYI rigorous is an understatement for my coding techniques.
Im still confused about the difference between undefined behavior and a mistake.
There should be some sort of structure and rules i think.Quote:
you want HyperC to retain the notion of undefined behaviour.
It isn't!
You forgot to check the return value of fgets when providing an example in the C programming forum recently :pQuote:
Originally Posted by Structure
But anyway, I'm talking about rigour of language specification, not code.
Consider a common programming mistake:Quote:
Originally Posted by Structure
In C, this results in undefined behaviour: the compiler is free to produce a program that does practically anything on that out of bounds assignment to numbers[10]. In other programming languages, this error might be well defined, e.g., perhaps the wrong assignment would cause an exception to be thrown, and this is guaranteed to happen.Code:int numbers[10];
for (int i = 0; i <= 10; ++i)
numbers[i] = i;
Here's another common beginner's question in C:
What's the output? In C, the answer is that the behaviour is undefined, so this is actually a mistake because of how sequence points/sequenced before/after work in C. In languages that don't have the notion of undefined behaviour, they might define it, so this would not be a mistake... or they might explicitly say that such use is an error, and hence require the compiler to reject the code with an error.Code:int x = 0;
printf("%d\n", x++ + x++);
Importing shaders:
Code:<c static const char* vertex_shader_source = ":$>shaders/vertex.glsl;";
<c static const char* fragment_shader_source = ":$>shaders/fragment.glsl;";
If anyone wants to actually try the compiler and give me comments that would be fun. I built the compiler for myself but thought it might be usefull to others. tbh i'm not trying to put it out there i'm fine using it myself but if you want try it out and help me build a better c i'm all ears.
go away.Quote:
Perhaps if it was open source then I'd give it a go.
I understand this issue and people are scared of running .exe i get it.Quote:
As for running a random .exe
If people want to use it and maybe if it works out i will open-source a bare bones version.Quote:
Why not open source it?
Hyper C CompilerQuote:
Ok, I want to use it
Let me know if you have any questions.
When compiling to .c at the top of the c file you should see a compiled with hyperc version. The current version is v5.
During the v4. process i came across some errors while adding new features.
Those have been fixed. So if you do come across an error make sure it is v5 as it may already be fixed.
A simple menu system:
Code:<stdio.h>; <stdlib.h>; <conio.h>;
#@drawMenu() {
with ink ;and "\n";
"Menu ";
"-------------";
"[1] cls";
"[2] dir";
"[esc] exit";
"-------------";
and;
"selection: ";
with;
return getch();
};
@menu() {
switch (drawMenu()) {
case '1':
shell "cls";
break;
case '2':
shell "dir";
break;
case 27:
exit(1);
break;
default:
ink "Invalid Selection.\n";
break;
};
menu();
};
@{
menu();
};
TBH, all this belongs on a blog on your own forum, where people who are actually interested can follow your wandering thoughts.
ok then.Quote:
this belongs on a blog on your own forum
Have people ever heard of innovation and integrity ?Quote:
where people who are actually interested can follow your wandering thoughts.
What happens if the input file doesn't fit into a char array of size 1000000 and why read the entire file into memory?
Also it would be nice to check that calls to fopen() succeed before reading from the file and then call fclose() after you're finished with it
I have not had a problem with the program size yet.Quote:
What happens if the input file doesn't fit into a char array of size 1000000 and why read the entire file into memory?
When importing files i have definitely come across size issues.
I built it awhile ago and it could use some improvements.
I thought that i closed anything i opened...Quote:
Also it would be nice to check that calls to fopen() succeed before reading from the file and then call fclose() after you're finished with it
In the function where you read the entire file into a global array, you open a file (without checking that it was actually opened) and then proceed to read the file (using fgets into a 256 char buffer and adding what's read to the global) and when finished not close the file. As far as I can see anyway.
Update: v5.1
I closed the file, thank you.Quote:
call fclose() after you're finished with it