词法分析 从左至右读字符流的源程序、识别(拼)单词 position initial rate 60
词法分析 从左至右读字符流的源程序、识别(拼)单词 例: position := initial + rate * 60;
词法分析 position: initial rate *60 单词类型 单词值 标识符1d1) posItion 算符(赋值) 标识符2id2) initial 算符(加) 标识符3(id3) rate 算符(乘) 整数 60 分号
词法分析 position := initial + rate * 60; 单词类型 单词值 标识符1(id1) position 算符(赋值) := 标识符2(id2) initial 算符(加) + 标识符3(id3) rate 算符(乘) * 整数 60 分号 ;
又如一个C源程序片断:inta; a=a+2 词法分析后可能返回: 单词类型 单词值 保留字 标识符(变量名) a 界符 标识符(变量名) a 算符(赋值) 标识符(变量名) 算符(加) 整数 界符
又如一个C源程序片断: int a; a = a + 2; 词法分析后可能返回: 单词类型 单词值 保留字 int 标识符(变量名) a 界符 ; 标识符(变量名) a 算符(赋值) = 标识符(变量名) a 算符(加) + 整数 2 界符 ;
有关术语 词法分析( exical analysis or scanning) The stream of characters making up a source program is read from left to right and grouped into tokens, which are sequences of characters that have a collective meaning 单词- token 保留字-- reserved word 标识符- identifier( user-defined name)
有关术语 词法分析(lexical analysis or scanning) --The stream of characters making up a source program is read from left to right and grouped into tokens,which are sequences of characters that have a collective meaning. 单词---token 保留字---reserved word 标识符 ---identifier(user-defined name)
语法分析 功能:层次分析依据源程序的语法规则把源程 序的单词序列组成语法短语(表示成语法树) position : initial rate *60 规则 <赋值语句>∷三<标识符>“:=”<表达式> <表达式>:三<表达式>“+”<表达式> <表达式>∷三<表达式>“*”<表达式> 表达式>∷=“(”<表达式>“)” <表达式>∷三<标识符> <表达式>∷三<整数> <表达式>∷=<实数>
语法分析 功能:层次分析.依据源程序的语法规则把源程 序的单词序列组成语法短语(表示成语法树). position := initial + rate * 60 ; 规则 <赋值语句>::=<标识符>“:=”<表达式> <表达式>::=<表达式>“+”<表达式> <表达式>::=<表达式>“*”<表达式> <表达式>::=“(”<表达式>“)” <表达式>::=<标识符> <表达式>::=<整数> <表达式>::=<实数>