Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

YACC

Name: Anonymous 2011-12-13 21:24

I am trying to implement if/if else statements.

for example I want
if(a<b){ statement }
to print something like
"ifbegin a<b" + whatever statement prints + "ifend".

however for
if(a<b){statement1}else{statement2}
it should print
"ifelsebegin a<b" + whatever statement1 prints + " else " + ifelseend

is this possible? I tried the code below but ifelse and if are printed after the statements.

IF '(' expr ')' singlestatement ELSE singlestatement {printf("ifelse")} ;
|
IF '(' expr ')' singlestatement %prec IFX {printf("if")};

Name: Anonymous 2011-12-14 0:34

>>1
Because it's evaluating the singlestatements before these two rules, of course it'll print before (assuming you're just printf'ing in them). Have it propagate some value up to these two statements ($$ = ...), so you can do some shit with it, like as $5 and $7.

http://www.gnu.org/s/bison/manual/bison.html#Semantic-Actions

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List