BNFC / bnfc

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

Invalid C++ is generated #125

Closed lovasoa closed 9 years ago

lovasoa commented 9 years ago

I have the following grammar:

comment "(*" "*)" ;

Prog.        Program   ::= [HeaderElem] [BodyElem] [FooterElem] ;

DefaultRate.   HeaderElem ::=  "directive" "default_rate" Number;
Stochasticity. HeaderElem ::=  "directive" "stochasticity_absorption" Integer;
Sample.        HeaderElem ::=  "directive" "sample" Number;
separator HeaderElem "";

InitState.     FooterElem ::= "initial_state" [Process];
separator FooterElem "";

SortDef.     BodyElem  ::= "process" ProcessName Integer ;

GenDyn.      BodyElem  ::= "GRN" "(" "[" [GRNAction] "]" ")" ;

Coop.        BodyElem ::= "COOPERATIVITY" "("
                              "[" [CoopName] "]" "->" Transition
                              ","
                              "[" [CoopCondition] "]" ")" ;

ActionElem. BodyElem  ::= Action Rate ;

KnockDown.  BodyElem ::= "KNOCKDOWN" "(" Process ")" ;

Remove.     BodyElem ::= "RM" "(" "{" [Action] "}" ")" ;

CoopNameDef. CoopName ::= ProcessName ;
separator CoopName ";" ;

CoopConditionDef. CoopCondition ::= "[" [CoopCondState] "]";
separator CoopCondition ";" ;
CoopCondStateDef. CoopCondState ::= Integer;
separator CoopCondState ";" ;

terminator BodyElem "" ;

ProcessDef.        Process      ::= ProcessName Integer ;
ActionDef.         Action       ::= Process "->" Transition ;
ProcessTransition. Transition   ::= ProcessName Integer Integer ;

separator Action  "," ;
separator Process "," ;

GRNActionDef.GRNAction ::= ProcessName Integer "->" Sign ProcessName ;
separator GRNAction ";" ;

NoRate.         Rate  ::= ;
InfRate.        Rate  ::= "@" "Inf" ;
FiniteRate.     Rate  ::= "@" Number ;
StochasticRate. Rate  ::= "@" Number "~" Integer ;

SimpleInt.      Number ::= Integer ;
FloatNum.       Number ::= Float ;
Inf.            Number ::= "Inf" ;

token ProcessName ((letter | '_') (letter | '_' | '\'')*) ;
token Float  (digit+ '.' digit*) ;
token Sign   ('+' | '-') ;

(For the pint .ph language)

I compile it with :

bnfc -m -cpp grammar.cf && make

And I get :

g++ -g -c Printer.C
Printer.C: In member function ‘virtual void PrintAbsyn::visitGRNActionDef(GRNActionDef*)’:
Printer.C:437:28: error: base operand of ‘->’ has non-pointer type ‘ProcessName {aka std::basic_string<char>}’
   _i_ = 0; p->processname_1->accept(this);
gdetrez commented 9 years ago

I think this is fixed in git but it'd be great if you can confirm it. If you don't want to build bnfc yourself, you can find binaries of the latest good commit at https://ci.zjyto.net/job/BNFC/job/ci-pipeline/.

gdetrez commented 9 years ago

Should be fixed. Feel free to re-open if you still have problems.