1
votes

I'm getting started with Bison/YACC and Flex/Lex, but I cannot compile the simplest of parsers.

File: Ruby.y

%{ 
#include <stdio.h>
#include <stdlib.h> 
%}

%start program
%token NUMBER

%%

program : NUMBER;

%%

main( int argc, char* argv[] ) {
    yyparse();
} 

yyerror(char *s){
    printf("%s\n", s);
}

File: Ruby.l

%{
#define "Ruby.tab.h"
%}
DIGIT   [0-9]
%%
{DIGIT}+    { return(NUMBER);           }
[ \t\n]+
.           { return(yytext[0]);        }
%%

I compiled Ruby.y using "Bison -vd Ruby.y", then "Flex Ruby.l" and then tried to compile the whole thing using GCC with "GCC -c Ruby.tab.c" and "GCC -c lex.yy.c" but I get the following error on the latter:

Ruby.l:2:9: error: macro names must be identifiers Ruby.l: In function 'yylex': Ruby.l:6:10: error: 'NUMBER' undeclared (first use in this function) Ruby.l:6:10: note: each undeclared identifier is reported only once for each fun ction it appears in

I am clueless, any idea?

Thank you.

1

1 Answers

0
votes

In the Ruby.l file this:

%{
#define "Ruby.tab.h"
%}

should be:

%{
#include "Ruby.tab.h"
%}