BNFC is not parsing individual functions

33 Views Asked by At

I have the following BNFC code:

GFDefC. GoalForm ::= Constraint ;
GFDefT. GoalForm ::= True ;
GFDefA. GoalForm ::= GoalForm "," GoalForm ;
GFDefO. GoalForm ::= GoalForm ";" GoalForm ;

ConFr. Constraint ::= Var "#" Term ;

TVar. Term ::= UnVar;
TFun. Term ::= Fun ;

FDef. Fun  ::= FunId "(" [Arg] ")" ;
ADecl. Arg ::= Term ;
separator Arg "," ;

...

However, the following is not parsed

fun(X)

while it parses the one below

x # fun(Y)

so to sum up, it parses the function as a part of constraints, but not individually. It should parse both of them.

Could anyone point out why?

1

There are 1 best solutions below

0
ice1000 On

You should set your entrypoints properly.

As you're parsing x # fun(Y) successfully, I assume you have set your entrypoints to Constraint and using the generated pConstraint function to parse your expressions. Then, you can change your rules of Constraint to

ConNoVar. Constraint ::= Term ;
ConFr.    Constraint ::= Var "#" Term ;

Aternatively, you can add Term to your entrypoints and invoke pTerm to parse your function terms.