Single, double quotes or tokens?

Yacc code writing tutorials online use single quotes for semicolons and other characters:

';' '+' '-' (etc) 

however when using:

 '<' or '>' 

I got errors until I changed it to double quotes:

 "<" or ">" 

Similarly

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

don't seem to match

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

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

 ie: '!=' vs "!=" vs TOKNOTEQUALS 
+4
source share
1 answer

You can use ' or " around literals - they are equivalent. HOWEVER, you can, in general, put only one character between quotation marks and get a reasonable result - a parser that takes this single character token. Putting multiple characters in quotation marks gives you one token, but for your lexer there is no way to return this token, so it is not useful.

+2
source

All Articles