Frankly, if you had the experience needed to understand the answer, then you wouldn't need to ask that question in the first place.
But to try to give you a picture: this is what SquidDev is talking about when he refers to
tokenisation. In a nutshell, you need to break that line down into
parts so that you can identify that it
starts with a request to display something, and that it then
moves on to establish what that "something" is.
Consider the items in the line print("Hello, World!") - first it provides a name ("print"). Then it throws in some brackets, an indication that the preceding name is that of a variable containing a function pointer, and that function is to be called. Within those brackets, quotes then appear, which are used to define a single string of text, "Hello, World!", which is the argument to be passed to the called function.
You need to code your own way of breaking the line down into those elements. The way I would
personally do this is to switch from inspecting your file
line by line to instead going
character by character - start by adding characters to a string until you have a complete word (terminated by a space, or a bracket, or an equals sign, or any of the other characters that signify a break), and then use the following symbol to determine what to do with it. Following the above example of printing something, the first word is ended with a bracket, indicating you should be preparing to call a function - so within your interpreter, define a function for the purpose of interpreting function calls. Pass that the name of the function you read in, along with the remainder of the text, and have it keep parsing character by character until it's gathered all the information contained
within the brackets.
You'll soon want to define additional functions for the purpose of translating other data types. A string-identifier would be next, in order to recognise "Hello, World!". Soon you'll want to be able to recognise numbers, and then perhaps booleans, too.
The basic structure of your script would start to look a bit like this very-rough-and-loose bit of psuedo-code:
Spoiler
local data = <everythingThat'sInYourInputFile>
local currentWord = ""
for i = 1, #data do
currentChar = data:sub(i, i)
if currentChar is a normal alphabetical character then
add it to the end of currentWord
currentWord = currentWord .. currentChar
elseif currentChar is a ( symbol then
the word we assembled represents a variable pointing to a function to be called.
Start gathering arguments from that word...
arguments = gatherFunctionArgs(remainingData)
output code to call function with arguments - this might look something like _G[currentWord](unpack(arguments))
elseif currentChar is an = symbol then
the word we assembled represents a variable we want to assign something to.
Start evaluating the statement defining what is to be assigned...
evaluateStatement(remainingData)
output code to assign values to variable
elseif currentChar is a space then
spaces would be sort-of ignored - they signify that a word has ended,
but they don't tell us what happens next. More characters must be read in.
end
end
function gatherFunctionArgs(data)
--# Run a loop much like the last, gathering a list of arguments!
local arguments = {} --# A table to start putting arguments in.
local currentWord = ""
for i = 1, #data do
currentChar = data:sub(i, i)
if currentChar is a normal alphabetical character then
probably going to be a variable name, might be a boolean or something - add it to the end of currentWord
currentWord = currentWord .. currentChar
elseif currentChar is a " symbol then
must be a string of text
use anther function to go get that:
arguments[#arguments + 1] = gatherString(remainingData)
elseif currentChar is a number then
more numeric symbols might follow
arguments[#arguments + 1] = gatherNumber(remainingData)
elseif currentChar is a ( then
oh hey there's a function call in our function arguments!
so now we start recursing:
newArguments = gatherFunctionArgs(remainingData)
arguments[#arguments + 1] = code to call this new function with its own list of arguments
end
end
return arguments
end
function gatherString(data)
--# Run a loop much like the others, gathering a string!
local currentWord = ""
for i = 1, #data do
currentChar = data:sub(i, i)
if currentChar is " then
return currentWord
else
currentWord = currentWord + currentChar
end
end
return arguments
end
function gatherNumber(data)
--# and so on and so forth
.
.
.
As you start to add support for more actions, data types, and so on, this'll start to get a
lot longer. Take another look at Howl - this is the sort of thing that's doing.
So, um… yeah.
What I
suggest is that you switch projects and start work on a text adventure game - these sorts of "simple interpreters" would help you step up to the more complex source code interpreters.