/*******************************************************************************
* Copyright (c) 2007 LuaJ. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
package org.luaj.kahluafork.compiler;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Hashtable;
import org.luaj.kahluafork.compiler.FuncState.BlockCnt;
import se.krka.kahlua.vm.LuaException;
import se.krka.kahlua.vm.LuaPrototype;
public class LexState {
public int nCcalls;
Hashtable strings = new Hashtable();
protected static final String RESERVED_LOCAL_VAR_FOR_CONTROL = "(for control)";
protected static final String RESERVED_LOCAL_VAR_FOR_STATE = "(for state)";
protected static final String RESERVED_LOCAL_VAR_FOR_GENERATOR = "(for generator)";
protected static final String RESERVED_LOCAL_VAR_FOR_STEP = "(for step)";
protected static final String RESERVED_LOCAL_VAR_FOR_LIMIT = "(for limit)";
protected static final String RESERVED_LOCAL_VAR_FOR_INDEX = "(for index)";
// keywords array
protected static final String[] RESERVED_LOCAL_VAR_KEYWORDS = new String[] {
RESERVED_LOCAL_VAR_FOR_CONTROL,
RESERVED_LOCAL_VAR_FOR_GENERATOR,
RESERVED_LOCAL_VAR_FOR_INDEX,
RESERVED_LOCAL_VAR_FOR_LIMIT,
RESERVED_LOCAL_VAR_FOR_STATE,
RESERVED_LOCAL_VAR_FOR_STEP
};
private static final Hashtable RESERVED_LOCAL_VAR_KEYWORDS_TABLE = new Hashtable();
static {
for ( int i=0; i<RESERVED_LOCAL_VAR_KEYWORDS.length; i++ )
RESERVED_LOCAL_VAR_KEYWORDS_TABLE.put( RESERVED_LOCAL_VAR_KEYWORDS[i], Boolean.TRUE );
}
private static final int EOZ = (-1);
private static final int MAXSRC = 80;
private static final int MAX_INT = Integer.MAX_VALUE-2;
private static final int UCHAR_MAX = 255; // TODO, convert to unicode CHAR_MAX?
private static final int LUAI_MAXCCALLS = 200;
private static final String LUA_QS(String s) { return "'"+s+"'"; }
private static final String LUA_QL(Object o) { return LUA_QS(String.valueOf(o)); }
public static boolean isReservedKeyword(String varName) {
return RESERVED_LOCAL_VAR_KEYWORDS_TABLE.containsKey(varName);
}
/*
** Marks the end of a patch list. It is an invalid value both as an absolute
** address, and as a list link (would link an element to itself).
*/
static final int NO_JUMP = (-1);
/*
** grep "ORDER OPR" if you change these enums
*/
static final int
OPR_ADD=0, OPR_SUB=1, OPR_MUL=2, OPR_DIV=3, OPR_MOD=4, OPR_POW=5,
OPR_CONCAT=6,
OPR_NE=7, OPR_EQ=8,
OPR_LT=9, OPR_LE=10, OPR_GT=11, OPR_GE=12,
OPR_AND=13, OPR_OR=14,
OPR_NOBINOPR=15;
static final int
OPR_MINUS=0, OPR_NOT=1, OPR_LEN=2, OPR_NOUNOPR=3;
/* exp kind */
static final int
VVOID = 0, /* no value */
VNIL = 1,
VTRUE = 2,
VFALSE = 3,
VK = 4, /* info = index of constant in `k' */
VKNUM = 5, /* nval = numerical value */
VLOCAL = 6, /* info = local register */
VUPVAL = 7, /* info = index of upvalue in `upvalues' */
VGLOBAL = 8, /* info = index of table, aux = index of global name in `k' */
VINDEXED = 9, /* info = table register, aux = index register (or `k') */
VJMP = 10, /* info = instruction pc */
VRELOCABLE = 11, /* info = instruction pc */
VNONRELOC = 12, /* info = result register */
VCALL = 13, /* info = instruction pc */
VVARARG = 14; /* info = instruction pc */
private static class Token {
int token;
/* semantics information */
double r;
String ts;
public void set(Token other) {
this.token = other.token;
this.r = other.r;
this.ts = other.ts;
}
};
int current; /* current character (charint) */
int linenumber; /* input line counter */
int lastline; /* line of last token `consumed' */
final Token t = new Token(); /* current token */
final Token lookahead = new Token(); /* look ahead token */
FuncState fs; /* `FuncState' is private to the parser */
InputStream z; /* input stream */
byte[] buff; /* buffer for tokens */
int nbuff; /* length of buffer */
String source; /* current source name */
byte decpoint; /* locale decimal point */
/* ORDER RESERVED */
final static String luaX_tokens [] = {
"and", "break", "do", "else", "elseif",
"end", "false", "for", "function", "if",
"in", "local", "nil", "not", "or", "repeat",
"return", "then", "true", "until", "while",
"..", "...", "==", ">=", "<=", "~=",
"<number>", "<name>", "<string>", "<eof>",
};
final static int
/* terminal symbols denoted by reserved words */
TK_AND=257, TK_BREAK=258, TK_DO=259, TK_ELSE=260, TK_ELSEIF=261,
TK_END=262, TK_FALSE=263, TK_FOR=264, TK_FUNCTION=265, TK_IF=266,
TK_IN=267, TK_LOCAL=268, TK_NIL=269, TK_NOT=270, TK_OR=271, TK_REPEAT=272,
TK_RETURN=273, TK_THEN=274, TK_TRUE=275, TK_UNTIL=276, TK_WHILE=277,
/* other terminal symbols */
TK_CONCAT=278, TK_DOTS=279, TK_EQ=280, TK_GE=281, TK_LE=282, TK_NE=283,
TK_NUMBER=284, TK_NAME=285, TK_STRING=286, TK_EOS=287;
final static int FIRST_RESERVED = TK_AND;
final static int NUM_RESERVED = TK_WHILE+1-FIRST_RESERVED;
final static Hashtable RESERVED = new Hashtable();
static {
for ( int i=0; i<NUM_RESERVED; i++ ) {
String ts = luaX_tokens[i];
RESERVED.put(ts, new Integer(FIRST_RESERVED+i));
}
}
private boolean isalnum(int c) {
return (c >= '0' && c <= '9')
|| (c >= 'a' && c <= 'z')
|| (c >= 'A' && c <= 'Z')
|| (c == '_');
// return Character.isLetterOrDigit(c);
}
private boolean isalpha(int c) {
return (c >= 'a' && c <= 'z')
|| (c >= 'A' && c <= 'Z');
}
private boolean isdigit(int c) {
return (c >= '0' && c <= '9');
}
private boolean isspace(int c) {
return (c <= ' ');
}
public static LuaPrototype compile(int firstByte, InputStream z, String name) {
LexState lexstate = new LexState(z);
FuncState funcstate = new FuncState();
// lexstate.buff = buff;
lexstate.setinput(firstByte, z, name);
lexstate.open_func(funcstate);
/* main func. is always vararg */
funcstate.isVararg = FuncState.VARARG_ISVARARG;
funcstate.f.name = "@"+name;
lexstate.next(); /* read first token */
lexstate.chunk();
lexstate.check(LexState.TK_EOS);
lexstate.close_func();
FuncState._assert (funcstate.prev == null);
FuncState._assert (funcstate.f.numUpvalues == 0);
FuncState._assert (lexstate.fs == null);
return funcstate.f;
}
public LexState(InputStream stream) {
this.z = stream;
this.buff = new byte[32];
}
void nextChar() {
try {
current = z.read();
} catch ( IOException e ) {
e.printStackTrace();
c
没有合适的资源?快使用搜索试试~ 我知道了~
j2me 手机游戏入门开发--俄罗斯方块_5_使用LUA脚本写游戏
共108个文件
class:64个
java:24个
lua:4个
3星 · 超过75%的资源 需积分: 12 18 下载量 147 浏览量
2012-07-09
14:42:59
上传
评论
收藏 569KB RAR 举报
温馨提示
该程序是基于07年底写的一个J2ME小游戏 俄罗斯方块,将全部逻辑绘制都放到LUA脚本里来做,J2ME方面仅作一个绘制库来使用!
资源推荐
资源详情
资源评论
收起资源包目录
j2me 手机游戏入门开发--俄罗斯方块_5_使用LUA脚本写游戏 (108个子文件)
kemulator.cfg 111B
LexState.class 38KB
StringLib.class 35KB
LexState.class 33KB
LuaState.class 29KB
FuncState.class 28KB
StringLib.class 26KB
FuncState.class 25KB
LuaState.class 23KB
BaseLib.class 18KB
BaseLib.class 16KB
MathLib.class 14KB
MathLib.class 13KB
OsLib.class 9KB
LuaPrototype.class 9KB
OsLib.class 8KB
LuaPrototype.class 7KB
LuaTableImpl.class 7KB
LuaThread.class 7KB
TableLib.class 6KB
LuaTableImpl.class 6KB
LuaThread.class 6KB
CoroutineLib.class 6KB
TableLib.class 6KB
CoroutineLib.class 6KB
cGame.class 5KB
cGame.class 5KB
LuaCompiler.class 4KB
LuaCallFrame.class 4KB
LuaCompiler.class 4KB
UserdataArray.class 4KB
LuaCallFrame.class 3KB
UserdataArray.class 3KB
StringLib$StringPointer.class 3KB
StringLib$StringPointer.class 3KB
tool.class 2KB
tool.class 2KB
StringLib$MatchState.class 1KB
LexState$expdesc.class 1KB
StringLib$MatchState.class 1KB
LexState$expdesc.class 1KB
LuaClosure.class 1KB
LuaClosure.class 1KB
Minesweeper.class 1KB
Minesweeper.class 1KB
UpValue.class 821B
UpValue.class 773B
LexState$Token.class 743B
LexState$Token.class 735B
LuaException.class 670B
LexState$ConsControl.class 644B
LexState$ConsControl.class 644B
LuaException.class 642B
StringLib$MatchState$Capture.class 639B
StringLib$MatchState$Capture.class 639B
InstructionPtr.class 614B
InstructionPtr.class 614B
LexState$LHS_assign.class 596B
LexState$LHS_assign.class 596B
FuncState$BlockCnt.class 517B
FuncState$BlockCnt.class 517B
LuaTable.class 482B
LuaTable.class 482B
JavaFunction.class 177B
JavaFunction.class 177B
.classpath 411B
.eclipseme 243B
J2ME_LUA.jad 266B
J2ME_LUA.jad 266B
J2ME_LUA.jad 241B
J2ME_LUA.jar 128KB
J2ME_LUA.jar 128KB
LexState.java 50KB
StringLib.java 42KB
FuncState.java 42KB
LuaState.java 33KB
BaseLib.java 21KB
MathLib.java 19KB
OsLib.java 13KB
LuaPrototype.java 10KB
LuaTableImpl.java 9KB
LuaThread.java 9KB
CoroutineLib.java 7KB
TableLib.java 7KB
cGame.java 6KB
LuaCallFrame.java 4KB
LuaCompiler.java 4KB
UserdataArray.java 4KB
Minesweeper.java 2KB
JavaFunction.java 2KB
InstructionPtr.java 2KB
LuaClosure.java 2KB
UpValue.java 2KB
LuaException.java 1KB
LuaTable.java 1KB
tool.java 1KB
stdlib.lbc 8KB
stdlib.lbc 8KB
game.lua 13KB
game.lua 13KB
共 108 条
- 1
- 2
资源评论
- geastwind12014-07-02可以参考一下
kome2000
- 粉丝: 314
- 资源: 41
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
- 常用工具集参考用于图像等数据处理
- 音乐展示网页、基于Stenography的图像数字水印添加与提取,以及基于颜色矩和Tamura算法的图像相似度评估算法py源码
- 基于EmguCV(OpenCV .net封装),图像数字水印加解密算法的实现,其中包含最低有效位算法,离散傅里叶变换算法+文档书
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功