Good grammar for date data type for recursive descent parser LL(1)

Posted by Totophil on Stack Overflow See other posts from Stack Overflow or by Totophil
Published on 2010-03-17T12:30:37Z Indexed on 2010/03/17 12:31 UTC
Read the original article Hit count: 563

I'm building a custom expression parser and evaluator for production enviroment to provide a limited DSL to the users. The parser itself as the DSL, need to be simple. The parser is going to be built in an exotic language that doesn't support dynamic expression parsing nor has any parser generator tools available.

My decision is to go for recursive descent approach with LL(1) grammar, so that even programmers with no previous experience in evaluating expression could quickly learn how the code works.

It has to handle mixed expressions made up of several data types: decimals, percentages, strings and dates. And dates in the format of dd/mm/yyyy are easy to confuse with a string of devision ops.

Is where a good solution to this problem?

My own solution that is aimed at keeping the parser simple involves prefixing dates with a special symbol, let's say apostrophe:

<date>   ::= <apostr><digit><digit>/<digit><digit>/<digit><digit><digit><digit>

<apostr> ::= '

<digit>  ::= '0'..'9'

© Stack Overflow or respective owner

Related posts about parser

Related posts about expressionengine