While working on the grammar parser for Battle Turing I needed to come up with a small test case that I could use to verify the code generation portion of the compiler, here is the test case I came up with
min_code = '''
if(= ^ 'a') {
left;
}
while(= ^ 'a') {
write 'b';
right;
}
halt;
'''
It encases some of the complexities of flow control, while still being small enough that I could step through it completely. I also generated the parse tree in classic ascii art format:
# Parse Tree
#
#
# S
# / \
# | S
# | / \
# F F |
# | | |
# R R |
# / | \ / | \ |
# | H | | H T |
# | / | \ | | / | \ / | \ |
# | | X | M | | X | | S | |
# | | / \ | / | \ | | / \ | | / | \ | |
# | | | Y | | P | | | | Y | | | | S | S
# | | | / \ | | / \ | | | | / \ | | E | / \ | / \
# | | O N N | | E | | | | O N N | | / \ | E | | E |
# | | | | | | | | | | | | | | | | | | | | | | | | |
# if ( = ^ 'a' ) { left ; } while ( = ^ 'a' ) { write 'b' ; right ; } halt ;
I think this will be very helpful in the upcoming days
You are not logged in, please log in here to comment