tokens(Tokens专业术语)
一、derivation编译原理
首先把变量声明语句的规则,用形式化的方法表达一下。它的左边是一个非终结符(Non-terminal)。右边是它的产生式(ProductionRule)。在语法解析的过程中,左边会被右边替代。如果替代之后还有非终结符,那么继续这个替代过程,直到最后全部都是终结符(Terminal),也就是Token。只有终结符才可以成为AST的叶子节点。这个过程,也叫做推导(Derivation)过程。
intDeclaration:IntIdentifier(’=’additiveExpression)?;
上面的文法翻译成程序语句,代码如下
SimpleASTNodenode=null;
Tokentoken=tokens.peek();//预读
if(token!=null&&token.getType()==TokenType.Int){//匹配Int
token=tokens.read();//消耗掉int
if(tokens.peek().getType()==TokenType.Identifier){//匹配标识符
token=tokens.read();//消耗掉标识符
//创建当前节点,并把变量名记到AST节点的文本值中,
//这里新建一个变量子节点也是可以的
node=newSimpleASTNode(ASTNodeType.IntDeclaration,token.getText());
token=tokens.peek();//预读
if(token!=null&&token.getType()==TokenType.Assignment){
tokens.read();//消耗掉等号
SimpleASTNodechild=additive(tokens);//匹配一个表达式
if(child==null){
thrownewException("inval
二、token是远程办公的意思吗
不是!token的意思是:n.代币;(用以启动某些机器或用作支付方式的)专用辅币;代价券;赠券;礼券。adj.装样子的;装点门面的;敷衍的;作为标志的;象征性的(付款或费用)。
例句:1.Someoftheoldertelephonesstillonlyaccepttokens.
一些较老式的电话机仍然只收代币。
2.Atokenattempt,effort,offer,etc.
装样子的尝试、努力、好意等。
3.Thegovernmentagreedtosendasmalltokenforcetothearea.
政府同意派遣一小支象征性的部队到那一地区。