1

I'm creating a programming language with an interpreter that is written in Python. The syntax for my language looks like this:

disp "The quick brown fox jumps over the lazy dog"  # 'disp' displays text
disp $myStr  # anything starting with $ is a string variable

strop add $myStr "... The End" # String operations. Concatenate $myStr and some text.

However, I am having trouble parsing it. If I have the string "Hello, SO!" $myStr how do I separate it so that "Hello, SO!" and $myStr are separate, and make it work with two literals, two variables or one of each?

Thanks in advance.

  • You need a parser generator tool like ANTLR. Writing a language parser in Python by hand is not an easy job. – DYZ Aug 12 '17 at 06:26
  • @DYZ I'm interested in writing it myself for the learning experience if anything else. Am I vaguely in the right ballpark in terms of how feasible this is? –  Aug 12 '17 at 06:28
  • Even with ANTLR, you will have to write it yourself, but in the ANTLR language, not in Python. Depending on the grammar of your language, you may have some luck with regular expressions `re`. BTW, the posted example seems to have broken syntax: where is the closing `"`? – DYZ Aug 12 '17 at 06:30
  • That's a mistake, thanks for pointing that out! @DYZ –  Aug 12 '17 at 06:34

0 Answers0