.Open Syntax of LISP . Lexical Elements of LISP Many of the undefined terms in this document like `cond`, `car`, `cdr`, and so on are lexemes: .See http://www/dick/samples/lisp.lexemes.html .See http://www/dick/samples/comp.text.ASCII.html dot::=http://www/dick/samples/lisp.lexemes.html#dot . Syntax of LISP The two fundamental pieces of LISP syntax are the idea of a list of things and the dotted pair: For any set of strings X, list_of(X)::="(" # X ")", For any set of strings X, dotted_pair(X)::="(" X $dot X ")". A dotted pair is the external image of a node in an internal data structure with two components called "car" and "cdr" for historical reasons. Each component in the pair points at an atomic item or another list. Each list is coded internally as dotted pairs: .As_is (A) = (A.NIL). .As_is (A B) = (A.(B.NIL)). .As_is (A B C ) = (A.(B.(C.NIL)) ). .As_is (A B C D ... Y Z) = (A.(B.(C.(.D ... (Y. (Z. NIL)) ... ). After the lexical analysis the interpreter parses input as a `list_structure` before evaluating it. A list_structure is empty, or a dotted_pair, or an atom, or any number of lists inside a pair of parenthesis. We often call a list structure a list for short. But always be careful to distinguishing 'a list of numbers' from a 'list structure of numbers' list_structure::=$atom | $dotted_pair($list_structure) | $list_of($list_structure). Note. In old LISP, commas were optional separators in lists... but not in XLISP and Scheme. Note. The separating spaces, tabs, etc in a list are all sieved out by the lexical scan. This scan also removes comment lines that start with a semicolon .See http://www/dick/samples/lisp.lexemes.html#comment atom::= .See http://www/dick/samples/lisp.lexemes.html#atom .Open Syntax of S_expressions Note: Syntax assumes that a lexical analysis process has already divided the input into lexemes and deleted any extra whitespace. . Constants constant::= nil | true | number | $string | $quoted_list, word::= .See http://www/dick/samples/lisp.lexemes.html#word string::= .See http://www/dick/samples/lisp.lexemes.html#string quoted_list::="(" "QUOTE" $list_structure ")" | $single_quote $list_structure, -- The second form is an abbreviation for the first. quoted_list::="( QUOTE ( A B C ) )" | " '( A B C )" | .... . Expressions expression::=$S_expression | $macro_call. S_expression::=Syntax_expression. S_expression::= $constant | "(" $function #$expression ")" | $variable. -- The function determines the correct number of expressions. function::=car | cdr | cons | ..., function::= $word & (predefined_function | created_by_define ). macro_call::="(" $macro_name #$list_structure "), -- In a macro the arguments are not automatically evaluated and can be anything at all. macro_name::=cond | define | lambda |..., macro_name::=$word & (predefined_macro | created_by_defmacro). macro::=$lambda_form | $conditional | $definition |..., lambda_form::= "(" lambda $list_of($word) $expression ")". conditional::= "(" cond #( "(" $expression #$expression ")" )")". definition::="(" define "(" $function $arguments ")" #$expression ")" | "(" defun $function $list_of($word) #$expression ")". program::=`Not in pure LISP!`, program::="(" progn #$expression ")". program:semantics::=`The n expressions are evaluated in sequence and the last value (the n'th) is printed`. block::="(" let "(" #$local_variable")" $$expression ")". local_variable::= "(" atom $expression ")". block::semantics=`each local variable is bound to the value of the expression next to it and then the expressions after the local variables are executed`. arguments::= #$word. variable::=$word & (global | local). 'global' variables are created by commands like 'setq' by the user. 'Local' variables are created in lambda_forms, definitions, LETs, PROGs,.... and deleted at the end of the expression or form. .Close Expressions .Close Syntax