This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
nutcase84's profile picture

How to make a programming language?

Started by nutcase84, 15 May 2013 - 11:05 AM
nutcase84 #1
Posted 15 May 2013 - 01:05 PM
How do I make something that reads text off a file, then converts it into something I can process? I could make encryption for my OS as well…
PixelToast #2
Posted 15 May 2013 - 01:26 PM
thats called obufuscation
if you want encryption / hashing then go to the programs section
if you want to hide code use string.dump
nutcase84 #3
Posted 15 May 2013 - 01:27 PM
thats called obufuscation
if you want encryption / hashing then go to the programs section
if you want to hide code use string.dump

A little more info please?
Mads #4
Posted 15 May 2013 - 01:31 PM
Google, perhaps? Or Stackoverflow(RTFM)
LBPHacker #5
Posted 15 May 2013 - 01:33 PM
[imo] Hiding your code behing some dumb wall of encryption is just mean. [/imo]
Yup, string.dump, but storing a function dump is not that easy, since it contains characters with the ASCII value between the range of 128 and 255 as well. FS API doesn't like those. Although you can read them in binary mode. Hmm… Have no idea how much time would it take to write the entire dump of a function into a file in binary mode…

Anyways, what do you want?
  • Making the code unreadable by modifying the identifiers so others can't guess what are they meant to do? (Obfuscation)
  • Making a piece crap from a code that you can recover only with a password? (Encryption)
  • Making it unreadable but loadable? (Bytecode)
nutcase84 #6
Posted 15 May 2013 - 01:40 PM
[imo] Hiding your code behing some dumb wall of encryption is just mean. [/imo]
Yup, string.dump, but storing a function dump is not that easy, since it contains characters with the ASCII value between the range of 128 and 255 as well. FS API doesn't like those. Although you can read them in binary mode. Hmm… Have no idea how much time would it take to write the entire dump of a function into a file in binary mode…

Anyways, what do you want?
  • Making the code unreadable by modifying the identifiers so others can't guess what are they meant to do? (Obfuscation)
  • Making a piece crap from a code that you can recover only with a password? (Encryption)
  • Making it unreadable but loadable? (Bytecode)

I mostly just want to make a Language. But if I had to pick one, Bytecode.
LBPHacker #7
Posted 15 May 2013 - 01:43 PM
I could make encryption for my OS as well…
Yeah, we were answering the wrong part.

So… A new programming language? Heh… That's entirely upon you, since the instant you start writing your own language, it isn't exactly Lua (or any known language for that matter), so we can't help.
nutcase84 #8
Posted 15 May 2013 - 01:47 PM
I could make encryption for my OS as well…
Yeah, we were answering the wrong part.

So… A new programming language? Heh… That's entirely upon you, since the instant you start writing your own language, it isn't exactly Lua (or any known language for that matter), so we can't help.

I just want to know how to do it. I'm not saying that you have to make one for me.
PixelToast #9
Posted 15 May 2013 - 01:57 PM
making a language requires planning, if you dont know how its going to work you will have a verry hard time making it useable
nutcase84 #10
Posted 15 May 2013 - 02:00 PM
It's going to be like basic.
LBPHacker #11
Posted 15 May 2013 - 02:04 PM
It's going to be like basic.
FUUUUUUUUUUUUUUUUUUUUUUUUU…

Liberty or Visual? Or 80's?

Anyways, string.find and regex for the win.
Sammich Lord #12
Posted 15 May 2013 - 02:06 PM
I was going to go tell you to learn C but since you mentioned basic I will just leave this here for you to play with.

Smiley43210 #13
Posted 15 May 2013 - 02:07 PM
So, like a language interpreter?
nutcase84 #14
Posted 15 May 2013 - 02:15 PM
So, like a language interpreter?

Yes.

It's going to be like basic.
FUUUUUUUUUUUUUUUUUUUUUUUUU…

Liberty or Visual? Or 80's?

Anyways, string.find and regex for the win.

I'm going to make it like applebasic on my apple IIGS from 1986. (It's a rare model!(rom ver. 00))
nutcase84 #15
Posted 16 May 2013 - 07:20 AM
So… no explanation?
Shnupbups #16
Posted 16 May 2013 - 07:27 AM
So you want to create a 'programming language' (actually an interpreter) within CC? Could you be more specific as to what you mean?

Anyways, to make an interpreter simply make a file that can accept arguments. The arguments will be a file that is coded in your language. make the program fs.open it, and f.readLine() it. Get that line, and translate it into CCLua, output it. then repeat the line-reading until fs.readLine returns nil.
PixelToast #17
Posted 16 May 2013 - 10:09 AM
compiling to a simple bytecode language (or even better make it compile into lua) will increase runtime efficiency depending on the type of language your using
LNETeam #18
Posted 16 May 2013 - 12:57 PM
If you are looking for encryption, consider StrUtils. It offers SHA1 encryption without addons or mods. Just search it in Google for it
theoriginalbit #19
Posted 16 May 2013 - 01:06 PM
If you are looking for encryption, consider StrUtils. It offers SHA1 encryption without addons or mods. Just search it in Google for it
SHA isn't an encryption standard, it is a hashing algorithm.
A hash is designed to be ONE way (i.e. cannot convert from the output to the original data), where as an encryption is designed to be TWO way (i.e. can convert between encrypted data, and the original data at will as long as you know the key).
Also in terms of hashing, SHA1 is very insecure as there are a lot of collisions.
jesusthekiller #20
Posted 16 May 2013 - 01:27 PM
If you want to make something like translator from yourLanguage to LUA, it would not be too hard to do.

http://lmgtfy.com/?q...+String+library




If you want to make a real full-blown programming language, give up. No one aged 11 has ever made it :P/>
nutcase84 #21
Posted 16 May 2013 - 05:12 PM
What am I doing wrong with this?
Spoiler

print("")
write("File to open: ")
dir = read()
file = fs.open(dir, "r")
while line ~= nil do
  line = file.readLine()
  linecmd = string.lower(line)
  pn1, pn2 = string.find(linecmd, "print")
  if pn1 ~= nil then
    fsn1, fsn2 = string.find(line, ";")
    if  n1 ~= nil then
	  data1 = string.sub(line, n2 + 1)
	  print(data1)
    else
	  error("No ;")
    end
  else
    error("CMD Nil")
  end
end
file.close()
Espen #22
Posted 16 May 2013 - 05:21 PM
while line ~= nil do

"line" is not defined yet, ergo it will be nil and the while loop will be skipped entirely.
nutcase84 #23
Posted 16 May 2013 - 07:18 PM
while line ~= nil do

"line" is not defined yet, ergo it will be nil and the while loop will be skipped entirely.

DERP! Thanks.
nutcase84 #24
Posted 16 May 2013 - 07:49 PM
So, I am using file.readLine(). How do you detect when the files done?
Sammich Lord #25
Posted 16 May 2013 - 07:51 PM
So, I am using file.readLine(). How do you detect when the files done?
When file.readLine is nil.
nutcase84 #26
Posted 16 May 2013 - 07:59 PM
So, I am using file.readLine(). How do you detect when the files done?
When file.readLine is nil.

Nope. Doesn't work.
Sammich Lord #27
Posted 16 May 2013 - 08:01 PM
So, I am using file.readLine(). How do you detect when the files done?
When file.readLine is nil.

Nope. Doesn't work.
How does it not work?

local f = fs.open('meh', 'r')
local line = f.readLine()
while line do
  print(line)
  line = f.readLine()
end
f.close()
That works perfectly.
nutcase84 #28
Posted 16 May 2013 - 08:20 PM
I give up. This is so frustrating.
jesusthekiller #29
Posted 18 May 2013 - 08:22 AM
I give up. This is so frustrating.

God. Please kill me.