help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What is wrong with this simple example?


From: Joel E. Denny
Subject: Re: What is wrong with this simple example?
Date: Sun, 20 Dec 2009 22:48:59 -0500 (EST)
User-agent: Alpine 1.00 (DEB 882 2007-12-20)

On Sun, 20 Dec 2009, Peng Yu wrote:

> I try to run the example on
> http://tldp.org/HOWTO/Lex-YACC-HOWTO-4.html. But I get the following
> error. Could somebody let me know what I am wrong?
> 
> $ bison -d example4.y
> example4.y:24.1-8: syntax error, unexpected identifier:
> $ cat example4.y
> %{
> #include <stdio.h>
> #include <string.h>
> 
> void yyerror(const char *str)
> {
>         fprintf(stderr,"error: %s\n",str);
> }
> 
> int yywrap()
> {
>         return 1;
> }
> 
> main()
> {
>         yyparse();
> }
> 
> %}
> 
> %token NUMBER TOKHEAT STATE TOKTARGET TOKTEMPERATURE

You need this here:

  %%

> commands: /* empty */
>         | commands command
>         ;
> 
> command:
>         heat_switch
>         |
>         target_set
>         ;
> 
> heat_switch:
>         TOKHEAT STATE
>         {
>                 printf("\tHeat turned on or off\n");
>         }
>         ;
> 
> target_set:
>         TOKTARGET TOKTEMPERATURE NUMBER
>         {
>                 printf("\tTemperature set\n");
>         }
>         ;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]