⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 yyparser.java

📁 C语言的词法、语法分析器 输出语法分析树
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	// general methods
	public final void yydestructpop(int num) {
		if (yydestructorref != null) {
			while (num > 0) {
				short state = yypeek();
				int action = yydestructorref[state];
				if (action != -1) {
					// user actions in here
					yyvalref.yycopy(yyattributestackref[yytop], true);
					yypop(1);
					yyaction(action);
				}
				else {
					yypop(1);
				}
				num--;
			}
		}
		else {
			yypop(num);
		}
	}

	public final int yyparse() {
		int n = yysetup();
		if (n != 0) {
			return n;
		}
		return yywork();
	}

	public final void yycleanup() {
		yystackref = yysstackref;
		yyattributestackref = yysattributestackref;

		yytop = -1;
	}

	public final boolean yysetstacksize(int size) {
		if (yystackref.length != size) {
			if (size <= yytop) {
				return false;
			}

			if (yystack_max != 0) {
				if (size > yystack_max) {
					return false;
				}
			}

			// allocate
			short stackref[];
			yyattribute attributestackref[];
			if (size <= yysstack_size) {
				stackref = yysstackref;
				attributestackref = yysattributestackref;
			}
			else {
				stackref = new short[size];
				attributestackref = new yyattribute[size];
				int n = yymin(size, yystackref.length);
				for (int i = n; i < size; i++) {
					attributestackref[i] = yynewattribute();
				}
			}

			// copy
			if (stackref != yystackref) {
				int n = yymin(size, yystackref.length);
				for (int i = 0; i < n; i++) {
					stackref[i] = yystackref[i];
				}
			}
			if (attributestackref != yyattributestackref) {
				int n = yymin(size, yystackref.length);
				for (int i = 0; i < n; i++) {
					attributestackref[i] = yyattributestackref[i];
				}
			}

			// assign
			yystackref = stackref;
			yyattributestackref = attributestackref;
		}
		return true;
	}

	public final int yysetup() {
		// initialise variables
		yytop = -1;
		yylookahead = false;
		yyskip = 0;
		yyerrorcount = 0;
		yychar = -1;
		yypopflg = false;

		// push initial state onto the stack
		if (!yypush(0)) {
			if (YYDEBUG) {
				yydabort();
			}
			return 1;
		}
		return 0;
	}

	public final void yywipe() {
		yydestructpop(yytop + 1);
		yydestructclearin();
	}

	public abstract int yywork();
	public abstract void yydestructclearin();

	// service methods
	public int yygettoken() {
		return yylexerref.yylex();
	}

	public void yydiscard(int token) {
		// do nothing
	}

	public void yysyntaxerror() {
		yyerror("syntax error");
	}

	public void yystackoverflow() {
		String text = new String("parser stack overflow (" +
			String.valueOf(yystackref.length) + ")");
		yyerror(text);
	}

	public void yyerror(String text) {
		try {
			yyerr.write(text);
			yyerr.write(yygetlineseparator());
			if (yyerrflush) {
				yyerr.flush();
			}
		}
		catch (IOException e) {
			// do nothing
		}
	}

	// action methods
	public final void yysetin(int token) {
		if (token < 0) {
			token = 0;
		}
		yychar = token;
		yylookahead = true;
	}

	public final boolean yyunclearin() {
		if (!yylookahead && yychar != -1) {
			yylookahead = true;
			return true;
		}
		return false;
	}

	public final void yyabort() {
		yyexit(1);
	}

	public final void yyaccept() {
		yyexit(0);
	}

	public final void yyclearin() {
		yylookahead = false;
	}

	public final void yyerrok() {
		yysetskip(0);
	}

	public final void yyexit(int exitcode) {
		yyexitflg = true;
		yyexitcode = exitcode;
	}

	public final void yyforceerror() {
		yythrowerror(0);
	}

	public final boolean yypopping() {
		return yypopflg;
	}

	public final boolean yyrecovering() {
		return yyskip > 0;
	}

	public final void yyretire(int retirecode) {
		yyretireflg = true;
		yyretirecode = retirecode;
	}

	public final void yythrowerror(int pop) {
		yyerrorflg = true;
		yyerrorpop = pop;
	}

	public final void yythrowerror() {
		yythrowerror(0);
	}

	// debugging functions
	protected final String yytokenstring(int token) {
		int i = 0;
		while (yysymbol[i].yyname != null) {
			if (yysymbol[i].yytoken == token) {
				return yysymbol[i].yyname;
			}
			i++;
		}
		return "illegal-token";
	}

	protected final void yydgettoken(int token) {
		if (YYDEBUG) {
			if (yygetglobaldebug() || yydebug) {
				String tokenstring = yytokenstring(token);

				yydebugoutput("get token ");
				yydebugoutput(tokenstring);
				yydebugoutput(" (");
				yydebugoutput(String.valueOf(token));
				yydebugoutput(")" + yygetlineseparator());
			}
		}
	}

	protected final void yydshift(int token) {
		if (YYDEBUG) {
			if (yygetglobaldebug() || yydebug) {
				String tokenstring = yytokenstring(token);

				yydebugoutput("shift token ");
				yydebugoutput(tokenstring);
				yydebugoutput(" (");
				yydebugoutput(String.valueOf(token));
				yydebugoutput(")" + yygetlineseparator());
			}
		}
	}

	protected final void yydreduce(int rule) {
		if (YYDEBUG) {
			if (yygetglobaldebug() || yydebug) {
				yydebugoutput("reduce rule ");
				yydebugoutput(yyrule[rule]);
				yydebugoutput(" (");
				yydebugoutput(String.valueOf(rule));
				yydebugoutput(")" + yygetlineseparator());
			}
		}
	}

	protected final void yydsyntaxerror() {
		if (YYDEBUG) {
			if (yygetglobaldebug() || yydebug) {
				yydebugoutput("syntax error" + yygetlineseparator());
			}
		}
	}

	protected final void yydaccept() {
		if (YYDEBUG) {
			if (yygetglobaldebug() || yydebug) {
				yydebugoutput("accept" + yygetlineseparator());
			}
		}
	}

	protected final void yydabort() {
		if (YYDEBUG) {
			if (yygetglobaldebug() || yydebug) {
				yydebugoutput("abort" + yygetlineseparator());
			}
		}
	}

	protected final void yyddiscard(int token) {
		if (YYDEBUG) {
			if (yygetglobaldebug() || yydebug) {
				String tokenstring = yytokenstring(token);

				yydebugoutput("discard token ");
				yydebugoutput(tokenstring);
				yydebugoutput(" (");
				yydebugoutput(String.valueOf(token));
				yydebugoutput(")" + yygetlineseparator());
			}
		}
	}

	protected final void yydexit(int exitcode) {
		if (YYDEBUG) {
			if (yygetglobaldebug() || yydebug) {
				yydebugoutput("exit with code ");
				yydebugoutput(String.valueOf(exitcode));
				yydebugoutput(yygetlineseparator());
			}
		}
	}

	protected final void yydthrowerror(int errorpop) {
		if (YYDEBUG) {
			if (yygetglobaldebug() || yydebug) {
				yydebugoutput("throw error and pop ");
				yydebugoutput(String.valueOf(errorpop));
				yydebugoutput(" error handling state(s)" + yygetlineseparator());
			}
		}
	}

	protected final void yydretire(int retirecode) {
		if (YYDEBUG) {
			if (yygetglobaldebug() || yydebug) {
				yydebugoutput("retire with code ");
				yydebugoutput(String.valueOf(retirecode));
				yydebugoutput(yygetlineseparator());
			}
		}
	}

	protected final void yydattemptrecovery() {
		if (YYDEBUG) {
			if (yygetglobaldebug() || yydebug) {
				yydebugoutput("attempting error recovery" + yygetlineseparator());
			}
		}
	}

	// debugging methods
	protected native final void OutputDebugString(final String string);
	protected native final void Sleep(int milliseconds);

	protected final void yydebugoutput(final String string) {
		if (yydebugout != null) {
			try {
				yydebugout.write(string);
				if (yygetglobaldebugflush() || yydebugflush) {
					yydebugout.flush();
				}
			}
			catch (IOException e) {
				// do nohting
			}
		}
		else {
			if (YYWIN32) {
				if (yygetwin32loaded()) {
					try {
						OutputDebugString(string);
						Sleep(0);
					}
					catch (UnsatisfiedLinkError e) {
						// do nothing
					}
				}
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -