2
回答
求解:编译器tiny+语法分析,一个语法不知道怎么推导
终于搞明白,存储TCO原来是这样算的>>>   
EBNF如下,但bfactor不知道怎么推导,选(bool-exp)还是(comparison-exp)?

stmt-sequence -> statement { ; statement }

statement -> if-stmt | repeat-stmt | assign-stmt | read-stmt | write-stmt | while-stmt

while-stmt -> while bool-exp do stmt-sequence end

if-stmt -> if bool-exp then stmt-sequence [else stmt-sequence] end

repeat-stmt -> repeat stmt-sequence until bool-exp

assign-stmt -> identifier:=exp

read-stmt -> read identifier

write-stmt -> write exp

exp -> arithmetic-exp | bool-exp | string-exp| comparison-exp

comparison-exp -> arithmetic-exp comparison-op arithmetic-exp

comparison-op -> < | = | > | >= | <=

arithmetic-exp -> term { addop term }

addop -> + | -

term -> factor { mulop factor }

mulop -> * | /

factor -> (arithmetic-exp) | number | identifier

bool-exp -> bterm { or bterm }

bterm -> bfactor { and bfactor}

bfactor -> true | false | identifier | (bool-exp) | not bfactor | (comparison-exp)

string-exp -> string | identifier

<无标签>
举报
xiangxw
发帖于7年前 2回/305阅
顶部