token in c and cpp (C preprocessor)

本文详细介绍了C语言中六种代币类型:关键字、标识符、常量、字符串字面量、标点符号和预处理代币。每种类型都有具体的示例,如头文件名、标识符、预处理数字等,这些内容源自ISO/IEC9899:201x标准。

C tokens are of six types, They are,

  • keyword
  • identifier
  • constant
  • string-literal
  • punctuator

preprocessing-token:

  • head-name
  • identifer
  • pp-number
  • character-constant
  • string-literal
  • punctuator
  • each non-white-space character that cannot be one of the above

reference :
ISO/IEC 9899:201x
N1570
C11

[To be continued]

转载于:https://www.cnblogs.com/youchihwang/p/9029416.html

以下代码可以解决问题,def find_matching_brace(start_token): """ 找到与起始花括号匹配的结束花括号 """ depth = 1 current = start_token.next while current: if current.str == '{': depth += 1 elif current.str == '}': depth -= 1 if depth == 0: return current current = current.next return None def is_preprocessor(token): """检查token是否为预处理指令""" # 首选方法:token.preprocessor属性 if hasattr(token, 'preprocessor') and token.preprocessor: return True # 备选方法:token.isPreprocessor属性 if hasattr(token, 'isPreprocessor') and token.isPreprocessor: return True # 回退方法:检查字符串是否以#开头 token_str = token.str if token_str and token_str.startswith('#'): return True # 检查是否在预处理块中 if hasattr(token, 'previous') and token.previous: prev_str = token.previous.str if prev_str and prev_str.startswith('#'): return True return False @cppcheck.checker def check_function_length(cfg, data): """ 检查函数体是否超过80行(非空非注释行) """ reported_errors = set() # 避免重复报告相同错误 # 正确遍历所有token的方法 token = cfg.tokenlist[0] while token: # 检查是否是函数名 if token.isName and token.function: # 跳过模板参数 next_token = token.next if next_token and next_token.str == '<': depth = 1 next_token = next_token.next while next_token and depth > 0: if next_token.str == '<': depth += 1 elif next_token.str == '>': depth -= 1 next_token = next_token.next # 查找参数列表起始 while next_token and next_token.str != '(' and next_token.str != ';' and next_token.str != '{': next_token = next_token.next if not next_token or next_token.str != '(': token = token.next continue # 跳过参数列表 depth = 1 next_token = next_token.next while next_token and depth > 0: if next_token.str == '(': depth += 1 elif next_token.str == ')': depth -= 1 next_token = next_token.next # 查找函数体起始花括号 while next_token and next_token.str != '{' and next_token.str != ';': next_token = next_token.next if not next_token or next_token.str == ';': token = token.next continue # 函数声明,无函数体 # 确保花括号位置唯一(避免重复检查) brace_key = (next_token.linenr, next_token.column) if brace_key in reported_errors: token = token.next continue reported_errors.add(brace_key) # 找到匹配的结束花括号 end_brace = find_matching_brace(next_token) if not end_brace: token = token.next continue # 统计非空非注释行数 lines = set() current = next_token while current and current != end_brace.next: # 跳过预处理指令和空行 if not (is_preprocessor(current) or current.str.isspace()): lines.add(current.linenr) current = current.next line_count = len(lines) if line_count > 80: # 获取函数名(处理析构函数情况) func_name = token.str if token.previous and token.previous.str == '~': func_name = '~' + func_name # 生成错误消息键(避免重复报告) error_key = (token.linenr, f"function:{func_name}") if error_key not in reported_errors: cppcheck.reportError( token, 'style', f"Function '{func_name}' exceeds 80 lines ({line_count} lines). " "Consider refactoring into smaller functions." ) reported_errors.add(error_key) token = token.next
10-16
第三方支付功能的技术人员;尤其适合从事电商、在线教育、SaaS类项目开发的工程师。; 使用场景及目标:① 实现微信与支付宝的Native、网页/APP等主流支付方式接入;② 掌握支付过程中关键的安全机制如签名验签、证书管理与敏感信息保护;③ 构建完整的支付闭环,包括下单、支付、异步通知、订单状态更新、退款与对账功能;④ 通过定时任务处理内容支付超时与概要状态不一致问题:本文详细讲解了Java,提升系统健壮性。; 阅读应用接入支付宝和建议:建议结合官方文档与沙微信支付的全流程,涵盖支付产品介绍、开发环境搭建箱环境边学边练,重点关注、安全机制、配置管理、签名核心API调用及验签逻辑、异步通知的幂等处理实际代码实现。重点与异常边界情况;包括商户号与AppID获取、API注意生产环境中的密密钥与证书配置钥安全与接口调用频率控制、使用官方SDK进行支付。下单、异步通知处理、订单查询、退款、账单下载等功能,并深入解析签名与验签、加密解密、内网穿透等关键技术环节,帮助开发者构建安全可靠的支付系统。; 适合人群:具备一定Java开发基础,熟悉Spring框架和HTTP协议,有1-3年工作经验的后端研发人员或希望快速掌握第三方支付集成的开发者。; 使用场景及目标:① 实现微信支付Native模式与支付宝PC网页支付的接入;② 掌握支付过程中核心的安全机制如签名验签、证书管理、敏感数据加密;③ 处理支付结果异步通知、订单状态核对、定时任务补偿、退款及对账等生产级功能; 阅读建议:建议结合文档中的代码示例与官方API文档同步实践,重点关注支付流程的状态一致性控制、幂等性处理和异常边界情况,建议在沙箱环境中完成全流程测试后再上线。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值