资源简介
程序分析课程上机要求,方便广大学子拷贝。其中.g为ANTLR源文件,可生成语法分析器和语法树的.java文件,然后进行必要的修改(添加成员变量)。提供的.java文件已经修改好。直接放在项目里,选择主类Frame,编译运行即可。在窗口里输入测试文件的路径,即可绘出图像。
代码片段和文件信息
// $ANTLR 2.7.7 (20060930): “parer.g“ -> “DrawLexer.java“$
package fcc;
import java.io.InputStream;
import antlr.TokenStreamException;
import antlr.TokenStreamIOException;
import antlr.TokenStreamRecognitionException;
import antlr.CharStreamException;
import antlr.CharStreamIOException;
import antlr.ANTLRException;
import java.io.Reader;
import java.util.Hashtable;
import antlr.CharScanner;
import antlr.InputBuffer;
import antlr.ByteBuffer;
import antlr.CharBuffer;
import antlr.Token;
import antlr.CommonToken;
import antlr.RecognitionException;
import antlr.NoViableAltForCharException;
import antlr.MismatchedCharException;
import antlr.TokenStream;
import antlr.ANTLRHashString;
import antlr.LexerSharedInputState;
import antlr.collections.impl.BitSet;
import antlr.SemanticException;
public class DrawLexer extends antlr.CharScanner implements DrawParserTokenTypes TokenStream
{
public DrawLexer(InputStream in) {
this(new ByteBuffer(in));
}
public DrawLexer(Reader in) {
this(new CharBuffer(in));
}
public DrawLexer(InputBuffer ib) {
this(new LexerSharedInputState(ib));
}
public DrawLexer(LexerSharedInputState state) {
super(state);
caseSensitiveLiterals = false;
setCaseSensitive(false);
literals = new Hashtable();
}
public Token nextToken() throws TokenStreamException {
Token theRetToken=null;
tryAgain:
for (;;) {
Token _token = null;
int _ttype = Token.INVALID_TYPE;
resetText();
try { // for char stream error handling
try { // for lexical error handling
switch ( LA(1)) {
case ‘o‘:
{
mORIGIN(true);
theRetToken=_returnToken;
break;
}
case ‘r‘:
{
mROT(true);
theRetToken=_returnToken;
break;
}
case ‘i‘:
{
mIS(true);
theRetToken=_returnToken;
break;
}
case ‘d‘:
{
mDRAW(true);
theRetToken=_returnToken;
break;
}
case ‘+‘:
{
mPLUS(true);
theRetToken=_returnToken;
break;
}
case ‘;‘:
{
mSEMICO(true);
theRetToken=_returnToken;
break;
}
case ‘(‘:
{
mLPAREN(true);
theRetToken=_returnToken;
break;
}
case ‘)‘:
{
mRPAREN(true);
theRetToken=_returnToken;
break;
}
case ‘‘:
{
mCOMMA(true);
theRetToken=_returnToken;
break;
}
case ‘p‘:
{
mPI(true);
theRetToken=_returnToken;
break;
}
case ‘0‘: case ‘1‘: case ‘2‘: case ‘3‘:
case ‘4‘: case ‘5‘: case ‘6‘: case ‘7‘:
case ‘8‘: case ‘9‘:
{
mNUM(true);
theRetToken=_returnToken;
break;
}
case ‘c‘:
{
mCOS(true);
theRetToken=_returnToken;
break;
}
case ‘l‘:
{
mLOG(true);
theRetToken=_returnToken;
break;
}
case ‘\t‘: case ‘\n‘: case ‘\r‘: case ‘ ‘:
{
mWS(true);
theRetToken=_returnToken;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1741 2012-06-08 14:05 fcc\fcc\treewalker.g
文件 685 2012-06-08 10:49 fcc\fcc\DrawParserTokenTypes.java
文件 719 2012-06-08 10:56 fcc\fcc\DrawTreeWalkerTokenTypes.java
文件 21295 2012-06-08 11:08 fcc\fcc\DrawLexer.java
文件 2035 2012-06-08 14:05 fcc\fcc\parer.g
文件 15807 2012-06-08 13:45 fcc\fcc\DrawParser.java
文件 9276 2012-06-08 13:57 fcc\fcc\DrawTreeWalker.java
文件 6542 2012-06-10 18:59 fcc\fcc\fr
文件 204 2012-06-10 18:57 fcc\fcc\test.txt
目录 0 2012-06-08 11:02 fcc\fcc
目录 0 2012-06-08 09:25 fcc
----------- --------- ---------- ----- ----
58304 11
评论
共有 条评论