Victory Road  

Go Back   Victory Road > General > Technology
FAQ Community Today's Posts Search

Notices

 
 
Search this Thread
  #1  
Old May 23, 2009, 09:20:49 PM
SpaceMan++'s Avatar
SpaceMan++ SpaceMan++ is offline
Zoroark
 
Join Date: Aug 2008
Location: BC
Posts: 288
Default If you are creating your own programming language

If you are going to create your own programming language, how will it look like?

I will create one based on Perl, it requires less keystrokes.
Hello World
Code:
print 'Hello, world!' # Prints "Hello, world!"
# or
$str = 'Hello, world'
print $str
# even variable functions
$print = "print"
$print{$str}
# $print $str will be treated as $print * $str
Quote styles (uses UNICODE)
Code:
print q?Hello, world!?
If/else
Code:
? $name == 'Naruto' print "Your name is Naruto, right?"
??$name == 'Sasuke' print "Hi, Sasuke"
?? { # sometimes you must use braces to tell the parser it is part of if/else
  print "Who are you?" $name = <STDIN # no need to use > at last. Also, semicolon can be omitted if it does not confuse the parser
}
I/O Streams
Code:
open FILE, "file.txt"
?* <FILE  {# $_ will be automatically assigned, ?* means "while"
  >STDERR "Still more line: $line" # '>' operator writes to a writeable stream
  $line++; # It doesn't need to be declared, like in Perl
}
close FILE
Variable-variables
Code:
# You can use expression after $ to get a variable-variable
$("var${counter}") = 100;
Associated references
Code:
# When you are assigning a value, you can use expressions and conditions to get lvalue
$var || $var2 = 100 #will set $var or $var2 to 100
1 + 1 = 1 # sets $_ to 1, the left hand side does not associate to any reference
$a + $b = 1 # sets $b to 1
print("Hello, world!") = 1 # print does not return reference, so this is like the previous one
Regexp
Code:
$_ = 'string';
?/string/ print "Matched."
Other ideas I've compiled to one text file:
Code:
Comments
 # line comment
 #> block comment <#

Operators
 1 + 1 # 2
 15 - 3 # 12
 2 * 5 # 10
 2 5 # NOT ALLOWED: two statements of: 2; 5;
 2(5) # 10
 10 / 5 # 2
 -1.5 # -1.5
 (1 + 5) * 2 # 12
 $bool = 0; !$bool # true
 $a || $b # or operator
 $a && $b # and operator
 $a | $b # bitwise or
 $a & $b # bitwise and
 $a ^ $b # NOT exponent, bitwise XOR
 ~$b # bitwise NOT
 cos sin 10 # unary functions, same as: cos(sin(10))
 $ "var" # identifiers are also strings, $ is an unary operator
 $$var # variable-variables
 $ "value-\{$var - 1}" # String variable-variable and interpolation

Functions
 print "Hello, world!", " $name" # Top-level expressions can have multiple arguments
 print push $array, 12 # print(push $array), 12 Doesn't work
 print (push $array, 12)  # parens embed Expressions
 print cos rad $value # cos and rad are treated like unary operators

 ?& getmax $a $b {
  ?. # return
   ?  $a > $b $a # embedded if/else
   ?? $b
 }
 # one-expression functions
 ?& getmax $a $b : ? $a > $b : $a ?? $b

 ?&getmax$a$b?:?$a>$b$a??$b # Compressed

Goto labels
 label: # sets a label
 ?^label # goto a label

If/Else
 ?  $a > 90 : print "You got A" # if (':' after condition may be optional)
 ?: $a > 80 : print "You got B" # else if
 ?? print "You got C" # else

 ? $answer == 2 print "You are right"
 ?? print "You are wrong"

 # or ?? { print "You got C" }
 ? !$name {
   print "Enter your name:\n"
   $name = input()
   ?^ begin
 }

While loops
 $b = rand 100 # random numbers from 0 to 100
 ?* $a != $b {
  print "Incorrect, try again."
  $a = <STDIN;
 }

For loops
 ?% $a($b) # foreach $a in $b
  print $a # Remember braces can be omitted sometimes
 ?% $b print $_ # foreach $_ in $b
 ?% 1..10 print $_ # for $_ = 1 to 10
 ?% $j : 1..10..2 : print $j # for $j = 1 to 10 step 2
 ?% $i=0;$i<0;$i++ # Sometimes you can omit ; between statements
  print $i

Keywords
 ?& function
 ? if
 ?: else if
 ?? else
 ?* while
 ?% for
 ?^ goto
  #2  
Old July 30, 2009, 07:09:01 PM
§ethi Xzon §ethi Xzon is offline
Floatzel
 
Join Date: Nov 2008
Posts: 150
Default Re: If you are creating your own programming language

My un-named, pretty much a better version of basic.

Code:
displayText("This is probably inaccurate. I don't care.");
ask("Does this language suck?",AvaiKeys = Y,N,"Title")input$
if input$ = Y then
    displayText("Blegh.")
else
    displayText("Well I'm glad to hear that.")
Loop 3 then end
Other various functions: displayVectorGraphics([shape],x,y); display3DModel([file location],X,Y,Z)model; createCamera3D(x,y,z), textureModel([file location], sprite name); textureModel3D([file location]ModelName); removeTexture(texturename); removeTexture3D(texturename); playMusic([file location], loop number[0 is infinite, 1 is play once, 2 is play twice, so on.]) and so on. I think it would be great but it might have long loading times if it wasn't made efficiently.
  #3  
Old August 16, 2009, 09:39:26 PM
KingOfKYA's Avatar
KingOfKYA KingOfKYA is offline
Volcarona
 
Join Date: Sep 2008
Location: On The PC
Posts: 523
Default Re: If you are creating your own programming language

i like they python syntax because it forces noobs to write good code me included
 

Forum Jump


All times are GMT -8.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Victory Road ©2006 - 2024, Scott Cat333Pokémon Cheney
Theme by A'bom and Cat333Pokémon