public void parse() { int pos = 1; int size; accept(); do { if (lookAhead.TokenType == TokenType.TOKEN_EOF) { break; } int line = l.currentLine; string funcName; Statement body = functionDef(); Statement func = new stat_function(m, line, body, m.parser_getLocalCount()); funcName = m.parser_getCurrentFunction(); size = func.getInstruction(m.code, pos); m.parser_register_function(l.currentLine, funcName); if (funcName.Contains(":")) { var tableFunc = funcName.Split(':'); if (!m.IsGlobalExists(tableFunc[0])) { m.SetGlobal(tableFunc[0], new Varible(new Dictionary <Varible, Varible>(VarCompare.GetInstance()))); } var table = m.GetGlobal(tableFunc[0]); if (table.type != VarType.TYPE_TABLE) { throw new CompileException(line, "Not a table"); //Should never reach here } table.table[new Varible(tableFunc[1])] = new Varible(pos); } else { m.SetGlobal(funcName, new Varible(pos)); } pos += size; } while (!l.eof()); m.CodeLength = pos; }
public void parse() { int pos = 1; int size; accept(); do { if (lookAhead.TokenType == TokenType.TOKEN_EOF) { break; } int line = l.currentLine; Statement body = functionDef(); Statement func = new stat_function(m, line, body, m.parser_getLocalCount(), m.parser_getCurrentFunction() == "main" ? 1 : 0); size = func.getInstruction(m.code, pos); m.parser_register_function(l.currentLine, m.parser_getCurrentFunction()); m.SetGlobal(m.parser_getCurrentFunction(), new Varible(pos)); pos += size; } while (!l.eof()); m.CodeLength = pos; }