bnfc icon indicating copy to clipboard operation
bnfc copied to clipboard

Bool production

Open dmjio opened this issue 7 years ago • 5 comments

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;

dmjio avatar Jun 24 '18 21:06 dmjio

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.

andreasabel avatar Jun 24 '18 21:06 andreasabel

@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 avatar Aug 28 '18 18:08 TheMaverickProgrammer

@TheMaverickProgrammer, thanks, I ended up just going with alex and happy since I can lex directly into a Bool.

dmjio avatar Aug 28 '18 19:08 dmjio

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).

andreasabel avatar Oct 24 '19 09:10 andreasabel

A more general solution is #267.

andreasabel avatar Oct 29 '20 15:10 andreasabel