If you could create your own language...

Pages: 12345
closed account (iw0XoG1T)
Seraphimsan wrote:
for christ's sake stop this arguing. now.

did the big bad troll make you sad... thanks for the laugh.
>_> It just annoys the crap out of me when people argue. I hate conflict. And this isn't /b/ so we dont need trolling faggotry. That's really the only place where it's acceptable to be a preening faggot on the internet and not have people hate you.

also 500th post.
Last edited on
If I could have a language of my own, it would be like C++ but with some changes:
-No pointers; they would not be needed. You could simply use the value of any integral variable as the address and then the type to get it as.

-The integer data type would be the only type that allows you to specify the number of bytes to use, eg
signed int@16 My128BitSignedInteger;

-You could define many functions in a loop with the name conataining having the values of strings or numbers, eg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
for(unsigned long i = 0; i < 20; ++i)
{
	//the "rapidfunc" keyword indicates that the function is created on the fly,
	//and that it uses variable values as macros.
	rapidfunc signed long Func#i#Named$SomeString$(signed long A, signed long B)
	{
		return(A * #i# * B);
	}
}

//later...

//the "callrapidfunc" keyword indicates again that variables' values may be used in
//function call. The (0) is the value to return if the function does not exist.
int x = callrapidfunc(0) Func1NamedHello(2, 4);
x = callrapidfunc(x) Func#x#NamedBye(x, 2 * x); 


-Switch and Case statements would be able to optionally accept non-constants if you use this alternative syntax:
1
2
3
4
5
6
7
8
9
10
11
switch(SomeVar)
{
	case(AnotherVar)	//() for non-constants, and
	{				//{} if you don't want to have to include a break statement
		DoStuff();
	}
	case($$ >= AlwaysVar)	//$$ indicates that value that was passed to the switch statement (in this code, SomeVar)
	{					//with this method you can use the case statement like an if statement
		DoOtherStuff();
	}
}


-Of course, you could be allowed to pass a parameter to break for the number of control structures to break out of, eg break(2); which would essentially be the default of just break;

-Functions can have optional parameters without the rest after them having to be optional as well:
1
2
3
4
5
6
7
8
long MyFunc(long A, long B = 4, long C, long D = -2)
{
	return(A * ((B - C) / (A * (B - C))) + D);
}

//later...

MyFunc(4, ~, 5); //the ~ operator, in this case, means 'use the default value for this parameter' 


-Operator !| which essentially does this:
1
2
3
4
5
//operator !| function equiv:
bool NotOr(bool A, bool B)
{
	return((A || B) && !(A && B));
}


As you can see it's a bit crazy, but it'd make some stuff simpler. I can't really think of much else to fix or add...
-No pointers; they would not be needed. You could simply use the value of any integral variable as the address and then the type to get it as.
How is that different from a pointer, other than having no type safety?

-The integer data type would be the only type that allows you to specify the number of bytes to use
Why not just have arbitrary precision integers, then?

-You could define many functions in a loop with the name conataining having the values of strings or numbers
This 'rapidfunc' thing seems weaker than anonymous functions, because they need to be named, and than regular functions, because they're less efficient and don't really add any functionality.
Also, the syntax seems redundant. From what I understand, these are all valid calls to the same function:
1
2
3
callrapidfunc(0) Func#0#NamedBye(x, 2 * x)
callrapidfunc(0) Func#0#NamedFoo(x, 2 * x)
callrapidfunc(0) Func#0#NamedBar(x, 2 * x) 
Correct? Then what's the point of the part after Named?
And why would I want to pass data through the function name? Why not just pass x as another parameter?

-Operator !| which essentially does [(A || B) && !(A && B)]
That's called XOR, or exclusive or, and it already exists in C/++: ^.
By the way, "not or" suggests a different boolean operand, NOR, which is the negation of OR.
I appreciate your criticism :)

heios wrote:
Also, the syntax seems redundant. From what I understand, these are all valid calls to the same function:
1
2
3
callrapidfunc(0) Func#0#NamedBye(x, 2 * x)
callrapidfunc(0) Func#0#NamedFoo(x, 2 * x)
callrapidfunc(0) Func#0#NamedBar(x, 2 * x) 

Correct? Then what's the point of the part after Named?
And why would I want to pass data through the function name? Why not just pass x as another parameter?


No, they are all different functions. And it isn't quite passing data through the name. Just ignore the string after name, that was an example...

In my situation I design functions in a DLL that are called by ID in their name:
Func0
Func1
Func2
ect... I have no control over this, I simply design the functions.

In some cases it would make the code on both ends of this more efficient if I could loop-create the functions with the same code but a different name. Anyway,pay no mind to me, I just wanted to participate XD
Last edited on
And it isn't quite passing data through the name.
It's different from a template in that templates are resolved at compile time. If the functions get created at run time, you may as well just use parameters.

In my situation I design functions in a DLL that are called by ID in their name:
Func0
Func1
Func2
ect... I have no control over this, I simply design the functions.

In some cases it would make the code on both ends of this more efficient if I could loop-create the functions with the same code but a different name.
Could you give a concrete example of what you're doing and how it would help?
Could you give a concrete example of what a concrete example would be?

...I'm using an SDK.
Could you give a concrete example of what a concrete example would be?
This isn't going to get into metan territory, is it?
Anyway, I think I know what you're trying to do, now:
1
2
3
4
5
6
7
8
9
10
11
#define D(x) int a_function_that_will_be_loaded_from_a_DLL_or_SO_#x(){\
    return x;\
}

D(0)
D(1)
D(2)
D(3)
D(4)
D(5)
D(6)
I'm sure there's an easier way to do this that doesn't involve defining the same basic function once, but I think what would really help in this situation is a Turing-complete preprocessor:
1
2
3
4
5
6
7
8
9
10
11
$preprocessor
define D(){
    for (int a=0;a<10;a++)
        printf(
            "int a_function_that_will_be_loaded_from_a_DLL_or_SO_%(){\n"
            "    return %;\n"
            "}\n",a,a);
}
$end

D;
I actually did something like this, once, although I like this syntax a whole lot better than what I ended up using.
Last edited on
Actually, the other program that I have no control over is the one loading the functions from my file. It's... complicated. What I need to do is make the same function over and over, but dynamically, and it must have the ID in its name. The other app calls the functions like this, based on user input:
ActionFunc0(params,...)
ActionFunc2(params,...)
ActionFunc7(params,...)
ActionFunc3(params,...)
etc...

The problem is that for certain functions it needs to call them over and over in some cases, and this causes slowdown because the ID in one of the parameters must be checked over and over. If the ID could be the function name, there would be less slowdown because a comparison would not be needed. For now I just have to manually copy and paste the functions and change the ID in their name, but it would be more flexible and easier if the functions could be created in a loop.

Unfortunately as I said,I cannot control how this whole system works. [/ramble]
Their kung fu is weak. A properly designed dynamic interface with those requirements would work like this:
1
2
3
4
5
6
void public_dynamic_interface(std::vector<function> &v){
    v.push_back(unique_function_1);
    v.push_back(unique_function_2);
    for (int a=0;a<20;a++)
        v.push_back(same_function);
}
Or like this:
1
2
3
function get_function(int id){
    //...
}
Last edited on
closed account (EzwRko23)

Maybe I'm missing something, but why would you need to make several passes (unless an identifier can be used before its declaration)? The lexer can have access to the symbol table and decide the type of any given identifier


Yeah, a lexer accessing the symbol table. Brilliant! Hope you will never work for any of the teams designing compilers. I love those programmers, who never see any problem anywhere, and for every problem come up with a new set of "brilliant" hacks.
You're a dumbass. Seriously, "retarded" just doesn't cut it. You're like on your own category of stupid.
Last edited on
Yeah, a lexer accessing the symbol table. Brilliant! Hope you will never work for any of the teams designing compilers. I love those programmers, who never see any problem anywhere, and for every problem come up with a new set of "brilliant" hacks.


Silence, troll.

-Albatross

EDIT: I was going to post an example of my language, but I think I'll wait until xorebxebx gets kicked.
Last edited on
closed account (EzwRko23)
If you happened to work on a compiler team, you would get kicked immediately for suggesting "a lexer using the symbol table". You don't have a slightest idea on how real compilers are built (and you obviously haven't built any, because you would not say such heresy, otherwise).

Last edited on
Helios, Seraphimsan, Disch, Duoas, chrisname, and everyone else: Congratz! We got him to start flaming!

xorebxebx: Why do you even bother? Most of the veterans here hate you just because you are who you are. Have you ever built a compiler? No? Have you ever reverse-engineered a compiler? No? Have you ever seen how a compiler is built? Eh?

EDIT: Maybe that was a bit mean of me.

-Albatross
Last edited on
closed account (EzwRko23)

Have you ever built a compiler? No? Have you ever reverse-engineered a compiler? No? Have you ever seen how a compiler is built?


I created a full-fledged optimizing SQL compiler for the research project at the University.

Last edited on
@xorebxebx: those are not arguments. You sound like a kid trying to outsmart some other kid. That's why people call you a troll.

If you weren't trolling, you'd explain why doing that is a bad idea, and you'd refrain from commenting on how much you think others know about compilers.
closed account (EzwRko23)
Why is it a bad idea? It should be obvious.

Ok, but for the ones that think it is not obvious: simply the symbol table is not present at the tokenization / parsing level. It should not be. And if you make it available it would compllicate the tokenizer very much (e.g. you lose the ability to generate it directly from the grammar, you need to run the parser and semantic analyzer partially to fill the symbol table). Symbol table is a structure used in the semantic phase of the compiler. Usually compilers have the following phases:

1. tokenization (lexer)
2. parsing (parser)
3. semantic analysis (binding the symbols to meanings)
4. optional: internal representation transformations / optimisation phases (there can be more)
5. target code generation (in some compilers this phase does not exist)

Each phase should use only the results from the phase that was run before it. The first two are usually done by a generated code. No-one sane these days writes these things by hand, except for some home-grown languages. Mixing the phases causes a complete mess, impossibility to create a lexer/parser using standard tools, difficulty to proove its correctness. You can "technically" do it. But it is like using mutable global variables or macros everywhere.
Last edited on
some one was WRONG?!? on the INTERNET? I can't have this can I...
Both Yacc and Bison treat lexical analysis as a subtask of parsing, not as a separate process. Your argument is invalid.
Pages: 12345