bnfc
bnfc copied to clipboard
Bool production
This might be a huge oversight on my part. I noticed there are terminals for String, Integer, Double, etc. I was wondering if there was one for Bool. My current LBNF has rules in this form (see below), but since Bool wasn't present I had to define my own. Would it be hard to add Bool ?
StringValue . Value ::= String;
IntValue . Value ::= Integer;
BoolValue . Value ::= GBool;
FloatValue . Value ::= Double;
I think it would not be hard. However, it is quite easy to roll your own Bool, thus it is not so urgent. In contrast, the other literals are very common across languages and not all trivial to define yourself.
@dmjio I've written a scripting language with bnfc and booleans are just a string literal e.g.
DefVarBool. EVarType ::= EBool;
DefVarString. EVarType ::= String;
DefVarInt. EVarType ::= Integer;
DefVarId. EVarType ::= Ident;
...
DefBoolT. EBool ::= "true";
DefBoolF. EBool ::= "false";
@TheMaverickProgrammer, thanks, I ended up just going with alex and happy since I can lex directly into a Bool.
I think we could make Bool a predefined category and use True and False for the rule names. The user then writes:
True. Bool := "true";
False. Bool := "false";
or whatever concrete syntax they want for the truth values.
This is similar to how lists are treated (using Haskell's names for the list constructors).
A more general solution is #267.