从微软学生社区找到的:http://www.wildnoodle.com/ic2006/UI/Compete/Tutorial.aspx

The "h" language

Herbert is programmed in a simple but powerful language called "h". "h" contains elements of traditional high-level languages: statements, procedures, parameters, arguments, and recursion. However, "h" is syntactically simpler, and contains some concepts (procedural arguments) that are not found in traditional languages.

Here are the basic elements of "h":

Element Syntax Examples 
Statements(go straight), r (turn right), or l (turn left), a procedure call, or a procedural parameter.s
Procedure definitionx[(P1,P2,...,Pk)]:y1y2y3...yn where x is any lowercase letter (except s, r, or l), Pi is a parameter, yi is any statement, 0 <= k <=15, and >= 0. If k = 0 (no parameters) then the parentheses are not used.a:ssssr
b(C,D):sra(B)C
ParameterX where X is any uppercase letter.A
Expression[-] X [(+ or -) X [(+ or -) X [(+ or -) X ... ]]] where each X is either a numeric parameter or a number.5
A-5
-A-B-C+1
ArgumentAny number, expression, or sequence of zero or more statements.4
rsr
A-1
Procedure callx[(a1,a2,...,ak)] where x is the name of a procedure and ai is an argument (one for each parameter). If k = 0 (no parameters) then the parentheses are not used. No call is made if any numeric argument is 0 or less.a(1,B-1,srs)
b
Recursionx[(P1,P2,...,Pk)]:y1y2y3...ymx[(a1,a2,a3,..,ak)]ym+1ym+2ym+3...yn where x is any lowercase letter (except s, r, or l), Pi is a parameter, ai is an argument, yi is any statement, 0<= k <= 15, m >= 0, and >= 0. a(A):sa(A-1)
b:sssrb
Main Procedurey1y2y3...yn where yi is any statement and n >= 1.sa(1,rsr)r
Program

<procedure definition> 
     :
     :
<main procedure>

a:ssssra
sssa
ByteAny lowercase or uppercase letter, or any numbers
A
123

a(A,B,C):f(B)Ca(A-1,B,C)
b(A):a(4,5,r)lb(A-1)
f(A):sf(A-1)
b(4)

a(A,B,C):f(B)Ca(A-1,B,C)
b(A):a(4,A,r)b(A-1)
f(A):sf(A-1)
b(10)

a(A,B,C):f(B)Ca(A-1,B,C)
b(A):a(2,11-A,r)b(A-1)
f(A):sf(A-1)
b(10)

a(A,B,C):f(B)Ca(A-1,B,C)
f(A):sf(A-1)
a(4,5,rslsr)


Limitations and Advanced Techniques
Herbert is a pretty capable robot, but he does have his limits:
  • "h" programs can be a maximum of 999 characters (including special characters and digits). Your program can have a maximum of 15 lines, and each line can have a maximum of 127 characters (excluding the function prototype; that is, including everything after the ":").
     
  • Numbers are limited to the range between -256 and 255. You will receive a runtime error if a numeric argument evaluates to a number outside this range.
     
  • Herbert's stack is circular and of size 64K. For a procedure call, the size of each stack frame is 4 * (1 + number of arguments). For evaluating procedural arguments, a stack frame of size 8 is used. What this means in practice is that programs that recurse infinitely, without returning, and without nested procedural arguments, can run forever. Other programs are limited to a maximum call depth of approximately 2,000 calls (depending on the number of arguments being passed). You will receive a runtime error if you attempt to return from a call stack which exceeds this size.
     
  • There is no inherent time limit to running Herbert programs. Keep in mind, however, that your score will be based on the number of buttons pressed (and score uploaded) by the end of the round.
     
  • Level 0, in both the tutorial and full version of Herbert, is a practice level. Programs left on this level are not saved and restored across program sessions.
Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐