flex & YACC question

This is a discussion on flex & YACC question within the Tech Board forums, part of the Community Boards category; I'm following this: http://www.telenovela-world.com/~spa...C-HOWTO-4.html since I've always fancied writing my own programming language. I was hoping flex and yacc would ...

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    flex & YACC question

    I'm following this: http://www.telenovela-world.com/~spa...C-HOWTO-4.html since I've always fancied writing my own programming language. I was hoping flex and yacc would relieve some stress... yeah right.

    This grammar:

    Code:
    %{
    #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 TOKTEMP
    
    commands:
            | commands command
            ;
    
    command:
            heat_switch
            |
            target_set
            ;
    
    heat_switch:
            TOKHEAT STATE
            {
                    printf("\tHeat turned on or off\n");
            }
            ;
    
    target_set:
            TOKTARGET TOKTEMP NUMBER
            {
                    printf("\tTemperature set\n");
            }
            ;
    Doesn't compile:

    [lee@localhost c_cpp]$ yacc -d thermo.y
    yacc: e - line 24 of "thermo.y", syntax error
    commands:
    ^
    I was hoping somebody here might be able to help me - not sure how much this is used though.

    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  2. #2
    Dump Truck Internet valis's Avatar
    Join Date
    Jul 2005
    Posts
    357
    remember it's:
    Code:
    declarations
    %%
    rules
    %%
    programs
    so try a %% after your tokens

    Also I suggest writing something by hand, it makes it a lot easier since you have a solid understanding of what is going on.
    Last edited by valis; 03-22-2006 at 05:18 PM.

  3. #3
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Cheers valis, I'll probably write my own one day
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 03:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 06:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 01:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21