title: How to use "literal string tokens" in Bison
body: <p>I am learning Flex/Bison. The manual of Bison says:</p>
  
  <blockquote>
    <p>A literal string token is written like a C string constant; for
    example, "&lt;=" is a literal string token. A literal string token
    doesn’t need to be declared unless you need to specify its semantic
    value data type</p>
  </blockquote>
  
  <p>But I do not figure how to use it and I do not find an example.</p>
  
  <p>I have the following code for testing:</p>
  
  <p><strong>example.l</strong></p>
  
  <pre><code>%option noyywrap nodefault
  
  %{
  #include "example.tab.h"
  %}
  
  %%
  
  [ \t\n] {;}
  [0-9] { return NUMBER; }
  . { return yytext[0]; }
  
  %%
  </code></pre>
  
  <p><strong>example.y</strong></p>
  
  <pre><code>%{
  #include &lt;stdio.h&gt;
  #define YYSTYPE char *
  %}
  
  %token NUMBER
  
  %%
  
  start: %empty | start tokens
  
  tokens:
         NUMBER "&lt;=" NUMBER { printf("&lt;="); }
       | NUMBER "=&gt;" NUMBER { printf("=&gt;\n"); }
       | NUMBER '&gt;' NUMBER { printf("&gt;\n"); }
       | NUMBER '&lt;' NUMBER { printf("&lt;\n"); }
  
  %%
  
  main(int argc, char **argv) {
     yyparse();
  }
  
  yyerror(char *s) {
     fprintf(stderr, "error: %s\n", s);
  }
  </code></pre>
  
  <p><strong>Makefile</strong></p>
  
  <pre><code>#!/usr/bin/make
  # by RAM
  
  all: example
  
  example.tab.c example.tab.h: example.y
      bison -d $&lt;
  
  lex.yy.c: example.l example.tab.h
      flex $&lt;
  
  example: lex.yy.c example.tab.c
      cc -o $@ example.tab.c lex.yy.c -lfl
  
  clean:
      rm -fr example.tab.c example.tab.h lex.yy.c example
  </code></pre>
  
  <p>And when I run it:</p>
  
  <pre><code>$ ./example 
  3&lt;4
  &lt;
  6&gt;9
  &gt;
  6=&gt;9
  error: syntax error
  </code></pre>
  
  <p>Any idea?</p>
  
  <hr>
  
  <p>UPDATE: I want to clarify that I know alternative ways to solve it, but I want to use <strong>literal string tokens</strong>.</p>
  
  <p>One Alternative: using multiple "literal character tokens":</p>
  
  <pre><code>tokens:
         NUMBER '&lt;' '=' NUMBER { printf("&lt;="); }
       | NUMBER '=' '&gt;' NUMBER { printf("=&gt;\n"); }
       | NUMBER '&gt;' NUMBER { printf("&gt;\n"); }
       | NUMBER '&lt;' NUMBER { printf("&lt;\n"); }
  </code></pre>
  
  <p>When I run it:</p>
  
  <pre><code>$ ./example 
  3&lt;=9
  &lt;=
  </code></pre>
  
  <p>Other alternative:</p>
  
  <p>In <strong>example.l</strong>:</p>
  
  <pre><code>"&lt;="  { return LE; }
  "=&gt;"  { return GE; }
  </code></pre>
  
  <p>In <strong>example.y</strong>:</p>
  
  <pre><code>...
  %token NUMBER
  %token LE "&lt;="
  %token GE "=&gt;"
  
  %%
  
  start: %empty | start tokens
  
  tokens:
         NUMBER "&lt;=" NUMBER { printf("&lt;="); }
       | NUMBER "=&gt;" NUMBER { printf("=&gt;\n"); }
       | NUMBER '&gt;' NUMBER { printf("&gt;\n"); }
       | NUMBER '&lt;' NUMBER { printf("&lt;\n"); }
  ...
  </code></pre>
  
  <p>When I run it:</p>
  
  <pre><code>$ ./example 
  3&lt;=4
  &lt;=
  </code></pre>
  
  <p>But the manual says: </p>
  
  <blockquote>
    <p>A literal string token doesn’t need to be declared unless you need to
    specify its semantic value data type</p>
  </blockquote>