CS 433 Spring 2008 Students' ideas for the syntax of our compiler ====================================================================== Jeff Wehrwein Proposed names: PAL - Pretty Average Language or Positively Amiss Language; or PIL - Positively Inadequate Language. Characteristics: case-sensitive, all keywords are lower case, variables can be mixed, no multi-line comments, foreach instead of for with built-in incrementing that decreases flexibility in the name of being non-identical to java, strongly typed, procedural. Operators: and, or, xor (logical), &, |, ^ (bitwise), mod, +, -, *, / (int division), <<, >> (shift) Control structures: foreach, if, while Examples: int x = 72, y = 48; println(gcd(x,y)); # built-in println function int[0..4] a = {3, 1, 2, 5, 4}; bubblesort(a); foreach (int i from 0 to length(a) by 1) { print(a[i]); # built-in print function } echo(); # kill the program to stop # prints out whatever you type in, as characters void echo() { while (true) { int c = read(); # built-in read function printc(c); # print as character # printlnc would print as a character with a newline at the end } } int gcd(int x, int y) { # pass-by-val if (x mod y == 0) { return y; } else { return gcd(x mod y, y); } } void bubblesort(int[] @a) { # pass-by-ref foreach (int i from 0 to length(a) by 1) { foreach (int j from i to length(a) by -1) { if (a[j-1] > a[j]) { int tmp = a[j]; a[j] = a[j-1]; a[j-1] = tmp; } } } } ====================================================================== Saitulaa Naranong name: lay (for layman code) let num -declare num num be 30 -assign 30 as value or num is 30 starting with [condition] and [step] -for loop ending with [condition] i up -i++ i down -i-- a mod b congruence -a % b = --equality evaluator GreatestFactor(num) { let greatest starting with let i be 1 and i up if num mod i congruence = 0 { greatest is i } ending with i = num/2 return greatest } ====================================================================== Scott Wehrwein Name suggestion: Our Mixture of Grammars (OMG) Language details: Arrays can have arbitrary integer indices. Variables declared as follows: var a,b : int := for assignment, = for equality case insensitive Comment syntax suggestion: +- (comment here) -+ Keywords func and proc define functions and procedures Pass by reference denoted by @ before variable. Sample code: (Note: I got my GCD algorithm from Wikipedia) +- bubblesorts the contents of a -+ proc bubblesort(@a : int[], length : int) { var i,j,temp : int; for(i := 0; i < length-1; i++) { for(j := i+1; j < length; j++) { temp := a[i]; a[i] := a[j]; a[j] := temp; } } } +- computes the GCD of a and b -+ func gcd(a : int, b : int) { var t : int; while (b != 0) { t := b; b := a % b; a := t; } return a; } ====================================================================== David Fouhey ### Copyright Notice Something goes here ### function gcd(a:int, b:int) returns int{ if(b = 0){ return a; } return gcd(b, a%b); } function isEven(x:int) returns bool{ var returnValue:bool; #just to show a way of assignment of booleans returnValue := false; if( (x%2)=0 ){ returnValue := true; } return returnValue; } procedure swap(a: int ptr, b: int ptr){ var temp:int; temp := @a; @a := @b; @b := temp; } procedure bubblesort(a: int[], start: int, end:int){ var i:int, j:int, temp:int; j:= end-1; while(j != start){ for(i := start; i < j; i := i+1){ if(a[i] > a[i+1]){ temp = a[i+1]; a[i+1] = a[i]; a[i] = temp; } } j := j-1; } } #we'll start from 30 to ensure that our maintenance #programmer will have many fun bugs var myArray:int[30..40], length:int, i:int; var a:int, b:int; length := 10; for(i := 1; i < length; i := i+1){ myArray[i] := 11-i; } #we're assuming that arrays are passed by reference, not value bubblesort(myArray,30,40); a := 4; b := 5; swap(&a, &b); if(a = 4){ #uh oh. we're up a creek } WRITE a; WRITE b; ====================================================================== Toby Norden I have a few suggestions for the language. First, in collaboration with Scott, I came up with the name OMG: Our Mixture of Grammars. However, here are a few other things: - No booleans; they can be simulated with integers - Minor point, but I think it would be kind of cool to represent multi-dimensional arrays in this way: a[1.5.3], which would be equivalent to a[1][5][3]. - Braces for scope, or possibly parentheses, but not brackets - An equality operator of =, and an assignment operator of ~> (the arrow points to what the left-hand operand should become) - Multi-line comments indicated with (: at the front and :) at the back, and single-line comments indicated with :)) (fitting in with the theme of the language name...) ====================================================================== Kofi Appiah { gcd(i=int a,int b:o=int) /\* {} only for beginning and end of program, \/ for internal, <- for assign, = for equal */\ int temp; while(a%b!=0) \ temp<-b; b<-a/b; a<-temp; / output b; } { bubblesort (i=int[] a, int b:o=int[]) int z,i,j,temp; z<-a[0]; i<-1; j<-i; for(i;i