OSDev.org

The Place to Start for Operating System Developers
It is currently Mon Mar 18, 2024 9:31 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 52 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
 Post subject: ExC: Custom programming language
PostPosted: Mon Feb 13, 2017 2:07 pm 
Offline
Member
Member
User avatar

Joined: Mon Sep 12, 2016 10:21 am
Posts: 28
Location: London, UK
Hi! I'm currently working on an operating system with it's own new programming language, called ExC.

ExC is a programming language which is meant to be a decent replacement for C. It won't require any pre-existing runtime environment to run, but if you want to do any serious development with it you'll probably want to make some code libraries for printing and such. The syntax currently looks a bit like this:

Image

(subject to change, and pls don't kill me for how I placed that bracket near the struct declaration)

The syntax is similar to higher-level languages, and there are features such as function/variable hiding, packages and importing, and, of course, inline assembly. I chose to do packages instead of file paths because of three main reasons:

- Separate from directory structure (though good directory structure is definitely advised)
This is good because you can move files around without having to rewrite a thousand import statements. #getorganised

- Packages don't have to contain files
Which basically means you don't need a stdio.exc file to provide a stdio interface, which might be useful if you're doing fancy stuff with VMs.

- I like packages better, anyway
That's probably not a real reason, but Java was the first language I learned, if that helps explain why.

When you import another code file, you can reference any accessible variables and functions by specifying the file name and then using the dot operator to access the variable/function from inside the file:

Code:
package a.test.file.Example;

import a.test.file.SomeCode;

public int main()
{
    return SomeCode.aVar;
}


When I say "accessible variables and functions", I'm talking about function/variable hiding. There are two keywords dedicated to this, public and private.

- Private variables are only accessible from inside the file in which they are defined.
- Public variables are accessible from all other files.
- If a function or variable does not declare itself as public or private, then it is accessible from other files that are in the same package, or a subpackage.

Some notes:

- No, this isn't C#, but yes, it's quite similar. I expect that as development continues it'll become more distinct.
- Yes, it'll be suitable for osdev, I'm designing it with low level stuff in mind.
- Possibly, I might even make an ExC compiler in ExC. You probably wasn't curious, but it'll be possible, and it'll be a pretty large scale test of the language.

So yeah. This is the first time I'm ever making a real, general-purpose programming language. It's both fun and educational to make, and, if I remember to, I'll keep you updated on it's development. What are your thoughts and/or opinions?

_________________
I'm bored.


Last edited by Elttob on Tue Feb 14, 2017 2:35 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: ExC: Custom programming language
PostPosted: Mon Feb 13, 2017 3:22 pm 
Offline
Member
Member

Joined: Wed Oct 12, 2016 11:32 am
Posts: 34
Location: At my PC
This seems to be C# but with packages.


Top
 Profile  
 
 Post subject: Re: ExC: Custom programming language
PostPosted: Mon Feb 13, 2017 3:36 pm 
Offline
Member
Member
User avatar

Joined: Tue Aug 02, 2016 1:52 pm
Posts: 286
Location: East Riding of Yorkshire, UK
Code:
private string[] goGetSomething(int myVar)
{
    return [...] "eggs and flour";
}


"eggs and flour" doesn't look like an array of strings to me ;)

_________________
com.sun.java.swing.plaf.nimbus.InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonWindowNotFocusedState
Compiler Development Forum


Top
 Profile  
 
 Post subject: Re: ExC: Custom programming language
PostPosted: Mon Feb 13, 2017 5:28 pm 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 723
Location: Tallinn, Estonia
Elttob wrote:
Which basically means you don't need a stdio.exc file to provide a stdio interface, which might be useful if you're doing fancy stuff with VMs.


huh, wtf?

_________________
Learn to read.


Top
 Profile  
 
 Post subject: Re: ExC: Custom programming language
PostPosted: Mon Feb 13, 2017 11:21 pm 
Offline
Member
Member
User avatar

Joined: Sun Dec 25, 2016 1:54 am
Posts: 204
is this a compiled language or interpreted language or an compiled into bytecode on a VM language or what?

public/private for a package?

And not to troll but why the tertiary operator when that makes your lexer/parser to much more difficult?

_________________
Plagiarize. Plagiarize. Let not one line escape thine eyes...


Top
 Profile  
 
 Post subject: Re: ExC: Custom programming language
PostPosted: Tue Feb 14, 2017 2:31 am 
Offline
Member
Member
User avatar

Joined: Mon Sep 12, 2016 10:21 am
Posts: 28
Location: London, UK
hannah wrote:
This seems to be C# but with packages.


Not quite. ExC isn't object-orientated, and, like C, compiles to machine code. Also unlike C#, ExC is designed to do lower level stuff, hence you can make an operating system using ExC (basically what I intend to do). You wouldn't want to do the same with C#, due to the fact manipulating lower level stuff becomes more difficult, and the end result would likely not be optimal (probably you would end up with a slightly better JavaOS). And yeah, if the syntax is too similar (probably the case here lol) then I'm not really making a new programming language. Again, the syntax is subject to change, and I could probably change some syntax to make it easier for the compiler, but only marginally harder to write (e.g. adding a 'protected' keyword and requiring an access modifer wouldn't be too hard, but would simplify the variable and function code, since most of the time you'll probably be using public/private anyway)

dchapiesky wrote:
is this a compiled language or interpreted language or an compiled into bytecode on a VM language or what?

public/private for a package?

And not to troll but why the tertiary operator when that makes your lexer/parser to much more difficult?


1. Compiled language, no VM's required but you could if you wanted to.

2. I'm not sure what you mean by that. I'll assume you're talking about hiding packages, which could be useful. I'll consider it :p

3. I like the tertiary operator personally, and yes, that makes my compiler more complex, but I'll be able to manage (hopefully) since I'm implementing more core features first (i.e. functions and variables) before working on other, less required features (i.e. arrays, structs and the tertiary operator ofc :p )

dozniak wrote:
Elttob wrote:
Which basically means you don't need a stdio.exc file to provide a stdio interface, which might be useful if you're doing fancy stuff with VMs.


huh, wtf?


I'll give an example since I acknowledge this wasn't really clear. In some languages you can access certain functions and variables which you can't actually write yourself. For example, in Lua, the print() function doesn't exist as a Lua function, instead the call is passed to the Lua VM to output stuff, meaning you can't write the print() function yourself. Hope that helps!

matt11235 wrote:
Code:
private string[] goGetSomething(int myVar)
{
    return [...] "eggs and flour";
}


"eggs and flour" doesn't look like an array of strings to me ;)


Nice catch! I was probably half-asleep while writing this :p

_________________
I'm bored.


Top
 Profile  
 
 Post subject: Re: ExC: Custom programming language
PostPosted: Tue Feb 14, 2017 2:38 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7612
Location: Germany
Elttob wrote:
ExC isn't object-orientated...


Elttob wrote:
Code:
TestTwo.publicFunc( ... )

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
 Post subject: Re: ExC: Custom programming language
PostPosted: Tue Feb 14, 2017 3:11 am 
Offline
Member
Member
User avatar

Joined: Mon Sep 12, 2016 10:21 am
Posts: 28
Location: London, UK
Solar wrote:
Elttob wrote:
ExC isn't object-orientated...


Elttob wrote:
Code:
TestTwo.publicFunc( ... )


Yeah, that's the only arguable part of it. Personally, I would still argue ExC isn't object-oriented as the only OO-like features ExC implements are member hiding and, of course, the way you reference functions and variables from other files could be considered OO-like. However ExC does not have classes, inheritance, abstraction etc.

In reality ExC is probably only object-oriented to a small degree, but I may be wrong since I'm practically self-taught and only learned of programming paradigms in the last 5 months or so.

_________________
I'm bored.


Top
 Profile  
 
 Post subject: Re: ExC: Custom programming language
PostPosted: Tue Feb 14, 2017 3:34 am 
Offline
Member
Member

Joined: Sun Feb 01, 2009 6:11 am
Posts: 1070
Location: Germany
Solar wrote:
Elttob wrote:
ExC isn't object-orientated...


Elttob wrote:
Code:
TestTwo.publicFunc( ... )

This is valid C code if TestTwo is a struct and publicFunc a function pointer. Does that make C object oriented?

I think the most important concept of OO is not the syntax of function calls, but inheritance and polymorphism, and this is completely missing.

_________________
Developer of tyndur - community OS of Lowlevel (German)


Top
 Profile  
 
 Post subject: Re: ExC: Custom programming language
PostPosted: Tue Feb 14, 2017 3:38 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7612
Location: Germany
How can you tell?

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
 Post subject: Re: ExC: Custom programming language
PostPosted: Tue Feb 14, 2017 5:38 am 
Offline
Member
Member
User avatar

Joined: Wed Aug 17, 2016 4:55 am
Posts: 251
Kevin wrote:
This is valid C code if TestTwo is a struct and publicFunc a function pointer. Does that make C object oriented?

That was the whole idea behind COM, to be fair.


Top
 Profile  
 
 Post subject: Re: ExC: Custom programming language
PostPosted: Tue Feb 14, 2017 5:49 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7612
Location: Germany
To be completely fair, "object orientation" is about how much a language supports that programming style. Function pointers in structs are one step. Information hiding by public / private is another. Inheritance is the next. Polymorphism the next, and so on.

There is no cut-and-dried border at which there are "OO" languages on one side, and "non-OO" on the other. But ExC is further down the road than C is (though not as far as C++ is).

----

Generally speaking, though, I consider either creating a feasible OS or creating a feasible programming language to be a more-than-one-man-sized endeavor. And I don't really see that much of a niche for a system programming language between C and C++. There are a lot of languages who've made an attempt at that niche, among them quite successful ones like D or Rust.

So. Why ExC instead of C, C++, or Rust? Give me the elevator pitch.

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
 Post subject: Re: ExC: Custom programming language
PostPosted: Tue Feb 14, 2017 5:56 am 
Offline
Member
Member
User avatar

Joined: Thu Mar 27, 2014 3:57 am
Posts: 568
Location: Moscow, Russia
How does "return null" work? Does it return a null pointer? If yes, then why doesn't the return type mention that a pointer is returned?

Why is it better than C++ and Rust?

_________________
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay


Top
 Profile  
 
 Post subject: Re: ExC: Custom programming language
PostPosted: Tue Feb 14, 2017 8:45 am 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
Solar wrote:
There is no cut-and-dried border at which there are "OO" languages on one side, and "non-OO" on the other.


<well-actually mode="pedantic yet of questionable validity">
There is, but it isn't a useful one as it rules out pretty much everything except Smalltalk, Self, and a handful of toy languages, and if followed strictly would hamstring efficiency.

Most of the characteristics Alan Kay defined for OO in the old days were in fact consequences of the actual defining aspect of OO, namely that all communication between objects is done through message passing - by which I mean, the object would be passed a data structure with the name of the method (or a hash of same) and the invocation arguments, which the object's resolver/mini-interpreter would parse, and then look up the matching method for in a table.

The dot notation used in most later OO languages (starting with C++, though it was itself taken from Simula, which was one of the inspirations for both Kay and Stroustrup) was meant to mimic this, while avoiding the inefficiency of actually sending messages to independent objects which would then have to interpret them and match them to a given method (which would itself be made up of messages, drilling down until you hit primitives).
</well-actually>

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.


Top
 Profile  
 
 Post subject: Re: ExC: Custom programming language
PostPosted: Wed Feb 15, 2017 2:12 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7612
Location: Germany
This is the point of "well, actually..." where The Mighty Jingles of Youtube fame usually edits in a soundbit of a rifle being cocked and fired. :-D

But let's return to the elevator pitch. Why ExC, and not C, Rust, C++? Is ExC something you do "because you can", i.e. for no particular reason (which would be fine for me), or do you think ExC is bringing something of actual value to the table?

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 52 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group