locked
why empty is not equal "" ? RRS feed

  • Question

  • Hi,
    when I use this simple grammar:
     
            token Letter = "a".."z" | "A".."Z";
            token String = Letter+;
           
            syntax Main = p:Person("") => p;
           
            syntax Person(b) = b n:String => Person { Name => n };

    And give it an input "John", it does not work (Intellipad). When I change it to

            syntax Main = p:Person(empty ) => p;

    then it works ok. Why is that?
    contact: http://hidentity.org/hid/CZ123456
    Thursday, February 18, 2010 10:38 AM

Answers

  • I believe that empty, essentially, always matches (except EOF) where "" would never match? empty is especially useful for the last statement in an OR also like this:

    Bool(X) = X => true | empty => false;
    Thursday, February 18, 2010 6:39 PM