You are a nice programmer somewhere far away . . . You’ve set up an agency : CodeFun Agency. A bright morning when the sun was 43.5 degrees to the vertical, the door knocked, in three bursts … The doorbell has long been thrown away. You hurried to the door. A weird, middle-sized man was looking at you.

The customer enters

Customer : Greetings

You: *Greetings*

Customer : I am Mr. Lug Ha, from the Great country of Xamin

You : Ah nice ! Please take a seat 

‘creak tak dock more undefined sounds’

Ah let us discuss matters

Mr. Lug Ha : I want you to create a language for me 

You {while recording and wondering if the name was well spelt} : what ?

Mr Lug Ha : I want to create a language which allows me to make messages appear to the screen

You : That’s all? i mean . . . wh what, create a language? you are joking, right . . .

Mr Lug Ha : euhh no

You : Oh well i can’t do . .

Mr Lug Ha : well, see you soon

You : waaait

*clack*

Wonder

*Assistant codebot comes in*

codebot : Master, why are you looking like that? let us start by the beginning . . .

Let us see what the language needs to l0ok like . . .

you : ah yes

Let us see . . . he wants print  . . .

fake lang syntax – Mr. Lug ha – Assignment

print he is here; 

print the sun is shining;

should be ok

codebot : yes looks good

you : now how do we make that work ?

codebot : let us use the nice language called python . . . simpler.

you : let us see

langstring = 'print i am here; print he is here;'

now .  . . i need to print i am here and he is here

these are two statements, how do i separate the two . . .  ah exactly . . . using the ; as separator

langstring = 'print i am here; print he is here;'

statementslist = langstring.split(';')

_____________________ output : 

[‘print i am here’, ‘ print he is here’, ”]

now i can print them . . .

langstring = 'print i am here; print he is here;'

statementslist = langstring.split(';')

for i in range (len(statementslist)):

        print(statementslist[i])

_____________________ output : 

print i am here

print he is here

Great !

codebot : euhh the print keyword appears master

you : oh we’ll just erase it

langstring = 'print i am here; print he is here;'

statementslist = langstring.split(';')

for i in range (len(statementslist)):

        print(statementslist[i].replace('print',''))

_____________________ output : 

i am here

he is here

codebot : euhh in essence, you should instruct the program to print because the print word is here and it should print what is after the print keyword  . . .

you : ah so,

  1. print if print word exists
  2. print what is after the print keyword

codebot : also, note that :

  1. The word print appears at the beginning of each statement . . .

you : ah yes . . . so if statementslist[i] ‘s 1st to 5th character is print, i print what is after it . . .

langstring = 'print i am here; print he is here;'

statementslist = langstring.split(';')

for i in range (len(statementslist)):

        if statementslist[i][0:5] == 'print':

codebot : yes and you will print from the sixth to the end of the statement, before you ask, you get it automatically by

len(statementslist[i])

you : hum ok let us try . . .

langstring = 'print i am here; print he is here;'

statementslist = langstring.split(';')

for i in range (len(statementslist)):

    if statementslist[i][0:5] == 'print':

        print( statementslist[i][6:len(statementslist[i])])

_____________________ output : 

i am here

What ?? only one output . . .

codebot : take the space from between the ; and the print . . .

‘print i am here; print he is here;’

to

‘print i am here;print he is here;’

you :  ok now it is all set . . .

langstring = 'print i am here;print he is here;'

statementslist = langstring.split(';')

for i in range (len(statementslist)):

    if statementslist[i][0:5] == 'print':

        print( statementslist[i][6:len(statementslist[i])])

_____________________ output : 

i am here

he is here

codebot : i don’t feel at ease, this can be more lively  .  .  .

Real Feel

codebot : The user will feel better writing their code in a text file . . .

you : excellent let us make the user write in a printlang.txt file . . .. i’ll create one in the project directory then we’ll read from that !

reader =open('printlang.txt','r')

langstring = reader.read()

statementslist = langstring.split(';')

for i in range (len(statementslist)):

    if statementslist[i][0:5] == 'print':

        print( statementslist[i][6:len(statementslist[i])])

in textfile:

print i am here;

print he is here;

codebot : you’ll get crazy outputs, newlines \n in python is counted, replace it with nothing

.replace(‘\n’,”)

you :

reader =open('printlang.txt','r')

langstring = reader.read().replace('\n','')

statementslist = langstring.split(';')

for i in range (len(statementslist)):

    if statementslist[i][0:5] == 'print':

        print( statementslist[i][6:len(statementslist[i])])

yes !

print it works;

print print;

print hhh;

maa aa it works !!!!

_____________________ output : 

it works

print

hhh

codebot : youhooo now we can customise a bit

you : like ?

Customisations

codebot : let us give the language a name ! LugHa seems nice

you : hum we can customise the .txt extention, we’ll put like .lug

codebot : yes

you : yes we rename the text file from .txt to .lug and modify the file name to be opened . . .

reader =open('printlang.lug','r')

langstring = reader.read().replace('\n','')

statementslist = langstring.split(';')

for i in range (len(statementslist)):

    if statementslist[i][0:5] == 'print':

        print( statementslist[i][6:len(statementslist[i])])

we’ll now wait for the customer . . .

Mr. lug : so, print will print text to the printer, right ?

… examining

Mr Lug Ha : Ah nice, very nice, but does print actually prints the text to the printer? nice nice .  . .

you : no euhh . . it shows text to the screen

Mr Lug Ha : are you sure? print, printer . . . very confusing, show me something else . . .

you : ok ah how about show?

Mr Lug Ha : Great !

you : we also put if … 0:4] == and 5: …

reader =open('printlang.lug','r')

langstring = reader.read().replace('\n','')

statementslist = langstring.split(';')

for i in range (len(statementslist)):

    if statementslist[i][0:4] == 'show':

        print( statementslist[i][5:len(statementslist[i])])

and tests in the file printlang.lug

show awesome;

show good . . .;

Mr Lug Ha : great, ill take it, tell me the price

….

You fall down on the chair while the nagging accent of Mr. Lug trails in your head . . .

codebot : master you’ve created your first interpreter . . . the LugHa interpreter

——————–

CodeFun Agency

——————–

[+] Making interpreters

queer session

codebot : take a quick bath; hands face arms head feet

*splash splash*

codebot : relax deeply

you : fuuuuuuuuuum huuuuuum

codebot : repeat

you : … … …

codebot : again

you : … … . . .

codebot : now read that compiler theory article about which you understand nothing again . . .

you : lexemes are . . . .

DAYS LATER

*Dring Dreeng*

Mr. Lug : Hum finally, there is something wrong

you : ah, what it is?

Dear reader o] wait for next post [o

 

 

In need of managing bookmarks online? Try the awesome Bookmark Ninja
Advertisements