// Just a relatively quick single test to verify most of // the compiler is working. include 'lib' int x,y,z, string foo; to nextId() into int id { static int lId; lId += 1; id = lId; } class creature { string name; string species; int id = nextId(); morph to speak() { print("grunt"); } } class human extends creature { morph to speak() { print("Hello there, I'm " + self.name); } } to pingCreature(creature c) { print(c); c.speak()} to checkClasses() { creature mimi = ("Mimi", "dog"); human tisa = ("Tisa", "human"); pingCreature(tisa); pingCreature(mimi); } to checkModule() { print("six factorial two ways " + 6*5*4*3*2*1 + " " + factorial(6)); } class point { array[3] of double dims; } flow distance(point a,b) into double d { int dimCount = a.dims.size; if (b.dims.size < dimCount) dimCount = b.dims.size; for (i in 0 til dimCount) { double diff = a.dims[i] - b.dims[i]; d += diff*diff; } d = sqrt(d); } to checkPara() { array of point a = (((1,2,3),),((2,3,4),),((4,5,6),)); array of point b = (((3,2,1),),((4,3,2),),((4,5,6),)); double sumDistance = para (i in 0 til a.size) + distance(a[i], b[i]); print(sumDistance); } to countSpaces(string s) into int count { while (s) { if (s.first(1) == " ") count += 1; s = s.rest(1); } } to countWords(string s) into int count { array of string a = s.words(); count = a.size; } to countTokens(string s) into int count { array of string a = s.tokens(); count = a.size; } to checkStrings() { string sentence = "This is a test sentence."; print(sentence); print("spaces: " + countSpaces(sentence)); print("words: " + countWords(sentence)); print("tokens: " + countTokens(sentence)); print(sentence.words()); print(sentence.tokens()); /* Test once. */ { print("Individial words"); string word, int pos; for (;;) { (word, pos) = sentence.nextWord(pos); if (!word) break; print(" " + word); } } /* Test twice. */ { print("Individual tokens"); string word, int pos; for (;;) { (word, pos) = sentence.nextToken(pos); if (!word) break; print(" " + word); } } } global to checkFile() { file f = fileOpen("input.txt", "r"); for (s in f.readLine()) prin(s); } checkModule(); checkClasses(); checkPara(); checkStrings(); checkFile();