feat:init
This commit is contained in:
@@ -771,40 +771,18 @@ export class CppCodeExecutor {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否是函数调用(包括带参数的)
|
// 检查是否是自定义函数调用(包括带括号的实参,如 f((n + 1));)
|
||||||
const functionCallMatch = line.match(/(\w+)\s*\(([^)]*)\)\s*;?/);
|
const customCall = this.parseCustomFunctionCall(line);
|
||||||
if (functionCallMatch) {
|
if (customCall) {
|
||||||
const functionName = functionCallMatch[1];
|
statements.push({
|
||||||
const argumentsStr = functionCallMatch[2];
|
type: 'function_call',
|
||||||
|
functionName: customCall.functionName,
|
||||||
// 排除C++关键字和控制结构
|
arguments: customCall.arguments,
|
||||||
const cppKeywords = [
|
lineNumber: isMainFunction ? this.getActualLineNumber(i) : i + 1,
|
||||||
'for', 'while', 'if', 'else', 'switch', 'case', 'return',
|
content: line // 保存原始内容用于行号映射
|
||||||
'int', 'string', 'bool', 'void', 'float', 'double', 'char'
|
});
|
||||||
];
|
i++;
|
||||||
|
continue;
|
||||||
// 检查是否是游戏API函数(这些不是自定义函数)
|
|
||||||
const gameApiFunctions = [
|
|
||||||
'playerMove', 'playerJump', 'turnLeft', 'turnRight',
|
|
||||||
'vehicleMove', 'turnVehicleLeft', 'turnVehicleRight',
|
|
||||||
'player_data', 'player_position', 'vehicle_position'
|
|
||||||
];
|
|
||||||
|
|
||||||
if (!cppKeywords.includes(functionName) &&
|
|
||||||
!gameApiFunctions.includes(functionName) &&
|
|
||||||
!line.includes('cout')) {
|
|
||||||
// 这是自定义函数调用
|
|
||||||
const parsedArguments = this.parseArguments(argumentsStr);
|
|
||||||
statements.push({
|
|
||||||
type: 'function_call',
|
|
||||||
functionName: functionName,
|
|
||||||
arguments: parsedArguments,
|
|
||||||
lineNumber: isMainFunction ? this.getActualLineNumber(i) : i + 1,
|
|
||||||
content: line // 保存原始内容用于行号映射
|
|
||||||
});
|
|
||||||
i++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析不同类型的语句
|
// 解析不同类型的语句
|
||||||
@@ -1346,29 +1324,16 @@ export class CppCodeExecutor {
|
|||||||
async executeSimpleStatement(content) {
|
async executeSimpleStatement(content) {
|
||||||
debugLog(`🔍 执行简单语句: ${content}`);
|
debugLog(`🔍 执行简单语句: ${content}`);
|
||||||
|
|
||||||
// 检查是否是函数调用(包括带参数的)
|
// 检查是否是自定义函数调用(包括带括号的实参,如 f((n + 1));)
|
||||||
const functionCallMatch = content.match(/(\w+)\s*\(([^)]*)\)\s*;?/);
|
const customCall = this.parseCustomFunctionCall(content);
|
||||||
if (functionCallMatch) {
|
if (customCall && this.functions.has(customCall.functionName)) {
|
||||||
const functionName = functionCallMatch[1];
|
console.log(`📞 调用自定义函数: ${customCall.functionName}(${customCall.arguments.join(', ')})`);
|
||||||
const argumentsStr = functionCallMatch[2];
|
await this.executeFunctionCall({
|
||||||
|
type: 'function_call',
|
||||||
// 排除C++关键字和控制结构
|
functionName: customCall.functionName,
|
||||||
const cppKeywords = [
|
arguments: customCall.arguments
|
||||||
'for', 'while', 'if', 'else', 'switch', 'case', 'return',
|
});
|
||||||
'int', 'string', 'bool', 'void', 'float', 'double', 'char'
|
return;
|
||||||
];
|
|
||||||
|
|
||||||
// 检查是否是自定义函数(排除关键字)
|
|
||||||
if (!cppKeywords.includes(functionName) && this.functions.has(functionName)) {
|
|
||||||
console.log(`📞 调用自定义函数: ${functionName}(${argumentsStr})`);
|
|
||||||
const parsedArguments = this.parseArguments(argumentsStr);
|
|
||||||
await this.executeFunctionCall({
|
|
||||||
type: 'function_call',
|
|
||||||
functionName: functionName,
|
|
||||||
arguments: parsedArguments
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 自增/自减语句 (如 a++; 或 ++a;)
|
// 自增/自减语句 (如 a++; 或 ++a;)
|
||||||
@@ -2158,7 +2123,46 @@ export class CppCodeExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析函数调用参数
|
// 解析自定义函数调用,正确处理实参里的嵌套括号(如 f((n + 1)))
|
||||||
|
parseCustomFunctionCall(content) {
|
||||||
|
if (!content) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cppKeywords = [
|
||||||
|
'for', 'while', 'if', 'else', 'switch', 'case', 'return',
|
||||||
|
'int', 'string', 'bool', 'void', 'float', 'double', 'char'
|
||||||
|
];
|
||||||
|
const gameApiFunctions = [
|
||||||
|
'playerMove', 'playerJump', 'turnLeft', 'turnRight',
|
||||||
|
'vehicleMove', 'turnVehicleLeft', 'turnVehicleRight',
|
||||||
|
'player_data', 'player_position', 'vehicle_position'
|
||||||
|
];
|
||||||
|
|
||||||
|
const nameMatch = content.match(/(\w+)\s*\(/);
|
||||||
|
if (!nameMatch) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const functionName = nameMatch[1];
|
||||||
|
if (cppKeywords.includes(functionName) ||
|
||||||
|
gameApiFunctions.includes(functionName) ||
|
||||||
|
content.includes('cout')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsedArguments = this.extractFunctionArguments(content, functionName);
|
||||||
|
if (parsedArguments === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
functionName,
|
||||||
|
arguments: parsedArguments
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解析函数调用参数,按逗号分割时忽略括号内的逗号
|
||||||
parseArguments(argumentsStr) {
|
parseArguments(argumentsStr) {
|
||||||
const argumentsList = [];
|
const argumentsList = [];
|
||||||
|
|
||||||
@@ -2166,14 +2170,29 @@ export class CppCodeExecutor {
|
|||||||
return argumentsList; // 无参数调用
|
return argumentsList; // 无参数调用
|
||||||
}
|
}
|
||||||
|
|
||||||
// 分割参数,支持多个参数
|
let currentArg = '';
|
||||||
const argParts = argumentsStr.split(',');
|
let nestedParens = 0;
|
||||||
|
|
||||||
for (const argPart of argParts) {
|
for (let j = 0; j < argumentsStr.length; j++) {
|
||||||
const trimmed = argPart.trim();
|
const char = argumentsStr[j];
|
||||||
if (trimmed) {
|
|
||||||
argumentsList.push(trimmed);
|
if (char === '(') {
|
||||||
|
nestedParens++;
|
||||||
|
} else if (char === ')') {
|
||||||
|
nestedParens--;
|
||||||
|
} else if (char === ',' && nestedParens === 0) {
|
||||||
|
if (currentArg.trim()) {
|
||||||
|
argumentsList.push(currentArg.trim());
|
||||||
|
}
|
||||||
|
currentArg = '';
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentArg += char;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentArg.trim()) {
|
||||||
|
argumentsList.push(currentArg.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
return argumentsList;
|
return argumentsList;
|
||||||
@@ -2624,35 +2643,8 @@ export class CppCodeExecutor {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析参数
|
// 解析参数,按逗号分割时忽略括号内的逗号
|
||||||
if (!argsString.trim()) {
|
const args = this.parseArguments(argsString);
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// 按逗号分割参数,但要考虑括号嵌套
|
|
||||||
const args = [];
|
|
||||||
let currentArg = '';
|
|
||||||
let nestedParens = 0;
|
|
||||||
|
|
||||||
for (let j = 0; j < argsString.length; j++) {
|
|
||||||
const char = argsString[j];
|
|
||||||
|
|
||||||
if (char === '(') {
|
|
||||||
nestedParens++;
|
|
||||||
} else if (char === ')') {
|
|
||||||
nestedParens--;
|
|
||||||
} else if (char === ',' && nestedParens === 0) {
|
|
||||||
args.push(currentArg.trim());
|
|
||||||
currentArg = '';
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentArg += char;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentArg.trim()) {
|
|
||||||
args.push(currentArg.trim());
|
|
||||||
}
|
|
||||||
|
|
||||||
debugLog(`🔍 函数${functionName}提取到的参数:`, args);
|
debugLog(`🔍 函数${functionName}提取到的参数:`, args);
|
||||||
return args;
|
return args;
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
// config.js
|
// config.js
|
||||||
|
|
||||||
// const CONFIG = {
|
// const CONFIG = {
|
||||||
// DataServerBaseUrl: "https://server.001code.com", // 在这里定义服务器地址
|
// DataServerBaseUrl: "https://test.server.001code.com", // 在这里定义服务器地址
|
||||||
// // DataServerBaseUrl: "https://server.001code.com", // 在这里定义服务器地址
|
// // DataServerBaseUrl: "https://test.server.001code.com", // 在这里定义服务器地址
|
||||||
// // DataServerBaseUrl: "https://server.001code.com",
|
// // DataServerBaseUrl: "https://test.server.001code.com",
|
||||||
// // DataServerBaseUrl: "https://server.001code.com",
|
// // DataServerBaseUrl: "https://test.server.001code.com",
|
||||||
// // DataServerBaseUrl: "https://server.001code.com",
|
// // DataServerBaseUrl: "https://test.server.001code.com",
|
||||||
// // DataServerBaseUrl: "https://server.001code.com",
|
// // DataServerBaseUrl: "https://test.server.001code.com",
|
||||||
// version : "2025010301",
|
// version : "2025010301",
|
||||||
// unitycdndir : 'https://oss-rpwqy.jjwlcdn.com/001_code_unity_res_20250826',
|
// unitycdndir : 'https://oss-rpwqy.jjwlcdn.com/001_code_unity_res_20250826',
|
||||||
// unitycdnbuilddir : 'https://oss-rpwqy.jjwlcdn.com/001_code_unity_res_20250826/Build',
|
// unitycdnbuilddir : 'https://oss-rpwqy.jjwlcdn.com/001_code_unity_res_20250826/Build',
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
// // 可以根据需要添加其他配置
|
// // 可以根据需要添加其他配置
|
||||||
|
|
||||||
// disabledev: true,
|
// disabledev: false,
|
||||||
// usecdn :true, //资源走CDN
|
// usecdn :true, //资源走CDN
|
||||||
// lvlock :false, //关卡5关解锁,下一关加锁
|
// lvlock :false, //关卡5关解锁,下一关加锁
|
||||||
// lvlock_normal_learn :true, //常规关起锁
|
// lvlock_normal_learn :true, //常规关起锁
|
||||||
@@ -78,12 +78,12 @@
|
|||||||
|
|
||||||
|
|
||||||
// const CONFIG = {
|
// const CONFIG = {
|
||||||
// // DataServerBaseUrl: "https://server.001code.com", // 在这里定义服务器地址
|
// // DataServerBaseUrl: "https://test.server.001code.com", // 在这里定义服务器地址
|
||||||
// // DataServerBaseUrl: "https://server.001code.com", // 在这里定义服务器地址
|
// // DataServerBaseUrl: "https://test.server.001code.com", // 在这里定义服务器地址
|
||||||
// // DataServerBaseUrl: "https://server.001code.com",
|
// // DataServerBaseUrl: "https://test.server.001code.com",
|
||||||
// DataServerBaseUrl: "https://server.001code.com",
|
// DataServerBaseUrl: "https://test.server.001code.com",
|
||||||
// // DataServerBaseUrl: "https://server.001code.com",
|
// // DataServerBaseUrl: "https://test.server.001code.com",
|
||||||
// // DataServerBaseUrl: "https://server.001code.com",
|
// // DataServerBaseUrl: "https://test.server.001code.com",
|
||||||
// version : "2025011001",
|
// version : "2025011001",
|
||||||
// unitycdndir : 'https://oss-rpwqy.jjwlcdn.com/001_code_unity_res_20250826',
|
// unitycdndir : 'https://oss-rpwqy.jjwlcdn.com/001_code_unity_res_20250826',
|
||||||
// unitycdnbuilddir : 'https://oss-rpwqy.jjwlcdn.com/001_code_unity_res_20250826/Build',
|
// unitycdnbuilddir : 'https://oss-rpwqy.jjwlcdn.com/001_code_unity_res_20250826/Build',
|
||||||
@@ -91,8 +91,8 @@
|
|||||||
|
|
||||||
// // 可以根据需要添加其他配置
|
// // 可以根据需要添加其他配置
|
||||||
|
|
||||||
// // disabledev: true,
|
// // disabledev: false,
|
||||||
// disabledev: true,
|
// disabledev: false,
|
||||||
// usecdn :true, //资源走CDN
|
// usecdn :true, //资源走CDN
|
||||||
// lvlock :false, //关卡5关解锁,下一关加锁
|
// lvlock :false, //关卡5关解锁,下一关加锁
|
||||||
// lvlock_normal_learn : !(typeof localStorage !== 'undefined' &&
|
// lvlock_normal_learn : !(typeof localStorage !== 'undefined' &&
|
||||||
@@ -157,12 +157,12 @@
|
|||||||
|
|
||||||
|
|
||||||
const CONFIG = {
|
const CONFIG = {
|
||||||
// DataServerBaseUrl: "https://server.001code.com", // 在这里定义服务器地址
|
// DataServerBaseUrl: "https://test.server.001code.com", // 在这里定义服务器地址
|
||||||
// DataServerBaseUrl: "https://server.001code.com", // 在这里定义服务器地址
|
// DataServerBaseUrl: "https://test.server.001code.com", // 在这里定义服务器地址
|
||||||
// DataServerBaseUrl: "https://server.001code.com",
|
// DataServerBaseUrl: "https://test.server.001code.com",
|
||||||
DataServerBaseUrl: "https://server.001code.com",
|
DataServerBaseUrl: "https://test.server.001code.com",
|
||||||
// DataServerBaseUrl: "https://server.001code.com",
|
// DataServerBaseUrl: "https://test.server.001code.com",
|
||||||
// DataServerBaseUrl: "https://server.001code.com",
|
// DataServerBaseUrl: "https://test.server.001code.com",
|
||||||
|
|
||||||
version: "2026071701",
|
version: "2026071701",
|
||||||
|
|
||||||
@@ -182,7 +182,7 @@ const CONFIG = {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
disabledev: true,
|
disabledev: false,
|
||||||
usecdn: false,
|
usecdn: false,
|
||||||
lvlock: false,
|
lvlock: false,
|
||||||
lvlock_normal_learn: !(typeof localStorage !== 'undefined' &&
|
lvlock_normal_learn: !(typeof localStorage !== 'undefined' &&
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user