ILP (Iterprete para un Lenguaje Pila), thus ISL (Interpreter for a Stack Language) * Build * The source is commented in Spanish, but you can get interpreter messages in english with: $ make en If you want to install it, just copy usr/ilp to /usr/local/bin. If your compiler doesn't support the 'inline' directive, please comment the HAS_INLINE define in the config.h file. * Features * - Types: integers digits or - and digits (negative values) variables identifiers form a to z addresses program address (see :) - Operators: + a b + -> a + b - a b - -> a - b / a b / -> a / b * a b * -> a * b = a b = -> a = b E a b E -> a == b < a b < -> a < b > a b > -> a > b ~ a ~ -> NOT a - Input/Output: $ to screen the value in stack $$ to screen the value in stack plus end of line " to screen literals until " control characters: \n end of line \t tab \" double quotes \\ left slash ? push a value from keyboard - Loop: : push address ^ a b ^ -> jumps to a adress if b is not zero - Conditional: ! a ! bloq -> pops a and execs bloq if a is not zero - Misc: # comment until end of line ; points end of block (see conditional) . a . -> ends the program returning the system a by default the programs return 0 * Known problems * - The line count means executed lines, so the loops make the line count confusing - Push/operator notation is weird :-) * Examples * Some comparisons with C: /* in C */ for(i=0;i<10;i++) printf("iteration %i\n",i); # in LP i 0 = : "iteration " i $$ i i 1 + = # this is i=i+1 i 10 < ^ /* in C */ if(a==b) printf("a equal to b"); else { if(a>b) printf("a bigger than b"); else printf("a smaller than b"); } # in LP (there's nothing like 'else') a b E ! "a equal to b" ; a b > ! "a bigger than b" ; a b < ! "a smaller than b" ; A program: "Multiplication table\nEnter a number: " a ? = j 1 = i 10 = : " " a $ "x" j $ "=" a j * $$ j j 1 + = i i 1 - = i ^ # A simple example Another program: : "The bomb game\n\nThere are 19 bombs and we must drop from 1 to 5 each" " one each turn.\nThe player with the last bomb in his/her hand... boom!" "\n\n" a 19 = : "There are " a $ " bombs, " : "how many do you wanna drop? " b ? = b 5 > b 1 < + ! "you cannot drop more than 5 bombs neither less than " "1\n" ; b 5 > b 1 < + ^ a a b - = c 6 b - = "there are " a $ " bombs, I " "drop " c $$ a a c - = a 1 > ^ "there's 1 bomb and you have it in your " "hand!\nYou're over... Play again (0 to end)? " b ? = b ^ # The bomb game * Author * Juan J. Martinez ***