// File: /workspace/github_cpp_makefile_star2_O2/AndrewAlbert[P]Compiler-Theory/SourceCode/parser.cpp
// Function: Parser::ProgramBody()
bool Parser::ProgramBody(){
	bool resyncEnabled = true;
	bool procDec = false;
	string labelBegin = generator->newLabel("Begin_Program");
	//Get Procedure and Variable Declarations
	while(true){
		while( Declaration(procDec) ){
			if(procDec){
				if( !CheckToken(T_SEMICOLON) ) ReportWarning("expected ';' after procedure declaration in procedure");
			}
			else if( !CheckToken(T_SEMICOLON) ) ReportLineError("expected ';' after variable declaration in procedure", true);
		}
		if(CheckToken(T_BEGIN)){
			// GEN: Place label to procedure entry and set the Stack Pointer
			generator->placeLabel(labelBegin);
			generator->setSPfromFP( Scopes->getFrameSize() );
			//reset resync for statements
			resyncEnabled = false;
			while(true){
				//get all valid statements
				while( Statement() ){
					if( !CheckToken(T_SEMICOLON) ) ReportLineError("Expected ';' at end of statement in program body.", true);
				}
				//get program body's end
				if(CheckToken(T_END)){
					if( CheckToken(T_PROGRAM) ) return true;
					else ReportError("Expected 'end program' to close program execution.");
				}
				//use up resync attempt if parser can't find a statement or 'end'
				else if(resyncEnabled){
					resyncEnabled = false;
					ReportLineError("Bad line. Expected Statement or 'END' reserved keyword in program body.");
				}
				//if resync failed, report a fatal error
				else ReportFatalError("Parser resync failed. Could not find another valid statement or end of program.");
			}
		}
		//use up resync attempt if parser can't find a declaration or 'begin'
		else if(resyncEnabled){
			resyncEnabled = false;
			ReportLineError("Bad line. Expected Declaration or 'BEGIN' reserved keyword in program body.");
		}
		//if resync failed, report a fatal error
		else{
			ReportFatalError("Parser resync failed. Could not find another valid declaration or start of program execution.");
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rdi, %rbx
movb $0x0, 0x7(%rsp)
movq 0x98(%rdi), %r14
leaq 0xc470(%rip), %rsi      # 0x1142d
leaq 0x28(%rsp), %rdi
leaq 0x6(%rsp), %rdx
callq 0x36b8
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rdx
movq %r14, %rsi
callq 0xeaa4
leaq 0x28(%rsp), %rdi
callq 0x20f0
movb $0x1, %bpl
leaq 0x7(%rsp), %r14
leaq 0x128(%rsp), %r12
leaq 0x6(%rsp), %r13
leaq 0x108(%rsp), %r15
movq %rbx, %rdi
movq %r14, %rsi
callq 0x534e
testb %al, %al
je 0x5091
cmpb $0x1, 0x7(%rsp)
jne 0x5053
movq %rbx, %rdi
movl $0x12c, %esi            # imm = 0x12C
callq 0x49b0
testb %al, %al
jne 0x5005
movq %r12, %rdi
leaq 0xc405(%rip), %rsi      # 0x1143b
movq %r13, %rdx
callq 0x36b8
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4020
movq %r12, %rdi
callq 0x20f0
jmp 0x5005
movq %rbx, %rdi
movl $0x12c, %esi            # imm = 0x12C
callq 0x49b0
testb %al, %al
jne 0x5005
movq %r15, %rdi
leaq 0xc403(%rip), %rsi      # 0x11471
movq %r13, %rdx
callq 0x36b8
movq %rbx, %rdi
movq %r15, %rsi
pushq $0x1
popq %rdx
callq 0x444c
movq %r15, %rdi
callq 0x20f0
jmp 0x5005
movq %rbx, %rdi
movl $0x103, %esi            # imm = 0x103
callq 0x49b0
testb %al, %al
jne 0x50e3
testb $0x1, %bpl
je 0x5221
leaq 0xa8(%rsp), %rbp
movq %rbp, %rdi
leaq 0xc49d(%rip), %rsi      # 0x1155b
movq %r13, %rdx
callq 0x36b8
movq %rbx, %rdi
movq %rbp, %rsi
pushq $0x1
popq %rdx
callq 0x444c
movq %rbp, %rdi
callq 0x20f0
xorl %ebp, %ebp
jmp 0x5005
movq 0x98(%rbx), %r14
leaq 0x8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x2270
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0xeb7e
leaq 0x8(%rsp), %rdi
callq 0x20f0
movq 0x90(%rbx), %rdi
movq 0x98(%rbx), %r14
callq 0xb4d6
movq %r14, %rdi
movl %eax, %esi
callq 0xeece
leaq 0xe8(%rsp), %r15
leaq 0x6(%rsp), %r12
pushq $0x1
popq %rbp
leaq 0xc394(%rip), %r13      # 0x114d8
leaq 0xc8(%rsp), %r14
movq %rbx, %rdi
callq 0x557c
testb %al, %al
je 0x5192
movq %rbx, %rdi
movl $0x12c, %esi            # imm = 0x12C
callq 0x49b0
testb %al, %al
jne 0x514c
movq %r15, %rdi
leaq 0xc333(%rip), %rsi      # 0x114a6
movq %r12, %rdx
callq 0x36b8
movq %rbx, %rdi
movq %r15, %rsi
movl %ebp, %edx
callq 0x444c
movq %r15, %rdi
callq 0x20f0
jmp 0x514c
movq %rbx, %rdi
movl $0x104, %esi            # imm = 0x104
callq 0x49b0
testb %al, %al
je 0x51f8
movq %rbx, %rdi
movl $0x101, %esi            # imm = 0x101
callq 0x49b0
testb %al, %al
jne 0x51da
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x36b8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x47e0
movq %r14, %rdi
callq 0x20f0
jmp 0x514c
leaq 0x48(%rsp), %rdi
callq 0x20f0
movb $0x1, %al
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc30c(%rip), %rsi      # 0x1150b
leaq 0x88(%rsp), %rdi
leaq 0x6(%rsp), %rdx
callq 0x36b8
leaq 0x88(%rsp), %rsi
movq %rbx, %rdi
callq 0x4278
leaq 0xc37f(%rip), %rsi      # 0x115a7
leaq 0x68(%rsp), %rdi
leaq 0x6(%rsp), %rdx
callq 0x36b8
leaq 0x68(%rsp), %rsi
movq %rbx, %rdi
callq 0x4278
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
jmp 0x52cb
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
jmp 0x52de
movq %rax, %rbx
jmp 0x52e3
jmp 0x52d6
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
jmp 0x52cb
jmp 0x52d6
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
jmp 0x52cb
jmp 0x52d6
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
jmp 0x52cb
jmp 0x52d6
jmp 0x52d6
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
jmp 0x52cb
jmp 0x52d6
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
jmp 0x52cb
jmp 0x52d6
jmp 0x52d6
jmp 0x52d6
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
jmp 0x52cb
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x20f0
jmp 0x52d9
jmp 0x52d6
jmp 0x52d6
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x2310
nop