[erlang-questions] Re: sending extra information to leex or yecc? (or how to know the name of the file I'm parsing in them)

Mariano Guerra <>
Sun Jun 6 19:42:34 CEST 2010


On Sun, Jun 6, 2010 at 11:54 AM, Robert Virding <> wrote:
> Do you mean the name of the source files used to generate a leex
> scanner or a yecc parser? Or do you mean the name of a file scanned by
> a leex scanner or parsed by a yecc parser?
>
> For a description of how a scanner/parser is integrated into the i/o
> system check out the i/o part of the Erlang Rationale found at:
>
> http://forum.trapexit.org/viewtopic.php?t=15022
>
> In short neither know who calls them. When generating a scanner/parser
> there is no direct way to get the source file names, indirectly the
> source name is used to generate the module and file name of the
> resultant scanner/parser.
>
> What is that you want to do?

I had to replace some macro variables in my language[1] and needed to
know the name of the file that I was parsing to replace $module
$module_string and $file, what I did whas to spawn a process, register
it with a name[2] and before starting the parsing I stored the
information in the process[3], then from yecc I request the
information sending a message[4]

if there is a better way to do it I would like to know how, if there
is some observations on how I did it it would be nice too :)

[1] http://github.com/marianoguerra/efene
[2] http://github.com/marianoguerra/efene/blob/0181fcecb2f0e430b2c5ac13b2652070ddb5476f/src/fn_server.erl#L4
[3] http://github.com/marianoguerra/efene/blob/0181fcecb2f0e430b2c5ac13b2652070ddb5476f/src/fn.erl#L287
[4] http://github.com/marianoguerra/efene/blob/0181fcecb2f0e430b2c5ac13b2652070ddb5476f/src/fn_parser.yrl#L266


More information about the erlang-questions mailing list