Is rust lexical grammar regular, context-sensitive, or context-sensitive?

The lexical grammar of most programming languages โ€‹โ€‹is not quite expressive to use quickly. I'm not sure what category the lexical grammar of rust belongs to. Most of them seem to be regular, perhaps with the exception of raw string literals :

let s = r##"Hi lovely "\" and "#", welcome to Rust"##;
println!("{}", s);

What prints:

Hi lovely "\" and "#", welcome to Rust

How can we add as much as we like #, it seems that it cannot be regular, right? But is grammar at least context-free? Or is there something non-contextual about the lexical grammar of rust?


Related: Is Rust's syntactic grammar free or context-sensitive?

+4
source share
1 answer

The raw string literal syntax is not contextual.

If you think this is a string surrounded by (using a superscript as the count operator), you can expect it to be contextual:r#k"โ€ฆ"#kk

raw_string_literal
   : 'r' delimited_quoted_string
delimited_quoted_string
   : quoted_string
   | '#' delimited_quoted_string '#'

But in fact, this is not the correct syntax, because it quoted_stringcannot contain , although it can contain for any"#k"#jj<k

- , ( ) k -repetition . ( , -, , - MathJax. , , ( ) , - .)

++ [ , , . 1], , (, Python Haskell), -. , , , . .

. - ', , . -, , , . , , ; -, . ( ++ ' : ++ , ' .)

, .. , 2..3 : 2 .. 3, 2. .3, , munch. , , . , , , DFA.

Postscript

, , " ". , , : " " "" . , , , . ( , FSA .)

. , , . , T U, , T, , U. ( ) :

a
a*b

, , a ( ), , a , a b ( ).

(, , Rust ), , .

  • , ++ (, , ), 16, 88 . , () , 13,082,362,351,752,551,144,309,757,252,761 , .
+7

Source: https://habr.com/ru/post/1675898/


All Articles