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

Pages: 1-

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-13 21:28

These don't look like s-expressions.

Name: Anonymous 2011-12-13 22:15

Semantics Engineering with PLT Redex

Name: YAK 2011-12-13 22:50

YAK YAK?

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

Name: >>5 2011-12-14 0:34

and yes I realize that's for bison, but fucking close enough.

Name: Anonymous 2011-12-14 7:42

>>5
>>6
returning a value won't be enough. It has to call a function before and after singlestatements and these functions are different for if and if/else structures.

I kinda solved it, now statements write things into different buffers, and these buffers are printed in right order in if statement. however there are still problems with this approach.

Name: Anonymous 2011-12-17 2:41

Is there any real purpose to printing the crap? Or is it purely for ``debugging'' purposes?

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