BNFC / bnfc

BNF Converter
http://bnfc.digitalgrammars.com/
588 stars 164 forks source link

Bool production #231

Open dmjio opened 6 years ago

dmjio commented 6 years ago

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;
andreasabel commented 6 years ago

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.

TheMaverickProgrammer commented 6 years ago

@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";
dmjio commented 6 years ago

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

andreasabel commented 5 years ago

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 commented 4 years ago

A more general solution is #267.