How to separate script source into parts

hello so i will explain with this example:

local Script = "print(\"Hello world!\")"
local ScriptContents = {
	"\"Hello world!\"",

so basically there will be a table of all the keywords i want to separate like print and also the words in quotations i want to be able to get like this: "Hello world!" i just need an idea of how i could separate a string into parts

1 Like

That’s called lexing, and it’s the first step in compiling or interpreting a program. Every bsc. comp. sci. course covers it I believe, and a decent starting point is to learn about grammars. Here’s some random slides I found on google: Try just skim reading it to get an idea of the topics. There’s obviously a lot of lingo but don’t mind that, it’s good to get an overview before diving in. If you’re interested in reading further then try following an actual course, or find some tutorials online on recursive descent parsers or other types of parsers, it should get you hands on a bit quicker. There are online implementations of Lua parsers as well, if you want to see some code examples.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.