1、clite语法类型的非概要信息和意义 (2014025704-116),Program:Declarations 和一个Compound; Declaration:个体Declaration序列; Declaration:个体变量,其类型和大小; Type:int,bool,float,char集合的部分; Statement:子类Compound,Skip,Assignment,Conditional和Loop; Compound:个体Statement序列,以他们出现的顺序执行。每一个出现在抽象语法树的相同层次。Skip:跳转语句 Assignment:将表达式赋给变量的语句,condit
2、ional:一个表达式(test)和两个语句(thenbranch和elsebranch),其中一个被执行则另一个则跳过。在if-then语句,elsebranch作为一个Skip语句的实例。 Lood:一个表达式(test)和一个只要测试结果是ture就不断重复的语句(循环体)。 Expression:子类Variable,Value,Binary,和Unary; Binary:一个Operater和两个Expression; Unary:一个Operator和两个Expression; Operator:数学运算符:plus,minus,times,divide,Value:有子类IntV
3、alue,FloatValue,BoolValue和CharValue intValue:整数值 FloatValue:浮点数值,描述从计算机近似值到一非整数值。 BoolValue:Boolean值,也就是说不是ture就是false; Char Value:单个字符值;,Clite程序抽象语法树:Program=Declarations decpart; Statements body; Declaration=Declaration*Declaration=VarableDecl | ArrayDecl VariableDecl=Variable v;Type tArrayDecl=Va
4、riable v;Typt t;Integer sizeType= int | bool | float | charStatements=Statemment*statement=Skip | Block |Assignment |Conditional |LoopSkip=Block=StatementsConditionnal=Expression test ;Statement thenbranch,elsebranchLoop=Expression test;Statement body Assignment=VariableRef target;Expression sourceE
5、xpression=VariableRef | Value | Binary |Unary,Variable Ref=Variable | ArrayRefBinary=Operator op;Expression term1,term2Unary=UnaryOp op;Expression termOperator=BooleanOp | RelationnalOp | ArithmeticOpBooleanlOp= Expression index Value = IntValue | BoolValue | FloatValue | CharValueIniValue =Integer
6、intValue FloatValue=Float floatvalueBoolValue =Boolean boolvalueCharValue = Character charvalue/*仔细看一下其实也不难-取决你态度*/,A.1Clite 词汇和具体句法 /*所有引用变量必须声明*/Program int main () Declarations Statements Declarations Declaration Declaration Type Identifier integer .Identifier integer;Type int | bool | float | ch
7、ar Statements-StatementStatement: | Block | Assignment | If Statement | WhileStatementBlock -Statement Assignment -Identifier Expression =Expression;If Statementif (Expression) Statement else Statement WhileStatement while (Expression) StatementExpressionConjunction |Conjunction Conjunction Equality
8、& Equality EqualityRelationEquOp Relation ,EquOp-= | != RelationAdditionRelOp Addition RelOp | =Addition Term AddOp Term AddOp+ | -Term Factor MulOp Factor MuiOp* | / | %FactorUnaryOpPrimary UnaryOp - | !PrimaryIdentifier Expression | Literal | (Expression )| Type (Expression) Identifier Letter Lett
9、er | Digit Boolean-true | falseFloatInteger .IntegerChar ASCIIChar,A.2 Clite 的抽象句法 /*所有声明变量必须唯一*/Program =Declarations decpart; Statements body; Declaration =Declaration*Declarations =VariableDecl | ArrayDecl VariableDecl = Variable V ; Type tArrayDecl = Variable v;Type t;Integer sizeType= int | boo
10、l | float | char Statements =Statement*Statement =Skip | Block | Assignment | Conditional | LoopSkip =Block=Statements Conditional=Experssion test;Statement thenbranch, elsebranchLoop=Expression test ;Statement bodyAssignment=VariableRef target ; Expression sourceExpression =VariableRef | Value |Bin
11、ary | Unary VariableRef =Variable | ArrayRef,Binary=BinaryOp op;Expression term1,term2Unary=UnaryOp op;Expression term1,term2Operator=BooleanOp | RelationalOp | ArithmeticOp | UnaryOpBooleanlOp= Expression index Value = IntValue | BoolValue | FloatValue | CharValueIniValue =Integer intValue FloatValue=Float floatvalueBoolValue =Boolean boolvalueCharValue = Character charvalue,