使用asn1c编译ETSI的VAM-PDU-Descriptions.asn时遇WITH语法错误求助
ASN.1编译报错:unexpected TOK_WITH, expecting ';'
使用命令asn1c VAM-PDU-Descriptions.asn编译ETSI官方提供的VAM-PDU-Descriptions.asn文件时,触发如下语法错误:
ASN.1 grammar parse error near VAM-PDU-Descriptions.asn:21 (token "WITH"): syntax error, unexpected TOK_WITH, expecting ';' Cannot parse "VAM-PDU-Descriptions.asn"
出错的ASN.1代码片段如下(重点为第21-22行的WITH SUCCESSORS):
VAM-PDU-Descriptions {itu-t(0) identified-organization(4) etsi(0) itsDomain(5) wg1(1) 103300 vam(1) major-version-3(3) minor-version-1(1)} DEFINITIONS AUTOMATIC TAGS ::= BEGIN IMPORTS AccelerationChangeIndication, BasicContainer, CartesianAngle, ClusterBreakupInfo, ClusterJoinInfo, ClusterLeaveInfo, Curvature, CurvatureCalculationMode, DeltaTimeQuarterSecond, GenerationDeltaTime, HeadingChangeIndication, ItsPduHeader, LanePosition, LateralAcceleration, LongitudinalAcceleration, PathHistory, PathPredicted, SequenceOfSafeDistanceIndication, SequenceOfTrajectoryInterceptionIndication, SequenceOfTrajectoryInterceptionIndication, Speed, StabilityChangeIndication, StationId, TrajectoryInterceptionIndication, VerticalAcceleration, VruClusterInformation, VruDeviceUsage, VruEnvironment, VruExteriorLights, GeneralizedLanePosition, VruProfileAndSubprofile, VruMovementControl, VruSizeClass, YawRate, Wgs84Angle FROM ETSI-ITS-CDD {itu-t (0) identified-organization (4) etsi (0) itsDomain (5) wg1 (1) 102894 cdd (2) major-version-3 (3) minor-version-1 (1) } WITH SUCCESSORS ; VAM ::= SEQUENCE { header ItsPduHeaderVam, vam VruAwareness }
问题原因
WITH SUCCESSORS是ETSI在ASN.1中使用的扩展语法,用于表示导入的类型兼容后续版本的定义,但asn1c默认不支持该语法,因此编译时触发错误。
解决方法
方法一:启用asn1c的扩展支持
编译时添加--keep-with-successors参数,命令改为:asn1c --keep-with-successors VAM-PDU-Descriptions.asn该参数会让asn1c保留
WITH SUCCESSORS语法并正常编译。方法二:手动移除扩展语法
如果不需要兼容后续版本的类型定义,可以直接删除ASN.1文件中WITH SUCCESSORS这一行,注意保留末尾的分号,修改后的IMPORTS块结尾如下:FROM ETSI-ITS-CDD {itu-t (0) identified-organization (4) etsi (0) itsDomain (5) wg1 (1) 102894 cdd (2) major-version-3 (3) minor-version-1 (1) } ;
内容的提问来源于stack exchange,提问作者Alessandro
相关产品推荐
相关产品推荐

