As a long time lurker, first time poster, I have decided to make a "programming language" today (It is really just a little passion project).
It has very simple syntax and is made in Fortran.
P=Print the letter that is associated with the current charnum value and end the program.
A=Add to the current charnum value.
M=Subtract (or minus) from the current charnum value.
S=Prints the syntax that can be used.




Code:
program pams_interpreter_v1
implicit none
character(len=1) :: pams
integer :: charnum
charnum=0
do
write(*,'(a)')
read (*,'(a)') pams
if (pams=='p') then
print *, charnum
exit
endif
if (pams=='a') then
charnum=charnum+1
endif
if (pams=='m') then
charnum=charnum-1
endif
if (pams=='s') then
print *,'This is an intperpreter for PAMS, a simple programming language'
print *,'created by your very own, Large_fard.'
print *,'P is to print the name,'
print *,'A is to add to the stack,'
print *,'M is to subtract (or minus) from the stack and '
print *,'S is to print this.'
exit
endif
enddo
if (charnum==1) then
print *,'a'
endif
if (charnum==2) then
print *,'b'
endif
if (charnum==3) then
print *,'c'
endif
if (charnum==4) then
print *,'d'
endif
if (charnum==5) then
print *,'e'
endif
if (charnum==6) then
print *,'f'
endif
if (charnum==7) then
print *,'g'
endif
if (charnum==8) then
print *,'h'
endif
if (charnum==9) then
print *,'i'
endif
if (charnum==10) then
print *,'j'
endif
if (charnum==11) then
print *,'k'
endif
if (charnum==12) then
print *,'l'
endif
if (charnum==13) then
print *,'m'
endif
if (charnum==14) then
print *,'n'
endif
if (charnum==15) then
print *,'o'
endif
if (charnum==16) then
print *,'p'
endif
if (charnum==17) then
print *,'q'
endif
if (charnum==18) then
print *,'r'
endif
if (charnum==19) then
print *,'s'
endif
if (charnum==20) then
print *,'t'
endif
if (charnum==21) then
print *,'u'
endif
if (charnum==22) then
print *,'v'
endif
if (charnum==23) then
print *,'w'
endif
if (charnum==24) then
print *,'x'
endif
if (charnum==25) then
print *,'y'
endif
if (charnum==26) then
print *,'z'
endif
end program pams_interpreter_v1


I am open to all suggestions!!
Hey, you finally got to creating an account! I still do not get why you wrote this in FORTRAN, of all languages. Also, there has to be a more efficient way to display characters in FORTRAN, besides individually mapping them ¯\_(ツ)_/¯
I have successfully wrote a C interpreter for PAMS!

Code:
#include <stdio.h>
#include <string.h>

int main() {
    char prog[1000];
    char sub;
    int cursor = 0;
    int charmem = 0;
   
    char chars[] = "abcdefghijklmnopqrstuvwxyz";

    scanf("%s", prog);
    while (cursor < strlen(prog)) {
        sub = prog[cursor];
        if (sub == 'A') {charmem++;}
        if (sub == 'M') {charmem--;}
        if (sub == 'P') {printf("%c",chars[charmem]);}
        cursor++;
    }
}

and a C++ one, which is my first c++ program 🙂

Code:

#include <iostream>
#include <string>
using namespace std;

int main() {
    string prog;
    string sub;
    int cursor = 0;
    int charmem = 0;
   
    string chars = "abcdefghijklmnopqrstuvwxyz";

    cout << "Program:";
    cin >> prog;
    while (cursor < prog.length()) {
        char sub = prog[cursor];
        if (sub == 'A') {charmem++;}
        if (sub == 'M') {charmem--;}
        if (sub == 'P') {cout << chars[charmem];}
        cursor++;
    }
}

and a python one

Code:
charnum = 0
chars = "abcdefghijklmnopqrstuvwxyz"
prog = input("Program:")
cursor = 0
while cursor < len(prog):
    sub = prog[cursor]
    if sub == "A":
        charnum += 1
    if sub == "M":
        charnum -= 1
    if sub == "P":
        print(chars[cursor])
    cursor += 1
I agree that there has to be an easier way to display characters, but then again, PAMS is still in it's early stages.
There is a way easier way to display characters:
You add the base ASCII value of a (using iachar), then add the charnum-1 to it, and get the ASCII character for this value using achar (a Google search was very helpful, since I don't know FORTRAN)

Code:

if (charnum >= 1 .and. charnum <= 26) then
    print *, achar(iachar('a') + charnum - 1)
endif
Here's another port (a lua one), because why not!

Code:

local charnum = 0
local chars = "abcdefghijklmnopqrstuvwxyz"
io.write("Program:")
local prog = io.read()
local cursor = 1

while cursor <= #prog do
    local sub = string.sub(prog, cursor, cursor)
    if sub == "A" then
        charnum = charnum + 1
    elseif sub == "M" then
        charnum = charnum - 1
    elseif sub == "P" then
        print(string.sub(chars, cursor, cursor))
    end
    cursor = cursor + 1
end
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement