⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vt.doc

📁 Unix下的MUD客户端程序
💻 DOC
📖 第 1 页 / 共 5 页
字号:
VT Program DocumentationDescription-----------Vaportalk (VT) is an Internet client program.  Its main features arean I/O scheduler for communication with remote hosts, a minimalwindowing system, and a C-like language called VTC.VT and its documentation were written by Greg Hudson, who can bereached via Internet email at ghudson@athena.mit.edu.This file documents the VT program.  It makes reference to thedistribution VTC code from time to time, but does not describe itfully.  Most users of VT will initially be more concerned with thedistribution documentation in dist.doc.Startup-------VT must read a startup file to initialize key bindings and otherparameters.  The startup file is a VTC file	1. If VT is invoked with an argument, it loads that file.	2. If the environment variable VTSTART exists, VT loads that		file.	3. VT searches for the following files, in order:		~/main.vtc		~/vt/dist/main.vtc		~/vt/main.vtc		/usr/local/lib/vt/main.vtcOnce one file is loaded, VT stops searching for others.  If VT isinvoked with an argument or the VTSTART environment variable exists,and VT cannot load either of those files, then it will print a warningmessage.  VT will exit if it cannot find any startup file.Environment variables---------------------Apart from the VTSTART environment variable, VT looks in the VTBOLDONand VTBOLDOFF variables for the names of the terminal capabilities touse for turning boldface text on or off.  These default to "md" and"me", which are the usual boldface capabilities.  (A commonalternative pair is "so" and "se", which turn inverse text on andoff.)The Compiler------------VTC is a C-like language.  It does not feature strong typing, typedefinitions, or a switch statement.  It does feature pointers andpointer arithmetic, structures in modified form, and dynamicallocation of arrays and strings.VTC Syntax----------VTC tokens are of five types: string constants, integer constants,operators, reserved words, and identifiers.  Reserved words andidentifiers are case-sensitive.The VTC compiler ignores spaces and tabs, except as they separatetokens.	 It also ignores text between C comment delimiters (/* and*/), and the rest of a line after a pair of slashes (//).VT character and string literals are similar to old-style C characterand string literals.  A character literal is a single character insidesingle quotes ('c'), while a string literal is a sequence ofcharacters inside double quotes ("This is a string literal").  Tospecify an unprintable or special character in a character or stringliteral, use one of the following codes:	\n	Newline	\t	Tab	\v	Vertical tab	\b	Backspace	\r	Carriage return	\f	Form feed	\\	Backspace	\'	Single quote	\"	Double quoteYou do not need to escape single quotes, and you only need to escapedouble quotes within string literals.  You may also follow a backslashwith up to three octal digits specifying the ASCII code for thecharacter.  The parser will ignore a newline preceded by a backslash,allowing the string literal to continue on the next line.An integer constant is a series of digits with no suffix.  To specifyan integer in octal, begin the series of digits with 0.  To specify aninteger in hexidecimal, prefix the series of digits with 0x or 0X.The compiler reserves the following words:	do while if else for func goto break continue returnThe compiler also reserves the names of builtin objects and namedconstants (q.v.).  The compiler does not reserve the names of VTC orprimitive functions.  You may use those names as variables, althoughthis may make your code confusing to read.An identifier is a sequence of letters, numbers, and underscores,beginning with a letter or an underscore.  Use identifiers to refer tovariable and function names.  Identifiers are significant to 32characters and are case-sensitive.A directive to the VTC parser is either a function definition or acommand.  These have the formats:	definition:	func ident (params) [local vars] compound			func ident (params) --> expr ;	command:	[local vars] statements[local vars] may be omitted in either case, but the square bracketsare literal.  Command directives are executed immediately, whilefunction definitions are saved so that you can call the functionslater.  "--> expr ;" is a shorthand for "{ return expr ; }" in afunction definition.Parameters and local vars are sequences of zero or more identifiersseparated by commas ("foo, bar, baz").  Parameters can also be twosuch sequences separated by a slash ("foo, bar / baz, quux"), in whichcase the identifiers in the second sequence denote optionalparameters.  Calling a function with fewer arguments than it hasnon-optional parameters results in a runtime error, although callinga function with more arguments than it has parameters is legal.Some examples:	func echoln(line) { echo(line, "\n"); } /* Echo a line */	[i] for (i = 0; i < 5; i++) echoln(itoa(i)); // Count to 5A statement can be one of the following:	statement:	compound			expression;			if (expression) statement			if (expression) statement else statement			while (expression) statement			do statement while (expression)			for (expression; expression; expression)				statement			label: statement			goto label;			break;			continue;			return expression;You can omit the expressions in the expression statement and thereturn statement, as well as any of the expressions in the forstatement.  ";", "for (;;);", and "return;" are all valid statements.A compound statement, as in C, is zero or more statements contained in{ and }.All the flow control statements are identical their counterparts in C.Expressions are as follows:	lvalue:		* expression			identifier			expression[expression]			expression->identifier			(lvalue)	expression:	lvalue			constant			builtin-object			. identifier			identifer(args)			(lvalue)(args)			(expression)			prefix-operator expression			expression postfix-operator			expression binop expression			lvalue assign-op expression			expression ? expression : expression			expression ? : expression			! expression			~ expression			- expression			+ expression			& lvalue			++ lvalue			-- lvalue			lvalue ++			lvalue --". identifer" indicates a pointer to the function named by theidentifier.  In C, you might write:	extern int bar();	int (*foo)() = bar;	(*foo)(args); /* or foo(args); for most compilers */In VTC you would write:	foo = .bar;	(*foo)(args);In most C compilers, you can write "foo(args)" instead of"(*foo)(args)".  VTC does not permit this.Expressions are mostly the same in VTC as in C.	 The logicaloperators, as in C, only evaluate their right-hand arguments if theirleft-hand arguments are not sufficient to determine their truthvalues.  The operators are, in order of precedence from highest tolowest:	unary:		.	unary:		! ~ ++ -- + - * &	binary:		* / %	binary:		+ -	binary:		<< >>	binary:		< <= > >=	binary:		== !=	binary:		&	binary:		^	binary:		|	binary:		&&	binary:		||	binary:		?:	assignment:	= += -= *= /= %= &= != <<= >>= ?:=	binary:		,The unary, assignment, and conditional operators associate right toleft.  All other operators associate left to right.  The interpreterevaluates arguments and binary expressions left to right.'args' refers to zero or more expressions separated by commas.	Thecomma binary operator does not apply to expressions in an argumentlist.  Outside of an argument list, a list of expressions separated bycommas takes the value of the last expression in the list, as in C.As noted in the expression syntax, you can omit the middle argument ofa conditional expression, in which case it evaluates to the value ofthe left argument if the left argument is true, and to the value ofthe right argument if the left argument is false.  There is also a ?:=operator; '(a ?:= b)' is equivalent to '((a) = (a) ? : (b))'.The + operator can take two string pointer arguments, producing aconcatenated string.The form of input to the parser is slightly restricted.	 The parsermust know when the user has completed a parser directive (command orfunction definition) because of the way it accepts input.  The parserassumes that this is true at the end of a line unless one of thefollowing conditions holds:	(1) You escape the newline with a backslash.	(2) You have entered more { tokens than } tokens (you are in	    the middle of a compound statement).	(3) You have entered a func token but not a --> token or a {	    token (you are declaring a function and have not begun the	    function body).	(4) You have entered a "/*" but no matching "*/".The following is a syntactically legal sequence of input:	func foo()	{		bar();	}	{		foo(); bar();	}	foo(); bar();	if (foo()) \		bar();Note that a line like:	foo(); bar();is somewhat different than two separate lines:	foo();	bar();The intepreter treats the first as a single task and the second as twotasks.  In the first case, if foo() aborts, bar() will not beexecuted, and if foo() is suspended due to an input request or sleep()primitive, bar() will wait until foo() exits before running.  In thesecond case, bar(); will run right after foo() terminates or issuspended.The parser will become confused if a directive contains unbalancedleft and right brace tokens.  A sufficiently long series of rightbraces will rectify this situation.Fatal Errors------------VT will abort a task whenever the task passes arguments of the wrongtype to a primitive, attempts to assign to a negative array or stringelement, passes too few arguments to a VTC function, calls or makes apointer to an undefined function, or makes an illegal assignment to abuiltin variable.See the section on "non-fatal errors" below for information on how VTdeals with other error conditions.Data----VT has eleven data types, each associated with a named constant:	Type		Description	----		-----------	T_INT		Integer	T_PPTR		Primitive pointer	T_BPTR		Builtin object pointer	T_RMT		Remote pointer	T_WIN		Window pointer	T_KEY		Key binding pointer	T_FILE		File pointer	T_SPTR		String pointer	T_APTR		Array (or variable) pointer	T_FPTR		Function pointer	T_REG		Regexp pointer	T_ASSOC		Association type	T_PLIST		Property list pointer	T_NULL		No valueUse NULL to refer to the data object with type T_NULL.  0 and NULL arefalse.  Every other data value is true.Variables---------There are three types of variables: parameters, local variables, andglobals variables.  You declare parameters in a function declaration,and local variables in the square brackets at the beginning of afunction declaration or command.You can store any type of data in a variable.  You can take itsaddress with the & operator.  The address of a variable is an objectof type T_APTR.  VT will reset any data value holding the address of aparameter or local variable when those variables go out of scope.To refer to a global variable, simply use its name in a variablecontext, assuming you are not in the scope of a local or parametervariable with the same name.  If the global variable does not alreadyexist, VT will create it and initialize it to NULL.Arrays------Arrays are sequences of variables.  They are of three classes: arraysreturned by the alloc() primitive, local and parameter variablearrays, and the global variable array.  The first and third type ofarray will stretch if the user attempts to assign values to an arrayelement past the current amount of allocated space, so those arrayscan be thought of as an infinite storage space with a fixed beginning.Uninitialized array elements and an elements before the beginning ofan array have the value NULL.  Assigning to an element before thebeginning of an array results in a runtime error.You cannot explicitly free an array.  VT frees a function's local andparameter arrays when the function exits.  VT frees arrays returned byalloc() when there is nothing pointing to them.  VT will notautomatically free a self-referential array or group of arrays ifnothing external is pointing to them, but you can free all such groupsof arrays by calling the garbage() primitive at any time.alloc() takes a size argument.  This number will not affect programcorrectness, since the array will stretch if necessary.  It is onlyfor reducing wasted space and unnecessary resizing.Property lists and association types------------------------------------Property lists vaguely mirror structures in C.	Here is an exampleusing of using a property list:	Tmytype = new_assoc();	p = alloc(2, Tmytype);	p->name = "Druid";	p->num = 673;	echo("p->name: ", p->name, ", p->num: ", itoa(p->num), "\n");A property list consists of an array and an association type.  Tocreate a new association type, use the new_assoc() primitive.  Allplists with a given association type will have the same associationsbetween element names and array offsets.  Each time you use a newelement name with a plist of a given association type, it assigns anarray offset to it, starting at 0.To retrieve an element of a plist, you can use the lookup() primitive."lookup(plist, str)" returns a pointer to the array element in<plist>'s array containing the element <str>.  If <str> is a simplestring constant, you can use "plist->str" as an abbreviation forabbreviation for "*lookup(plist, str)".You can retrieve the array part of a plist using the base() primitive.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -