0

identifier定义为:

identifier = /[A-zA-Z][A-zA-Z0-9_]*/ ;

并且arrayType作为:

arrayType = ARRAY LBRACK ~ typeList RBRACK OF componentType;

那么为什么 Tatsu 在下面的日志中决定 'ASCIIcode]' 是一个标识符而不是一个身份 + 右括号呢?

≡'[' 
ASCIIcode] Of ASCIIcode;
≡LBRACK↙arrayType↙unpackedStructuredType↙structuredType↙type↙ ~99:15
ASCIIcode] Of ASCIIcode;
↙typeList↙arrayType↙unpackedStructuredType↙structuredType↙type↙ ~99:15
ASCIIcode] Of ASCIIcode;
↙indexType↙typeList↙arrayType↙unpackedStructuredType↙structuredType↙type↙ ~99:15
ASCIIcode] Of ASCIIcode;
↙simpleType↙indexType↙typeList↙arrayType↙unpackedStructuredType↙ ~99:15
ASCIIcode] Of ASCIIcode;
↙scalarType↙simpleType↙indexType↙typeList↙arrayType↙ ~99:15
ASCIIcode] Of ASCIIcode;
↙LPAREN↙scalarType↙simpleType↙indexType↙typeList↙arrayType↙ ~99:15
ASCIIcode] Of ASCIIcode;
≢'(' 
ASCIIcode] Of ASCIIcode;
≢LPAREN↙scalarType↙simpleType↙indexType↙typeList↙arrayType↙ ~99:15
ASCIIcode] Of ASCIIcode;
≢scalarType↙simpleType↙indexType↙typeList↙arrayType↙ ~99:15
ASCIIcode] Of ASCIIcode;
↙subrangeType↙simpleType↙indexType↙typeList↙arrayType↙ ~99:15
ASCIIcode] Of ASCIIcode;
↙constant↙subrangeType↙simpleType↙indexType↙typeList↙arrayType↙ ~99:15
ASCIIcode] Of ASCIIcode;
↙unsignedNumber↙constant↙subrangeType↙simpleType↙indexType↙typeList↙ ~99:15
ASCIIcode] Of ASCIIcode;
↙unsignedInteger↙unsignedNumber↙constant↙subrangeType↙simpleType↙ ~99:15
ASCIIcode] Of ASCIIcode;
≢'' /\d+/
ASCIIcode] Of ASCIIcode;
↙unsignedReal↙unsignedNumber↙constant↙subrangeType↙simpleType↙indexType↙ ~99:15
ASCIIcode] Of ASCIIcode;
≢'' /\d+/
ASCIIcode] Of ASCIIcode;
≢unsignedNumber↙constant↙subrangeType↙simpleType↙indexType↙typeList↙ ~99:15
ASCIIcode] Of ASCIIcode;
↙sign↙constant↙subrangeType↙simpleType↙indexType↙typeList↙arrayType↙ ~99:15
ASCIIcode] Of ASCIIcode;
↙PLUS↙sign↙constant↙subrangeType↙simpleType↙indexType↙typeList↙arrayType↙ ~99:15
ASCIIcode] Of ASCIIcode;
≢'+' 
ASCIIcode] Of ASCIIcode;
≢PLUS↙sign↙constant↙subrangeType↙simpleType↙indexType↙typeList↙arrayType↙ ~99:15
ASCIIcode] Of ASCIIcode;
↙MINUS↙sign↙constant↙subrangeType↙simpleType↙indexType↙typeList↙ ~99:15
ASCIIcode] Of ASCIIcode;
≢'-' 
ASCIIcode] Of ASCIIcode;
≢MINUS↙sign↙constant↙subrangeType↙simpleType↙indexType↙typeList↙ ~99:15
ASCIIcode] Of ASCIIcode;
≢sign↙constant↙subrangeType↙simpleType↙indexType↙typeList↙arrayType↙ ~99:15
ASCIIcode] Of ASCIIcode;
↙identifier↙constant↙subrangeType↙simpleType↙indexType↙typeList↙ ~99:15
ASCIIcode] Of ASCIIcode;
≡'ASCIIcode]' /[A-zA-Z][A-zA-Z0-9_]*/
 Of ASCIIcode;
4

1 回答 1

2

正则表达式不正确,尊重您的意图(最好在https://pythex.org等网站上测试正则表达式)。

正则表达式在尝试定义小写字母范围时使用大写“A”。

您可以尝试使用:

identifier = /[a-zA-Z][a-zA-Z0-9_]*/ ;

甚至更好:

identifier = /\w[\w\d_]*/ ;
于 2021-03-26T12:15:33.413 回答