123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- 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 += "<br>错误发生在第" + Syntax.word.rowNum + "行:缺少变量。";
-
- } else if (type == "INT") {
- Syntax.error += "<br>错误发生在第" + Syntax.word.rowNum + "行:缺少整数。";
- } else if (type == "REAL") {
- Syntax.error += "<br>错误发生在第" + Syntax.word.rowNum + "行:缺少实数。";
- } else {
- Syntax.error += "<br>错误发生在第" + 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 += "<br>错误发生在第" + 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 += "<br>错误发生在第" + Syntax.word.rowNum + "行:缺少 " + s + " 。";
-
- }
- }
|