function file/2 undefined in generated code from Erlang's yecc

30 views Asked by At

When using Erlang's yecc to generate a parser from a grammar definition, my file compiled successfully with yecc:file/1, but the generated code wouldn't compile, with the following error:

src/parse.yrl:364:2: function file/2 undefined

I searched for file in the generated code, but found only module attributes -file(...) over and over again.

1

There are 1 answers

0
Sam Weaver On

This was caused by me failing to include a period . at the end of a function defined in the Erlang code. section of my .yrl file. It seems that the code compiles fine from yecc, but the lack of a period on the end of a function definition meant that the -file(...) annotation was being treated like a function call after a minus - sign.

The generated code looked like this:

function(A, B, C) ->
    {A, B, C}
-file("path/to/file", 0)

After adding the period to the end of the function in the .yrl file, the code compiled successfully.