开发者

single, double quotes, or tokens?

Tutorials on writing yacc code online use single quotes for semicolons, and other characters:

';'  '+'  '-' (et开发者_如何学Cc)

however when using:

'<' or '>'

I got errors until I changed it to double quotes:

"<" or ">"

Similarly,

'>='  '=<'  '==' '!='

do not seem to be the same as

">="  "=<"  "==" "!="

How does yacc treat single quotes? double quotes? And when should tokens be used instead of putting stuff in quotes?

ie: '!=' vs "!=" vs TOKNOTEQUALS


You can use either ' or " around literals -- they're equivalent. HOWEVER, you can in general only put a single character between the quotes and get a sensible result -- a parser that accepts that single character token. Putting multiple characters in the quotes gives you a single token, but there's no way for your lexer to return that token, so its not useful.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜