User Tools

Site Tools


language_definition

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
language_definition [2012/02/26 16:06] – [Comments] xjialanguage_definition [2012/03/17 08:56] (current) – [新语言与C/Pascal/Java的比较] marong
Line 2: Line 2:
   * [[contributed_functions|Contributed functions]]   * [[contributed_functions|Contributed functions]]
   * [[the_eight_queens_solver|The eight queens solver]]   * [[the_eight_queens_solver|The eight queens solver]]
-  * calculator of pi+  * [[pi_calculator|calculator of pi]]
 ====== 新语言与C/Pascal/Java的比较 ====== ====== 新语言与C/Pascal/Java的比较 ======
  
Line 15: Line 15:
 | 变量声明      || 任意块开始处      | 函数开始处       | 任意位置        | 函数开始处       | | 变量声明      || 任意块开始处      | 函数开始处       | 任意位置        | 函数开始处       |
 | 多维数组      || 连续存储空间 | 连续存储空间 | 数组的数组 | 数组的数组 | | 多维数组      || 连续存储空间 | 连续存储空间 | 数组的数组 | 数组的数组 |
 +| 注释      || 非嵌套 | 嵌套 | 非嵌套 | 嵌套 |
  
 +
 +改进的建议(这学期不适用)
 +
 +1. 允许全局变量
 +
 +2. 函数,变量,类型有独立的名字空间
 +
 +3. 变量将强制初始化
 +
 +4. 变量可以在块中间声明
 +
 +5. 去掉break和continue
 +
 +6. 去掉逗号表达式
 +
 +---by marong
 ====== Lexical Aspects ====== ====== Lexical Aspects ======
 A //token// can be a keyword, an identifier, a integer constant, a character constant, or a string constant. A //token// can be a keyword, an identifier, a integer constant, a character constant, or a string constant.
 Tokens are separated by whitespaces and comments. Tokens are separated by whitespaces and comments.
  
-An //identifier// is a sequence of letters, digits, or underscores, which begins with a letterand does not share its name with a keyword. +An //identifier// is a sequence of letters, digits, or underscores, which begins with a letter and does not share its name with a keyword. 
-Case is significant in identifiers.+Note that (i) identifiers cannot start with underscores, and (ii) case is significant in identifiers.
  
 //Line terminators// are ''\n'', ''\r'', and ''\r\n''. //Line terminators// are ''\n'', ''\r'', and ''\r\n''.
Line 31: Line 48:
 //Line comments// starts with two slashes ''/''''/''. Texts behind the two slashes are ignored, until a line terminator is met. //Line comments// starts with two slashes ''/''''/''. Texts behind the two slashes are ignored, until a line terminator is met.
  
-//Block comments// starts with a ''/*''and ends with a ''*/''. Texts in between are ignored. Block comments may nest.+//Block comments// starts with a ''/*'' and ends with a ''*/''. Texts in between are ignored. Block comments may nest.
  
 =====Constants===== =====Constants=====
Line 37: Line 54:
 There are no negative integer constants. There are no negative integer constants.
  
-A //character constant// is one printable character, or escape sequences that represents one character, surrounded by a pair of single quotes '''''+A //character constant// is one printable character or space, or escape sequences that represents one character, surrounded by a pair of single quotes '''''
  
-A //string constant// is a sequence of zero or more printable characters, spaces, or escape sequences, surrounded by a pair of double quotes ''"'' FIXME.+A //string constant// is a sequence of zero or more printable characters, spaces, or escape sequences, surrounded by a pair of double quotes ''"''.
  
 Escape sequences begins with a backslash ''\'', and represent some special characters. Escape sequences are Escape sequences begins with a backslash ''\'', and represent some special characters. Escape sequences are
Line 48: Line 65:
 | ''\\'' | Backslash | | ''\\'' | Backslash |
 | ''\//ddd//'' | The character with ASCII code //ddd// (three decimal digits) | | ''\//ddd//'' | The character with ASCII code //ddd// (three decimal digits) |
-| ''\"'' FIXME | Double quote (**only allowed in a string constant**) |+| ''\"'' | Double quote (**only allowed in a string constant**) |
 | ''\''' | Single quote (**only allowed in a character constant**) | | ''\''' | Single quote (**only allowed in a character constant**) |
  
Line 64: Line 81:
   * ''**native** **int** readInt();''   * ''**native** **int** readInt();''
   * ''**native** **char** readChar();''   * ''**native** **char** readChar();''
-  * ''**native** **string** readString();'' 
-  * ''**native** **string** readLine();'' 
   * ''**native** **int** printInt(**int** i);''   * ''**native** **int** printInt(**int** i);''
   * ''**native** **int** printChar(**char** c);''   * ''**native** **int** printChar(**char** c);''
language_definition.1330272377.txt.gz · Last modified: 2012/02/26 16:06 by xjia

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki