0

Hello,

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?


thanks,

2
Contributors
1
Reply
4
Views
5 Years
Discussion Span
Last Post by L7Sqr
0

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");
}

Then

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

Hope that helps

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.