Is it possible to create an in game compiler for a programming language such as c++ or python? I mean import the language and use it in a way that the player can interact with objects

What I would like to do is create import a programming language in order to be used to program something in game. Say for example the player is given a reactor with sensor outputs and inputs and are told to give parts of it commands depending on different conditions.

Does anyone know if this would be possible? I want to base it on real languages rather than create one just for the game, for example c++, python or maybe multiple different languages so that the player can chose what they are comfortable with or want to learn.

I know I could essentially create the language from scratch in a sudo sort of way but I think that could lead down a very dark path full of bugs and tears haha. Games like shenzhen i/o are a bit of an inspiration for this but I would like to drive it into hardware design as well, so you design your board, and connect them up to the inputs and outputs for example inputs 5v vcc then 240v and a sensor input, outputs GND and the 240v one.
Create something that turns off the mains when the sensor input is at whatever value. I really mean to make this a bit more indepth by requiring resistors to build voltage dividers to protect your chips etc.
Product Version: UE 4.14

If you want to embed a compiler in your game and dynamically compile and execute code, the following links might be of interest to you.

https://docs.python.org/2/extending/embedding.html
This describes the process of embedding the python VM into a C++ application.

TinyCC is a C compiler that provides a libtcc library that you can embed in your application to dynamically compile and execute C code.

http://www.mono-project.com/docs/advanced/embedding/
This page describes the process of embedding mono (a .NET Toolchain/Runtime (C#/F#/VB/etc)) into a C++ application.

There are various other options available if you look around a bit, but that should helpfully give you an idea of whats involved.

That is brilliant information! Thank you. Looks like python might be the ticket!

I’d like to caution you that python can be a real pain in the ■■■ to build content with.

It’s a weakly typed, interpreted language without explicit variable declaration. While for some reason people have gotten it into their heads that that means it’s “easy for designers to use,” what that means is that it’s a pain in the butt to test.

For example, let’s say you misspell or miscapitalize a variable somewhere in your script. In a C-like language, you’d discover that at compile time.

In Python, you discover that when you build your content, launch the game, play to that part of the level where the content is used, and then repeat doing that over and over until your misspelled variable causes a problem which is obvious enough to see in the content. And then you have to figure out why by examining all of the script, rather than being pointed to the problematic line.

Think, as a coder, of how many compiler errors you get even doing something simple. Woops, mispelled that. Woops, that’s a member of this child of such and such object. How productive would you be if every one of those took 5-10 minutes of testing and careful attention to see that it was even a problem? Would you want to ship code that you’d never even tried to compile?