Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ! ELIZA: a conversation simulation
- ! from Creative Computing magazine
- ! adapted FOR the IBM PC by patricia danielson AND Paul Hashfield
- ! readapted FOR Inform by Ricardo Dague (February 1999)
- !
- ! I was naked when I programmed this.
- constant grammar__version = 2;
- [ Main; Main_(); ];
- array conjugate -->
- 'are' 'am'
- 'were' 'was'
- 'you' 'i//'
- 'your' 'my'
- 'i^ve' 'you^ve'
- 'i^m' 'you^re'
- 'me' 'you'
- $ffff;
- global parrot_x = ";-)";
- [ parrot STR punc pl x w i;
- pl = ParseLen();
- IF(parrot_x == pl)
- "You will have to elaborate more for me to help you.";
- PRINT (STRING)STR;
- x = parrot_x-1;
- FOR(: parrot_x < pl: parrot_x++)
- {
- w = WordNth(parrot_x);
- FOR(i = 0: conjugate-->i ~= w OR -1: i++)
- ;
- IF(conjugate-->i == w)
- {
- PrSubStr(WordEnd(x),WordStart(parrot_x));
- IF(i&1) i--; ELSE i++;
- switch(conjugate-->i)
- {
- 'i//': print "I";
- 'i^ve': print "I've";
- 'i^m': print "I'm";
- default: PRINT (address)conjugate-->i;
- }
- x = parrot_x;
- }
- }
- x = WordEnd(x);
- i = BufferEnd();
- IF(i > x && (i-1)->0 == '.' or '?' or 33) ! 33 == '!'
- i--;
- PrSubStr(x,i);
- IF(punc) PRINT "."; ELSE PRINT "?";
- ];
- array buffer->121;
- array bufsave->121;
- array parse->65;
- [ PrSubStr s e;
- WHILE(s < e) PRINT (char)s++->0;
- ];
- [ BufferEnd; RETURN buffer + 2 + buffer->1; ];
- [ ParseLen; RETURN parse->1; ];
- [ WordStart x; RETURN buffer + parse->(5+4*x); ];
- [ WordEnd x; RETURN WordStart(x) + parse->(4+4*x); ];
- [ WordNth x;
- IF(x < ParseLen())
- RETURN parse-->(1+2*x);
- RETURN -1;
- ];
- global dict_nlines;
- global dict_addr;
- global dict_nextaddr;
- [ DictVerb x;
- IF(x && (x->#dict_par1 & 1))
- {
- dict_nextaddr = (0-->7)-->(255 - x->#dict_par2);
- dict_nlines = dict_nextaddr++->0;
- rtrue;
- }
- rfalse;
- ];
- [ DictLine x;
- IF(dict_nlines == 0) RETURN -1;
- dict_nlines--;
- dict_addr = dict_nextaddr;
- x = 0;
- WHILE(DictToken(x) & 15 ~= 15)
- x++;
- dict_nextaddr = dict_addr + (3+3*x);
- RETURN x;
- ];
- [ DictAction;
- RETURN dict_addr-->0;
- ];
- [ DictToken x;
- RETURN (dict_addr + (2+3*x))->0;
- ];
- [ DictValue x;
- RETURN (dict_addr + (3+3*x))-->0;
- ];
- [ Main_ pl ll i j k action;
- PRINT "Would you like a transcript? (Y/N)^";
- @read_char 1 i;
- WHILE(i ~= 'y' or 'Y' or 'n' or 'N')
- {
- PRINT "Please enter Y or N.^";
- @read_char 1 i;
- }
- IF(i == 'y' or 'Y')
- @output_stream 2;
- style BOLD; PRINT "^ELIZA"; style roman;
- PRINT " -- an interactive parroting^^From Creative Computing \
- magazine; ^adapted for the IBM PC by Patricia Danielson and \
- Paul Hashfield; ^readapted for Inform by Ricardo Dague. \
- ^[type ~shut up~ to end]";
- bufsave->0 = 1;
- PRINT "^^^Hi! I'm Eliza. What's your problem?^";
- FOR(::)
- {
- DO {
- PRINT "^>";
- buffer->0 = 120; parse->0 = 15;
- read buffer parse;
- FOR(i = 0: i < 121: i++)
- IF(buffer->i == '?')
- buffer->i = '.';
- @tokenise buffer parse;
- pl = ParseLen();
- } UNTIL(pl);
- FOR(i = 0: i < 121: i++)
- IF(bufsave->i ~= buffer->i)
- jump INEQUAL;
- PRINT "Please don't repeat yourself!^";
- CONTINUE;
- .INEQUAL;
- FOR(i = 0: i < 121: i++)
- bufsave->i = buffer->i;
- IF(WordNth(0) == 'shut')
- {
- PRINT "Okay if you feel that way I'll shut up.^";
- break;
- }
- parrot_x = 0;
- action = ##Default;
- FOR(i = 0: i < pl: i++)
- IF(DictVerb(WordNth(i)))
- WHILE((ll = DictLine()) >= 0)
- {
- j = i+1;
- FOR(k = 0: k < ll && DictValue(k) == WordNth(j):
- k++)
- {
- j++;
- }
- IF(k == ll)
- {
- parrot_x = j;
- action = DictAction();
- jump FOUND;
- }
- }
- .FOUND;
- indirect(#actions_table-->action);
- }
- ];
- global canyou_x = 1;
- [ CanYouSub;
- switch(canyou_x)
- {
- 1: parrot("Don't you believe that I can");
- 2: PRINT "Perhaps you would like to be like me.";
- 3: parrot("You want me to be able to");
- }
- PRINT "^";
- IF(++canyou_x == 4) canyou_x = 1;
- ];
- global cani_x = 1;
- [ CanISub;
- switch(cani_x)
- {
- 1: parrot("Perhaps you don't want to",1);
- 2: parrot("Do you want to be able to");
- }
- PRINT "^";
- IF(++cani_x == 3) cani_x = 1;
- ];
- global youare_x = 1;
- [ YouAreSub;
- switch(youare_x)
- {
- 1: parrot("What makes you think I am");
- 2: parrot("Does it please you to believe I am");
- 3: parrot("Perhaps you would like to be",1);
- 4: parrot("Do you sometimes wish you were");
- }
- PRINT "^";
- IF(++youare_x == 5) youare_x = 1;
- ];
- global idont_x = 1;
- [ IDontSub;
- switch(idont_x)
- {
- 1: parrot("Don't you really");
- 2: parrot("Why don't you");
- 3: parrot("Do you wish to be able to");
- 4: "Does that trouble you?";
- }
- PRINT "^";
- IF(++idont_x == 5) idont_x = 1;
- ];
- global ifeel_x = 1;
- [ IFeelSub;
- switch(ifeel_x)
- {
- 1: parrot("Do you often feel");
- 2: parrot("Do you enjoy feeling");
- }
- PRINT "^";
- IF(++ifeel_x == 3) ifeel_x = 1;
- ];
- global whydontyou_x = 1;
- [ WhyDontYouSub;
- switch(whydontyou_x)
- {
- 1: parrot("Do you really believe I don't");
- 2: parrot("Perhaps in good time I will",1);
- 3: parrot("Do you want me to");
- }
- PRINT "^";
- IF(++whydontyou_x == 4) whydontyou_x = 1;
- ];
- global whycanti_x = 1;
- [ WhyCantISub;
- switch(whycanti_x)
- {
- 1: parrot("Do you think you should be able to");
- 2: parrot("Why can't you");
- }
- PRINT "^";
- IF(++whycanti_x == 3) whycanti_x = 1;
- ];
- global areyou_x = 1;
- [ AreYouSub;
- switch(areyou_x)
- {
- 1: parrot("Why are you interested in whether or not I am");
- 2: parrot("Would you prefer if I were not");
- 3: parrot("Perhaps in your fantasies I am",1);
- }
- PRINT "^";
- IF(++areyou_x == 4) areyou_x = 1;
- ];
- global icant_x = 1;
- [ ICantSub;
- switch(icant_x)
- {
- 1: parrot("How do you know you can't");
- 2: PRINT "Have you tried?";
- 3: parrot("Perhaps you can now",1);
- }
- PRINT "^";
- IF(++icant_x == 4) icant_x = 1;
- ];
- global iam_x = 1;
- [ IAmSub;
- switch(iam_x)
- {
- 1: parrot("Did you come to me because you are");
- 2: parrot("How long have you been");
- 3: parrot("Do you believe it is normal to be");
- 4: parrot("Do you enjoy being");
- }
- PRINT "^";
- IF(++iam_x == 5) iam_x = 1;
- ];
- global you_x = 1;
- [ YouSub;
- switch(you_x)
- {
- 1: PRINT "We were discussing you--not me.";
- 2: parrot("Oh, i",1);
- 3: PRINT "You're not really talking about me, are you?";
- }
- PRINT "^";
- IF(++you_x == 4) you_x = 1;
- ];
- global iwant_x = 1;
- [ IWantSub;
- switch(iwant_x)
- {
- 1: parrot("What would it mean to you if you got");
- 2: parrot("Why do you want");
- 3: parrot("Suppose you soon got",1);
- 4: parrot("What if you never got");
- 5: parrot("I sometimes also want",1);
- }
- PRINT "^";
- IF(++iwant_x == 6) iwant_x = 1;
- ];
- global what_x = 1;
- [ WhatSub;
- switch(what_x)
- {
- 1: PRINT "Why do you ask?";
- 2: PRINT "Does that question interest you?";
- 3: PRINT "What answer would please you the most?";
- 4: PRINT "What do you think?";
- 5: PRINT "Are such questions on your mind often?";
- 6: PRINT "What is it that you really want to know?";
- 7: PRINT "Have you asked anyone else?";
- 8: PRINT "Have you asked such questions before?";
- 9: PRINT "What else comes to mind when you ask that?";
- }
- PRINT "^";
- IF(++what_x == 10) what_x = 1;
- ];
- global name_x = 1;
- [ NameSub;
- switch(name_x)
- {
- 1: PRINT "Names don't interest me.";
- 2: PRINT "I don't care about names --please go on.";
- }
- PRINT "^";
- IF(++name_x == 3) name_x = 1;
- ];
- global cause_x = 1;
- [ CauseSub;
- switch(cause_x)
- {
- 1: PRINT "Is that the real reason?";
- 2: PRINT "Don't any other reasons come to mind?";
- 3: PRINT "Does that reason explain anything else?";
- 4: PRINT "What other reasons might there be?";
- }
- PRINT "^";
- IF(++cause_x == 5) cause_x = 1;
- ];
- global sorry_x = 1;
- [ SorrySub;
- switch(sorry_x)
- {
- 1: PRINT "Please don't apologize!";
- 2: PRINT "Apologies are not necessary.";
- 3: PRINT "What feelings do you have when you apologize?";
- 4: PRINT "Don't be so defensive!";
- }
- PRINT "^";
- IF(++sorry_x == 5) sorry_x = 1;
- ];
- global dream_x = 1;
- [ DreamSub;
- switch(dream_x)
- {
- 1: PRINT "What does that dream suggest to you?";
- 2: PRINT "Do you dream often?";
- 3: PRINT "What persons appear in your dreams?";
- 4: PRINT "Are you disturbed by your dreams?";
- }
- PRINT "^";
- IF(++dream_x == 5) dream_x = 1;
- ];
- [ HelloSub;
- PRINT "How do you do ...please state your problem.";
- ];
- global maybe_x = 1;
- [ MaybeSub;
- switch(maybe_x)
- {
- 1: PRINT "You don't seem quite certain.";
- 2: PRINT "Why the uncertain tone?";
- 3: PRINT "Can't you be more positive?";
- 4: PRINT "You aren't sure?";
- 5: PRINT "Don't you know?";
- }
- PRINT "^";
- IF(++maybe_x == 6) maybe_x = 1;
- ];
- global no_x = 1;
- [ NoSub;
- switch(no_x)
- {
- 1: PRINT "Are you saying no just to be negative?";
- 2: PRINT "You are being a bit negative.";
- 3: PRINT "Why not?";
- 4: PRINT "Are you sure?";
- 5: PRINT "Why no?";
- }
- PRINT "^";
- IF(++no_x == 6) no_x = 1;
- ];
- global your_x = 1;
- [ YourSub;
- switch(your_x)
- {
- 1: parrot("Why are you concerned about my");
- 2: parrot("What about your own");
- }
- PRINT "^";
- IF(++your_x == 3) your_x = 1;
- ];
- global always_x = 1;
- [ AlwaysSub;
- switch(always_x)
- {
- 1: PRINT "Can you think of a specific example?";
- 2: PRINT "When?";
- 3: PRINT "What are you thinking of?";
- 4: PRINT "Really, always?";
- }
- PRINT "^";
- IF(++always_x == 5) always_x = 1;
- ];
- global think_x = 1;
- [ ThinkSub;
- switch(think_x)
- {
- 1: PRINT "Do you really think so?";
- 2: parrot("But you are not sure you",1);
- 3: parrot("Do you doubt you");
- }
- PRINT "^";
- IF(++think_x == 4) think_x = 1;
- ];
- global alike_x = 1;
- [ AlikeSub;
- switch(alike_x)
- {
- 1: PRINT "In what way?";
- 2: PRINT "What resemblance do you see?";
- 3: PRINT "What does the similarity suggest to you?";
- 4: PRINT "What other connections do you see?";
- 5: PRINT "Could there really be some connection?";
- 6: PRINT "How?";
- 7: PRINT "You seem quite positive.";
- }
- PRINT "^";
- IF(++alike_x == 8) alike_x = 1;
- ];
- global yes_x = 1;
- [ YesSub;
- switch(yes_x)
- {
- 1: PRINT "Are you sure?";
- 2: PRINT "I see.";
- 3: PRINT "I understand.";
- }
- PRINT "^";
- IF(++yes_x == 4) yes_x = 1;
- ];
- global friend_x = 1;
- [ FriendSub;
- switch(friend_x)
- {
- 1: PRINT "Why do you bring up the topic of friends?";
- 2: PRINT "Do your friends worry you?";
- 3: PRINT "Do your friends pick on you?";
- 4: PRINT "Are you sure you have any friends?";
- 5: PRINT "Do you impose on your friends?";
- 6: PRINT "Perhaps your love for friends worries you.";
- }
- PRINT "^";
- IF(++friend_x == 7) friend_x = 1;
- ];
- global computer_x = 1;
- [ ComputerSub;
- switch(computer_x)
- {
- 1: PRINT "Do computers worry you?";
- 2: PRINT "Are you talking about me in particular?";
- 3: PRINT "Are you frightened by machines?";
- 4: PRINT "Why do you mention computers?";
- 5: PRINT "What do you think machines have to do with your problem?";
- 6: PRINT "Don't you think computers can help people?";
- 7: PRINT "What is it about machines that worries you?";
- }
- PRINT "^";
- IF(++computer_x == 8) computer_x = 1;
- ];
- global default_x = 1;
- [ DefaultSub;
- switch(default_x)
- {
- 1: PRINT "Say, do you have any psychological problems?";
- 2: PRINT "What does that suggest to you?";
- 3: PRINT "I see.";
- 4: PRINT "I'm not sure I understand you fully.";
- 5: PRINT "Come come elucidate your thoughts.";
- 6: PRINT "Can you elaborate on that?";
- 7: PRINT "That is quite interesting.";
- }
- PRINT "^";
- IF(++default_x == 8) default_x = 1;
- ];
- verb 'can'
- * 'you' -> CanYou
- * 'i//' -> CanI;
- verb 'you'
- * 'are' -> YouAre
- * -> You;
- verb 'you^re'
- * -> YouAre;
- verb 'i//'
- * 'don^t' -> IDont
- * 'feel' -> IFeel
- * 'can^t' -> ICant
- * 'am' -> IAm
- * 'want' -> IWant;
- verb 'why'
- * 'don^t' 'you' -> WhyDontYou
- * 'can^t' 'i//' -> WhyCantI
- * -> What;
- verb 'are'
- * 'you' -> AreYou;
- verb 'i^m'
- * -> IAm;
- verb 'what' 'how' 'who' 'where' 'when'
- * -> What;
- verb 'name'
- * -> Name;
- verb 'cause'
- * -> Cause;
- verb 'sorry'
- * -> Sorry;
- verb 'dream'
- * -> Dream;
- verb 'hello' 'hi'
- * -> Hello;
- verb 'maybe'
- * -> Maybe;
- verb 'no'
- * -> No;
- verb 'your'
- * -> Your;
- verb 'always'
- * -> Always;
- verb 'think'
- * -> Think;
- verb 'alike'
- * -> Alike;
- verb 'yes'
- * -> Yes;
- verb 'friend'
- * -> Friend;
- verb 'computer'
- * -> Computer;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement