The missing features are:
- Shakespeare is supposed to restrict variable names to names of real Shakespeare characters...I have yet to implement this restriction
- Because of how I am currently treating any word delimited by spaces as a separate token, I have yet to implement support for multi-word names, nouns, and operators - this shouldn't be terribly hard to fix, but will be at least a little annoying...I didn't notice until the very end that multi-word names, nouns, and operators existed, but the example Primes.spl file from the Shakespeare website notably uses "The Ghost" as a variable and the "square root operator.
- I have not implemented Stacks...notably these are only needed for turing completeness if I implement the naming restriction, so... (but anyway, these would be useful)
- Any feature not used in the example hello.spl I have is untested, but "should" work (this includes gotos and input).
I won't publish my compiler until the above issues are taken care of, but, other than those issues, my compiler (written in python) correctly compiles Shakespeare code to C.
Below is the C output of my compiler for the Shakespeare program below it...it comes out a little bit less nice than the standard C hello world (nice indentation is pretty low on the priority list):
// hello.spl #include < stdio .h > #include "include/mathhelpers.h" int condition = 0; int Romeo = 2; int Juliet = 2; int Ophelia = 1; int Hamlet = 1; void act_1_scene1() { Romeo = -64 ; Romeo = (8 - Romeo) ; fprintf(stdout, "%c", (char)Romeo); Romeo = (-128 + 32) ; Romeo = ((4 + 1) - Romeo) ; fprintf(stdout, "%c", (char)Romeo); Romeo = (Romeo + (8 - 1)) ; fprintf(stdout, "%c", (char)Romeo); fprintf(stdout, "%c", (char)Romeo); } void act_1_scene2() { Juliet = ((Romeo + 1) + 2) ; fprintf(stdout, "%c", (char)Juliet); } void act_1_scene3() { Ophelia = (4 * 8) ; fprintf(stdout, "%c", (char)Ophelia); Ophelia = (8 * (1 + 2)) ; Ophelia = (Juliet - Ophelia) ; fprintf(stdout, "%c", (char)Ophelia); } void act1() { act_1_scene1(); act_1_scene2(); act_1_scene3(); } void act_2_scene1() { fprintf(stdout, "%c", (char)Juliet); Juliet = (Juliet + (4 - 1)) ; fprintf(stdout, "%c", (char)Juliet); fprintf(stdout, "%c", (char)Romeo); Romeo = Hamlet ; Romeo = (square((2 - -4)) - cube(-4)) ; fprintf(stdout, "%c", (char)Romeo); } void act_2_scene2() { Ophelia = (Romeo / (4 + -1)) ; fprintf(stdout, "%c", (char)Ophelia); Juliet = (Romeo / twice((1 - -4))) ; fprintf(stdout, "%c", (char)Juliet); } void act2() { act_2_scene1(); act_2_scene2(); } int main() { act1(); act2(); }
The Infamous Hello World Program. Romeo, a young man with a remarkable patience. Juliet, a likewise young woman of remarkable grace. Ophelia, a remarkable woman much in dispute with Hamlet. Hamlet, the flatterer of Andersen Insulting A/S. Act I: Hamlet's insults and flattery. Scene I: The insulting of Romeo. [Enter Hamlet and Romeo] Hamlet: You lying stupid fatherless big smelly half-witted coward! You are as stupid as the difference between a handsome rich brave hero and thyself! Speak your mind! You are as brave as the sum of your fat little stuffed misused dusty old rotten codpiece and a beautiful fair warm peaceful sunny day. You are as healthy as the difference between the sum of the sweetest reddest rose and my father and yourself! Speak your mind! You are as cowardly as the sum of yourself and the difference between a big mighty proud kingdom and a horse. Speak your mind. Speak your mind! [Exit Romeo] Scene II: The praising of Juliet. [Enter Juliet] Hamlet: Thou art as sweet as the sum of the sum of Romeo and his horse and his black cat! Speak thy mind! [Exit Juliet] Scene III: The praising of Ophelia. [Enter Ophelia] Hamlet: Thou art as lovely as the product of a large rural town and my amazing bottomless embroidered purse. Speak thy mind! Thou art as loving as the product of the bluest clearest sweetest sky and the sum of a squirrel and a white horse. Thou art as beautiful as the difference between Juliet and thyself. Speak thy mind! [Exeunt Ophelia and Hamlet] Act II: Behind Hamlet's back. Scene I: Romeo and Juliet's conversation. [Enter Romeo and Juliet] Romeo: Speak your mind. You are as worried as the sum of yourself and the difference between my small smooth hamster and my nose. Speak your mind! Juliet: Speak YOUR mind! You are as bad as Hamlet! You are as small as the difference between the square of the difference between my little pony and your big hairy hound and the cube of your sorry little codpiece. Speak your mind! [Exit Romeo] Scene II: Juliet and Ophelia's conversation. [Enter Ophelia] Juliet: Thou art as good as the quotient between Romeo and the sum of a small furry animal and a leech. Speak your mind! Ophelia: Thou art as disgusting as the quotient between Romeo and twice the difference between a mistletoe and an oozing infected blister! Speak your mind! [Exeunt]
No comments:
Post a Comment