I'm doing a project for my Compilers course and I stuck up on this.
my project is little, it's a program that allows entering a mathematical equation and identifies and outputs the equations type to the user.

I wrote the grammars for it and used Flex to generate a lexical analyzer for it.

My problem is, how can I use the generator's file lex.yy.c( i.e., pass an input string and get the generated tokens) without using the Yacc/Bison tool.

I was thinking of creating a little console application that does that but I was lost and didn't know what to do.

Can somebody please help me on this?


You can place code to be executed in your lex source file and provide an implementation during compile time. A short example:

------ ex.l ------
a { foo (); }
int main () {
   yylex ();
   return 0;

------ ex.c ------
#include <stdio.h>

void foo () {
   printf ("\nfoo called\n");


$ lex ex.l
$ gcc lex.yy.c ex.c -lfl
$ ./a.out
foo called

Hope that helps