开发者

Can I use double quotes string in yacc?

开发者 https://www.devze.com 2023-03-26 19:09 出处:网络
So far I only see stuff like \'<\' ,but never see \'abc\' nor \"abc\" in a yacc file. a: b \'<\'开发者_如何学JAVA c;

So far I only see stuff like '<' ,but never see 'abc' nor "abc" in a yacc file.

a:
  b '<'开发者_如何学JAVA c;

Are the later two valid at all?


'abc' = is valid character since whenever you specify char like this compiler/preprocessor simply remove last character , sometimes you would get "character constants must be one or two character long" compile time error in ANSI C.If it is not given by your compiler then it has removed last 'c' from 'abc' should be assumed.

so char ch='abc' ; // is actually equi. to ch = 'ab'

but while binding it will only use ch='a' ,that's why 'abc' is syntaxically correct but symantically wrong characher.(I wrote C coz. we use c89 tool i.e. POSIX C for compiling yacc and lex inputs)

Again yylex() works on characters as basic functional unit and not string (anything inside double quotes). So "abc" is not valid character not even character to match with yylex()'s input. (yylex() accepts string of token exam. "10+20" having grammer [[:DIGIT:]]+ [-+*/%] [[:DIGIT:]]+
and having tokens 1,0,+,2,0
The tokens lex can identify by default w/o specifying grammer are 10 as number + as char and 20 as number again so it will match with grammer specified before )

you can also specify string in rules section for matching with , like ^["I am"] means match with any input line starting with "I am" "I am" match with only input having string as "I am" only , It wont match with "I am Swapnil @ vikas.ghode@gmail.com"

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号