Search code examples
parsingsyntaxebnf

How does a parser for the infix notation detect the missing multiplication sign?


I am writing a parser that parses mathematical expressions based on a syntax diagram very similar to this one.

I have not found a way to handle a missing multiplication sign (for example in 3(x+y)). Where in the syntax diagram do I have to handle this?


Solution

  • You'd make the * optional in the definition of term.

    ASCII diagram:

    o-->-->--[factor]->-->--o
        /               \
        \               /
         ---<--[*]--<---
             \     /
              --<--