《Clite(抽象语法).ppt》由会员分享,可在线阅读,更多相关《Clite(抽象语法).ppt(9页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、clite语法类型的非概要信息和意义(2014025704-116)Program:Declarations 和一个Compound;Declaration:个体Declaration序列;1.Declaration:个体变量,其类型和大小;Type:int,bool,float,char集合的部分;Statement:子类Compound,Skip,Assignment,Conditional和Loop;Compound:个体Statement序列,以他们出现的顺序执行。每一个出现在抽象语法树的相同层次。Skip:跳转语句Assignment:将表达式赋给变量的语句conditional:一
2、个表达式(test)和两个语句(thenbranch和elsebranch),其中一个被执行则另一个则跳过。在if-then语句,elsebranch作为一个Skip语句的实例。Lood:一个表达式(test)和一个只要测试结果是ture就不断重复的语句(循环体)。Expression:子类Variable,Value,Binary,和Unary;Binary:一个Operater和两个Expression;Unary:一个Operator和两个Expression;Operator:&,|,|,=,+,-,和/,表现:boolean运算符:and,or,not;关系运算符:less than
3、,less or equal,equal,not equal,greater than,greater,or equal;数学运算符:plus,minus,times,divideValue:有子类IntValue,FloatValue,BoolValue和CharValueintValue:整数值FloatValue:浮点数值,描述从计算机近似值到一非整数值。BoolValue:Boolean值,也就是说不是ture就是false;Char Value:单个字符值;Clite程序抽象语法树:Program=Declarations decpart;Statements body;Declar
4、ation=Declaration*Declaration=VarableDecl|ArrayDeclVariableDecl=Variable v;Type t ArrayDecl=Variable v;Typt t;Integer size Type=int|bool|float|char Statements=Statemment*statement=Skip|Block|Assignment|Conditional|Loop Skip=Block=Statements Conditionnal=Expression test;Statement thenbranch,elsebranc
5、h Loop=Expression test;Statement bodyAssignment=VariableRef target;Expression source Expression=VariableRef|Value|Binary|UnaryVariable Ref=Variable|ArrayRef Binary=Operator op;Expression term1,term2 Unary=UnaryOp op;Expression term Operator=BooleanOp|RelationnalOp|ArithmeticOp BooleanlOp=&|Relationa
6、lOp=|!=|=ArithmeticOp=+|-|*|/Unary=!|-Variable=String id ArrayRef=String id;Expression index Value=IntValue|BoolValue|FloatValue|CharValue IniValue=Integer intValueFloatValue=Float floatvalue BoolValue=Boolean boolvalue CharValue=Character charvalue/*仔细看一下其实也不难-取决你态度*/A.1 Clite 词汇和具体句法 /*所有引用变量必须声明*
7、/Program-int main()Declarations Statements Declarations-Declaration Declaration-Type Identifier integer.Identifier integer;Type-int|bool|float|char Statements-Statement Statement-:|Block|Assignment|If Statement|WhileStatement Block-Statement Assignment-Identifier Expression =Expression;If Statement-
8、if(Expression)Statement else Statement WhileStatement-while(Expression)Statement Expression-Conjunction|Conjunction Conjunction-Equality&Equality Equality-RelationEquOp Relation EquOp-=|!=Relation-AdditionRelOp Addition RelOp-|=Addition-Term AddOp Term AddOp-+|-Term-Factor MulOp Factor MuiOp-*|/|%Fa
9、ctor-UnaryOpPrimaryUnaryOp-|!Primary-Identifier Expression|Literal|(Expression)|Type(Expression)Identifier-Letter Letter|Digit Boolean-true|false Float-Integer.Integer Char-ASCIICharA.2 Clite 的抽象句法 /*所有声明变量必须唯一*/Program=Declarations decpart;Statements body;Declaration=Declaration*Declarations=Variab
10、leDecl|ArrayDecl VariableDecl=Variable V;Type t ArrayDecl=Variable v;Type t;Integer size Type=int|bool|float|char Statements=Statement*Statement=Skip|Block|Assignment|Conditional|Loop Skip=Block=StatementsConditional=Experssion test;Statement thenbranch,elsebranch Loop=Expression test;Statement body
11、 Assignment=VariableRef target;Expression source Expression=VariableRef|Value|Binary|Unary VariableRef=Variable|ArrayRefBinary=BinaryOp op;Expression term1,term2 Unary=UnaryOp op;Expression term1,term2 Operator=BooleanOp|RelationalOp|ArithmeticOp|UnaryOp BooleanlOp=&|RelationalOp=|!=|=ArithmeticOp=+|-|*|/Unary=!|-Variable=String id ArrayRef=String id;Expression index Value=IntValue|BoolValue|FloatValue|CharValue IniValue=Integer intValueFloatValue=Float floatvalue BoolValue=Boolean boolvalue CharValue=Character charvalue
限制150内