DEV Community

Discussion on: Creating a new programming language

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Here's an ammended snippet with tripple backtick and go syntax highlighting, I tried perl but it didn't look so good.

/*
Comments and /*nested*/ comments are a thing
*/

ptinf(T: string, c: ... any) -> int; // We just declare the signature, it is implemented in a c file

MyStruct: Struct{
  id: int;
  age: u8;
}

main := ()-> int{
  a: int;
  a = 1;

  b: int = 2;

  c := a + b;

  printf("The value of c is %d\n", c); // 3

  arr: int[10];
  mys: MyStruct;
  mys.id = 2;
  arr[0] = mys.id;

  printf("The id is %d, and the 0th element is %d\n", mys.id, arr[0]); // 2, 2

  // We also have pointers:

  p: *int;
  p = &c;

  *p = 2;

  printf("The value of c is %d\n", c); // 2

  return 0;
}