I was assigned to write a compiler for the base programming language . In the base code, codes are separated by new lines or by a character :. For example, compliance with the following codes.
Model No. 1
10 PRINT "Hello World 1" : PRINT "Hello World 2"
Model No. 2
10 PRINT "Hello World 1"
20 PRINT "Hello World 2"
You can test those here .
The first thing I need to do before parsing the codes in my compiler is to split the codes.
I already broke the codes in the lines, but I was stuck in finding a regex for separation. The following code example:
This next code example should be split by 2 PRINT.
10 PRINT "Hello World 1" : PRINT "Hello World 2"
:
- .
10 PRINT "Hello World 1" ": PRINT Hello World 2"
, DO, , : " ?
- ?
.:)