Hello, To Improve my C skills, I've decided to create my mini programming language. It will read a string from a file and react as the context of the string. Here
is my question
- How to read a string in specific characters and give an error if they are missing. e.g:
1 2 3 4 5 6 7 8 9
if(readed_string == "print")
{
// here how to check if there are brackets or not.
if(have_brakets)
{
// how to read text within "" ?
}
}
Your topic asks how to use the C equivalent of file operations (which is related to fopen), but your code seems to trying to parse code...
Also are you calling quotes brackets? brackets are {}.
I think that a very simplistic scripting engine should not try to have complex operators inside them because it will cause you a lot of headache. You should keep it simple by just making the first word of every line designate what the operation is, and separate the arguments with spaces, and ends with a newline.
At a bare minimum, you could do a really simple routine that just plain and simply checks for a "(", then finds the end ")". This is very trivial.
Other than that I would highly recommend boost spirit if you want to do any complex language parsing.
But I know you are probably thinking this isn't C, but then why are you asking on a c++ board? I can see how people can have no choice but to use C for backwards compatibility, but I don't see how this is a "must use C" example.
You also need to specify in full what exactly do you want your mimi programming language to be capable of doing, because if you are really serious in creating a real programming language, you should just grab a book.