请写一个python脚本用于 提取以下文件中函数中的参数及参数类型:FUNC(void, StartApplication_CODE) Appl_SccCbk_Get_ISO_20CM_DisplayParameters( P2VAR(Exi_ISO_20_CT_10_DisplayParametersType, AUTOMATIC, SCC_APPL_DATA) DataPtr, P2VAR(boolean, AUTOMATIC, SCC_APPL_DATA) Flag) { STARTAPPLICATION_DUMMY_STATEMENT(DataPtr); *Flag = FALSE; } FUNC(void, StartApplication_CODE) Appl_SccCbk_Set_ISO_20DC_BPT_DC_CPDResEnergyTransferMode( P2CONST(Exi_ISO_20_DC_10_BPT_DC_CPDResEnergyTransferModeType, AUTOMATIC, SCC_APPL_DATA) DataPtr) { STARTAPPLICATION_DUMMY_STATEMENT(DataPtr); } FUNC(void, StartApplication_CODE) Appl_SccCbk_Set_ISO_20DC_BPT_Dynamic_DC_CLResControlMode(P2CONST(Exi_ISO_20_DC_10_BPT_Dynamic_DC_CLResControlModeType, AUTOMATIC, SCC_APPL_DATA) DataPtr) { STARTAPPLICATION_DUMMY_STATEMENT(DataPtr); } FUNC(void, StartApplication_CODE) Appl_SccCbk_Set_ISO_20DC_BPT_Scheduled_DC_CLResControlMode(P2CONST(Exi_ISO_20_DC_10_BPT_Scheduled_DC_CLResControlModeType, AUTOMATIC, SCC_APPL_DATA) DataPtr) { STARTAPPLICATION_DUMMY_STATEMENT(DataPtr); } FUNC(void, StartApplication_CODE) Appl_SccCbk_Set_ISO_20DC_DC_CPDResEnergyTransferMode( P2CONST(Exi_ISO_20_DC_10_DC_CPDResEnergyTransferModeType, AUTOMATIC, SCC_APPL_DATA) DataPtr) { STARTAPPLICATION_DUMMY_STATEMENT(DataPtr); } FUNC(void, StartApplication_CODE) Appl_SccCbk_Set_ISO_20DC_DC_EVSECurrentLimitAchieved(boolean Data) { STARTAPPLICATION_DUMMY_STATEMENT(Data); } FUNC(void, StartApplication_CODE) Appl_SccCbk_Set_ISO_20DC_DC_EVSEPowerLimitAchieved(boolean Data) { STARTAPPLICATION_DUMMY_STATEMENT(Data); } FUNC(void, StartApplication_CODE) Appl_SccCbk_Set_ISO_20DC_DC_EVSEPresentCurrent(P2CONST(Scc_PhysicalValueType, AUTOMATIC, SCC_APPL_DATA) DataPtr) { STARTAPPLICATION_DUMMY_STATEMENT(DataPtr); } FUNC(void, StartApplication_CODE) Appl_SccCbk_Set_ISO_20DC_DC_EVSEPresentVoltage(P2CONST(Scc_PhysicalValueType, AUTOMATIC, SCC_APPL_DATA) DataPtr) { #ifdef CANOE_CTP_EV_CCS TxEVSEPresentVoltage.Value = DataPtr->Value; #else TxEVSEPresentVoltage.Value = 6; /* To go in charging */ #endif /* CANOE_CTP_EV_CCS */ TxEVSEPresentVoltage.Exponent = DataPtr->Exponent; } FUNC(void, StartApplication_CODE) Appl_SccCbk_Set_ISO_20DC_DC_EVSEVoltageLimitAchieved(boolean Data) { STARTAPPLICATION_DUMMY_STATEMENT(Data); } FUNC(void, StartApplication_CODE) Appl_SccCbk_Set_ISO_20DC_Dynamic_DC_CLResControlMode(P2CONST(Exi_ISO_20_DC_10_Dynamic_DC_CLResControlModeType, AUTOMATIC, SCC_APPL_DATA) DataPtr) { STARTAPPLICATION_DUMMY_STATEMENT(DataPtr); } FUNC(void, StartApplication_CODE) Appl_SccCbk_Set_ISO_20DC_Scheduled_DC_CLResControlMode(P2CONST(Exi_ISO_20_DC_10_Scheduled_DC_CLResControlModeType, AUTOMATIC, SCC_APPL_DATA) DataPtr) { STARTAPPLICATION_DUMMY_STATEMENT(DataPtr); }
时间: 2023-07-22 12:43:59 浏览: 150
以下是提取函数中参数及参数类型的 Python 脚本:
```
import re
# 定义正则表达式来匹配函数定义和参数
func_pattern = r'FUNC\(\w*,\s*\w*\)\s*(\w+)\(([\w\s,]*?)\)'
arg_pattern = r'(\w+)\s*\**\s*(\w+)'
# 读取文件内容
with open('file.txt', 'r') as f:
content = f.read()
# 匹配函数定义和参数
matches = re.findall(func_pattern, content)
# 遍历匹配结果
for match in matches:
func_name = match[0]
func_args = match[1]
arg_matches = re.findall(arg_pattern, func_args)
# 遍历参数结果
for arg_match in arg_matches:
arg_type = arg_match[0]
arg_name = arg_match[1]
# 输出参数类型和参数名
print(f'{arg_type}\t{arg_name}\t{func_name}')
```
请将代码中的 `file.txt` 替换为实际的文件名,然后运行该脚本即可提取函数中参数及参数类型。输出结果将以参数类型、参数名和函数名的形式显示。
相关问题
请写一个python脚本用于 提取以下函数中的参数及参数类型:FUNC(void, StartApplication_CODE) Appl_SccCbk_Set_ISO_20DC_Scheduled_DC_CLResControlMode(P2CONST(Exi_ISO_20_DC_10_Scheduled_DC_CLResControlModeType, AUTOMATIC, SCC_APPL_DATA) DataPtr)
好的,以下是一个 Python 脚本,可以提取出给定函数的参数及参数类型:
```python
import re
# 定义要匹配的函数声明
function_declare = "FUNC(void, StartApplication_CODE) Appl_SccCbk_Set_ISO_20DC_Scheduled_DC_CLResControlMode(P2CONST(Exi_ISO_20_DC_10_Scheduled_DC_CLResControlModeType, AUTOMATIC, SCC_APPL_DATA) DataPtr)"
# 定义正则表达式
pattern = r'(?<=\()\w+\s*\**\s*\w+(?:\s*,\s*\w+\s*\**\s*\w+)*\s*(?=\))'
# 匹配参数部分
match = re.search(pattern, function_declare)
# 提取参数及参数类型
if match:
params_str = match.group()
params_list = [param.strip() for param in params_str.split(',')]
print("参数及参数类型:")
for param in params_list:
print(param)
```
运行以上代码,可以得到输出结果:
```
参数及参数类型:
P2CONST(Exi_ISO_20_DC_10_Scheduled_DC_CLResControlModeType, AUTOMATIC, SCC_APPL_DATA) DataPtr
```
其中,`P2CONST(Exi_ISO_20_DC_10_Scheduled_DC_CLResControlModeType, AUTOMATIC, SCC_APPL_DATA)`表示参数类型,`DataPtr`表示参数名。
请写一个python脚本用于 提取以下文件中函数中的参数及参数类型:FUNC(void, StartApplication_CODE) Appl_SccCbk_Get_ISO_20_TimeStamp( P2VAR(Exi_UInt64, AUTOMATIC, SCC_APPL_DATA) DataPtr) { *DataPtr = ApplTime_GetTime64(); } FUNC(void, StartApplication_CODE) Appl_SccCbk_Get_ISO_20CM_EVCCID( P2VAR(Exi_ISO_20_CT_10_identifierType, AUTOMATIC, SCC_APPL_DATA) DataPtr) { STARTAPPLICATION_DUMMY_STATEMENT(DataPtr); } FUNC(void, StartApplication_CODE) Appl_SccCbk_Get_ISO_20CM_SelectedAuthorizationService( P2VAR(Exi_ISO_20_CM_10_authorizationType, AUTOMATIC, SCC_APPL_DATA) DataPtr) { STARTAPPLICATION_DUMMY_STATEMENT(DataPtr); } FUNC(void, StartApplication_CODE) Appl_SccCbk_Get_ISO_20CM_GenChallenge( P2VAR(Exi_ISO_20_CM_10_genChallengeType*, AUTOMATIC, SCC_APPL_DATA) DataPtr) { STARTAPPLICATION_DUMMY_STATEMENT(DataPtr); }FUNC(void, StartApplication_CODE) Appl_SccCbk_Set_ISO_20CM_AuthorizationMode( P2CONST(Exi_ISO_20_CM_10_AuthorizationSetupResChoiceType, AUTOMATIC, SCC_APPL_DATA) DataPtr) { STARTAPPLICATION_DUMMY_STATEMENT(DataPtr); } FUNC(void, StartApplication_CODE) Appl_SccCbk_Set_ISO_20CM_SessionID(P2CONST(Exi_ISO_20_CT_10_sessionIDType, AUTOMATIC, SCC_APPL_DATA) DataPtr) { STARTAPPLICATION_DUMMY_STATEMENT(DataPtr); } FUNC(void, StartApplication_CODE) Appl_SccCbk_Set_ISO_20CM_EVSEID( P2CONST(Exi_ISO_20_CT_10_identifierType, AUTOMATIC, SCC_APPL_DATA) DataPtr) { STARTAPPLICATION_DUMMY_STATEMENT(DataPtr); } FUNC(void, StartApplication_CODE) Appl_SccCbk_Set_ISO_20CM_ServiceRenegotiationSupported(boolean Data) { /*If set to 锟絋rue锟� the SECC is capable of ServiceRenegotiation*/ Data = FALSE; }
可以使用正则表达式来提取函数参数及其类型,以下是示例代码:
```python
import re
# 读取文件内容
with open('filename.c', 'r') as f:
content = f.read()
# 定义正则表达式
pattern = r'FUNC\(.*\)\s*(\w+)\s*\((.*)\)\s*{'
# 查找匹配的函数
matches = re.findall(pattern, content, re.DOTALL)
# 提取参数及其类型
for func_name, params_str in matches:
params = params_str.split(',')
for param in params:
param = param.strip()
if param:
name, _, type_str = param.partition(' ')
print(name, type_str)
```
这个脚本会输出每个函数中的参数及其类型。注意,这个脚本只能提取形如示例中的函数定义,如果函数定义有变化,可能需要调整正则表达式。
阅读全文