0

I have to write a parser for some makefiles without variables and symbols (\$@, $< etc.), all they contain are Rules as :

Target: Dependencies

[tab] Commands

According to Makefile Grammar , the grammar of Makefile in general is context-sensitive which makes implementing a parser complicated. I tried to write the grammar of the simplified version (Fig below), but I'm not sure if it's correct and if it's context-free.

Fig : Grammar

I didn't detail C (commands) because the shell will parse it.

Tor Tor
  • 35
  • 6

1 Answers1

1

In the productions for 'n', 'b', and 'e', the '*' presumably means that each of them can derive epsilon (empty string), which is incorrect. (It means that a D could be followed by a C without a newline or tab or even a space intervening.)

Also, it's ambiguous, which doesn't necessarily mean it's incorrect for generating the language, but probably means it's incorrect for building a parser.

  • A production like T ::= TeT means that T derives TeTeT in 2 different ways (etc).
  • A production like n ::= n* means any derivation from n can involve arbitrarily many n -> n steps.
Michael Dyck
  • 2,153
  • 1
  • 14
  • 18