LDraw.org Discussion Forums
Lego Description Language (LDL) - Printable Version

+- LDraw.org Discussion Forums (https://forums.ldraw.org)
+-- Forum: General (https://forums.ldraw.org/forum-12.html)
+--- Forum: General LDraw.org Discussion (https://forums.ldraw.org/forum-6.html)
+--- Thread: Lego Description Language (LDL) (/thread-24073.html)



Lego Description Language (LDL) - SNIPE - 2020-06-01

Hi,

Today, I'd like to share a project I've been working on for a few years.

It is the idea of being able to describe lego models without the use of physical or digital lego, and in a way that is:
  • Very close to English and not too unintuitive
  • Has fast development time
  • Is cross platform and highly accessable
  • Is powerful enough to represent any possible combination of LEGO parts or building techniques
  • Capable of being translated by a computer into a digital model (though this goal was originally part of a seperate "lego programming language" project)
  • Flexable parts, hinges, etc are also possible
  • Still makes the user learn about lego techniques
  • Can be converted into native LDRAW script
After a few failed ideas I think I have got a good solution but the clever thing about it is that it takes what is good about low level languages and what is good about high level languages and combines them in a harmonious way.

It works by just having the bare minimum amount of information to build a lego model:
Part type, Part ID, Primative type, Primative ID

These are simply macros for certain paramaters in an ldraw script, that's it!. Let's take a few examples:

Code:
3005 B1 c1 = 3005 B2 s1
/* place  clutch1 of BRICK1 of type 3005 onto stud1 of BRICK2 of type 3005 */
32316 L1 ph1 = 2780 PI1 pi1
/* place pinhole1 of LIFTARM1 of type 32316 onto pin1 of PIN1 of type 4274 */
/* Now what if we want to attach these two assemblies together? easy: */
3024 PL1 c1 = PIN1 c1
PL1 s1 = B2 C1
/* place clutch1 of PLATE1 of type 3024 onto clutch1 of PIN1.
   place stud1 of PLATE1 onto clutch1 of BRICK2 */

This syntax also means you can create helper assemblies in order to position more complex parts then simply DEL(ete) the helper assemblies, which after all is what you do in ldd/ldcad anyhow therefore SNOT and advanced building tequniques are possible including the ability to flex certain types of parts. So the syntax has been tried and tested and can stand up to huge and or complex models.

There are a few syntax shortcuts so far such as part/primative ranges or lists (3003 B1:B50 c1) (3005 B2 c1,c2,c3,c4,), exact part positioning co-cordinates (B2 <25,87,53>) and the IDE will also help you by having tools which leads me onto the bit where I need help from the LDRAW community: building the compiler/IDE:

The idea (assuming you are not just typing into notepad) is to have a C program read the LDL syntax and parse it into native LDRAW script but also display the digital model in real time, as you type, in a graphical output window.

This post is already kinda long so feel free to ask about the full syntax, the IDE, or the compiler, or anything else more below.

Regards, Snipe


RE: Lego Description Language (LDL) - Mark Verbeek - 2020-06-05

Hey Snipe,

What do you have already working? I like the idea.

If I understand your suggestion correctly you want to develop a DSL, domain-specific language for LEGO, which is an interesting idea. Although I wonder what its use will be or who will be using it.

Having said that, a technology called Xtext is popping up to mind. This is a method of writing your own language in the Eclipse (and IDE) using its EMF framework. It is very powerful but has a steep learning curve.

When you have written your language, let's call it LDL, in Xtext, you can then write a parser, either using Accelo or python to convert the models in LDL to Ldraw format. Writing this parser would be quite a challenge. I would not do this in C, which is way to a low level for what you want to achieve.

Also, I'm thinking on the python module Pyldraw. Where you can create/write models using the python language. The module is not very feature-rich but it can do some neat basic stuff.

Since I'm very focussed towards LEGO Technick I'm looking for some easy way to describe the relationship between axis and gears.

Kind regards,
Mark


RE: Lego Description Language (LDL) - SNIPE - 2020-06-05

Quote:Hey Snipe,

What do you have already working? I like the idea.

If I understand your suggestion correctly you want to develop a DSL, domain-specific language for LEGO, which is an interesting idea. Although I wonder what its use will be or who will be using it.

Hi,

I don't have any code right now, I did try to do it in C a few times but it got scrapped and this was really a different project called LPL which was a bad idea really.

Yes, it is a DSL and while it can be used by ldraw part authors, digital builders, and just lego nerds in general it can also be generated, i.e used to analize real or digital LEGO not just to build digital LEGO, hance the name.


I think it would be better athough harder to write it in C because, if done properly the performance is guerenteed tot still be good when its time to scale up. This (which I don't wanna delve too far into) is because with C there is no OOP overhead or hidden code within classes or within classes inside libraries that breaks or is inefficiant.

I might be able to make a basic applicaiton in C as long as there are people here who will be able to support that without re-writing it to some other language however if not then I am happy to write it in another language as you suggested since its the only real option.

Regards, Snipe


RE: Lego Description Language (LDL) - Mark Verbeek - 2020-06-12

(2020-06-05, 22:56)SNIPE Wrote: Hi,

I don't have any code right now, I did try to do it in C a few times but it got scrapped and this was really a different project called LPL which was a bad idea really.

Yes, it is a DSL and while it can be used by ldraw part authors, digital builders, and just lego nerds in general it can also be generated, i.e used to analize real or digital LEGO not just to build digital LEGO, hance the name.


I think it would be better athough harder to write it in C because, if done properly the performance is guerenteed tot still be good when its time to scale up. This (which I don't wanna delve too far into) is because with C there is no OOP overhead or hidden code within classes or within classes inside libraries that breaks or is inefficiant.

I might be able to make a basic applicaiton in C as long as there are people here who will be able to support that without re-writing it to some other language however if not then I am happy to write it in another language as you suggested since its the only real option.

Regards, Snipe
Hi,

I did some investication on the subject, I discovered this project: OpenSdraw do you know it? because it look very similair to your idea. 

On your comment on performance. I would optimise for writability and readability as you might want help for others, they will need to understand want your code is doing. I my experience that not with c. 

regards,
Mark


RE: Lego Description Language (LDL) - Mark Wellas - 2020-06-28

Hi Snipe,

I think it's a great idea - I've been working on something similar for a while as well. 

For some parts of builds, like fiddly small details and decorations, doing it in an editor like Stud.io is always going to be preferable. But for repetitive large structures I think building via code has some great advantages. For example, if built a 30 x 30 x 20 cuboid building and realised it was 2 bricks too wide, or a window should 1-brick to the left, it's a lot of fiddly effort in a visual editor to change it.

Anyway good luck with your project  Smile

Also agree with what Mark said: use a higher level language for development speed: Java, Typescript, Python: they all have good parsing libraries to help you.

Mark