Grammar Testing

Tags:

#battle turing #compiling #custom programming language #grammar

By: Aaron Jencks

Views: 370
Posted on:

March 17, 2023, 1:46 a.m.

0 👍 0 👎

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

Comments

You are not logged in, please log in here to comment

Current Comments