0
votes

I've been working on implementing logic programming language using BNFC. The problem I'm having is related to the typing rules. In "Implementing Programming Languages" book by A.Ranta the types are included in the LBNF syntax as in

Tbool. Type ::= "bool" ;
Tdouble. Type ::= "double" ;
Tstring. Type ::= "string";

I understand that for grammars like in C it's important to add types, as they're integral in declarations and therefore need to be parsed by front-end. Further in the book the type checker is written in Haskell or Java. However in logic PL the types aren't so explicit, they are declared separately, the example syntax of types is encoded as :

tid: name_type
ty: type
varTy: tid -> ty
arrTy: ty x ty -> ty

So the question is where in the code does the syntax of types go? Whenever I try to add the types in BNFC it just doesn't make much sense, and the tested input doesn't parse properly. The book has a good example of the C grammar, but doesn't provide a complete picture of how front-end created by BNFC and the type checker are connected, how the information is passed from one to another, etc.

1

1 Answers

1
votes

I'm not familiar with BNFC, but from what I can see it's just some kind of compiler compiler specification.

So the question is where in the code does the syntax of types go?

The classic way is not to handle type checking at syntax level, but rather at semantic level. Or if your language is an interpreted one, at runtime, during interpretation.