A formal definition of the syNTactic structure of a language (see syNTax), normally given in terms of production rules which specify the order of constitueNTs and their sub-constitueNTs in a seNTence (a well-formed string in the language). Each rule has a left-hand side symbol naming a syNTactic category (e.g. "noun-phrase" for a {natural language} grammar) and a right-hand side which is a sequence of zero or more symbols. Each symbol may be either a terminal symbol or a non-terminal symbol. A terminal symbol corresponds to one "lexeme" - a part of the seNTence with no iNTernal syNTactic structure (e.g. an ideNTifier or an operator in a computer language). A non-terminal symbol is the left-hand side of some rule. One rule is normally designated as the top-level rule which gives the structure for a whole seNTence. A grammar can be used either to parse a seNTence (see parser) or to generate one. Parsing assigns a terminal syNTactic category to each input token and a non-terminal category to each appropriate group of tokens, up to the level of the whole seNTence. Parsing is usually preceded by lexical analysis. Generation starts from the top-level rule and chooses one alternative production wherever there is a choice. See also BNF, yacc, attribute grammar, {grammar analysis}.