//符号表项类 function SymItem(name, type, val) { this.Name = name || ""; this.Type = type || "double"; this.Val = val || 0; } var SymType_INT='int'; var SymType_REAL = 'real'; //符号表类 function SymTable() { this.SymItemList = new Array(); } //定位符号表项 SymTable.prototype.position = function(str) { for ( var i = 0; i < this.SymItemList.length; i++) { if (str == this.SymItemList[i].Name) { return this.SymItemList[i]; } } return null; } //语法树的节点 function Node(type) { this.type = type; // 节点类型 this.str = type; // 节点的字符串形式 this.children = new Array(); // 节点的孩子链表 } //匹配单词 Node.prototype.match1 = function(type) { while (!(Syntax.readall)) { Syntax.getWord(); if (Syntax.word.type == type) { Syntax.nextWord(); break; } else { if (type == "IDENT") { Syntax.error += "
错误发生在第" + Syntax.word.rowNum + "行:缺少变量。"; } else if (type == "INT") { Syntax.error += "
错误发生在第" + Syntax.word.rowNum + "行:缺少整数。"; } else if (type == "REAL") { Syntax.error += "
错误发生在第" + Syntax.word.rowNum + "行:缺少实数。"; } else { Syntax.error += "
错误发生在第" + Syntax.word.rowNum + "行:缺少" + type + "。"; } Syntax.nextWord(); } } } Node.prototype.match2 = function (s) { if (!(Syntax.readall)) { while (!(Syntax.readall)) { Syntax.getWord(); if (Syntax.word.value == s) { Syntax.nextWord(); break; } else { Syntax.error += "
错误发生在第" + Syntax.word.rowNum + "行:缺少 " + s + " 。"; while (s != Syntax.word.value) { Syntax.nextWord(); if (Syntax.index < tokens.length) { Syntax.getWord(); } else break; } Syntax.index--; } Syntax.nextWord(); } } else { Syntax.error += "
错误发生在第" + Syntax.word.rowNum + "行:缺少 " + s + " 。"; } }