上下文有关语法（context-sensitive grammar, CSG） 是一种 形式语法，其推导规则的左手端和右手端都可以被 终结符 和 非终结符 构成的上下文围绕。
上下文有关语法 比 上下文无关语法 更具有一般性。
A context-sensitive grammar (CSG) is a formal grammar in which the left-hand sides and right-hand sides of any production rules may be surrounded by a context of terminal and nonterminal symbols. Context-sensitive grammars are more general than context-free grammars, in the sense that there are languages that can be described by a CSG but not by a context-free grammar. Context-sensitive grammars are less general (in the same sense) than unrestricted grammars. Thus, CSGs are positioned between context-free and unrestricted grammars in the Chomsky hierarchy.