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

📄 rule.java

📁 java 词法分析器,用于一般的C,C++,VB,PS/SQL 语句的翻译
💻 JAVA
字号:
package fri.patterns.interpreter.parsergenerator.syntax;import java.util.*;import java.io.Serializable;/**	A rule is a list of String symbols on the right side	and a nonterminal on the left side: "a ::= b c d;"	A nonterminal is represented as a String with no quotes,	every terminal must appear quoted by " or ' or ` (backquote).		@author (c) 2004 Fritz Ritzberger*/public class Rule implements Serializable{	private List symbols;	/** Source generator constructor. */	public Rule(String nonterminal, int rightSize)	{		this(new ArrayList(rightSize + 1));		symbols.add(nonterminal);	}	/** Constructing a rule from a String array, first element is interpreted as nonterminal. */	public Rule(String [] symbols)	{		this(SyntaxUtil.ruleToList(symbols));	}	/** Constructing a rule from a String List, first element is interpreted as nonterminal. */	public Rule(List symbols)	{		if (symbols == null)			throw new IllegalArgumentException("Can not construct rule without nonterminal: "+symbols);		this.symbols = symbols;	}	/** Serializable constructor, do not use. */	protected Rule()	{	}	public String getNonterminal()	{		return (String) symbols.get(0);	}		public int rightSize()	{		return symbols.size() - 1;	}		public String getRightSymbol(int i)	{		return (String) symbols.get(i + 1);	}		public void setRightSymbol(String symbol, int i)	{		symbols.set(i + 1, symbol);	}		public void addRightSymbol(String symbol)	{		symbols.add(symbol);	}		public int indexOnRightSide(String symbol)	{		for (int i = 0; i < rightSize(); i++)			if (getRightSymbol(i).equals(symbol))				return i;		return -1;	}	/** Returns true if symbol lists are equal. */	public boolean equals(Object o)	{		return ((Rule)o).symbols.equals(symbols);	}		/** Returns symbol lists hashcode. */	public int hashCode()	{		return symbols.hashCode();	}		/** Returns the syntax as a multiline string. */	public String toString()	{		StringBuffer sb = new StringBuffer(getNonterminal()+" ::= ");		for (int i = 0; i < rightSize(); i++)	{			sb.append(getRightSymbol(i));			sb.append(" ");		}		sb.append(";");		return sb.toString();	}}

⌨️ 快捷键说明

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