Question: reorganize this source code / * * * * * * Header definitions * * * * * * / % { #include #include #include
reorganize this source code Header definitions
#include #include #include function prototypes from lex int yyerrorchar s; int yylexvoid; addString func added int addStringchar str; int debug; set to to turn on extra printing Not used in this code, but this can be used in Compiler to save the constant strings that need output in thedata section of the assembly output char savedStrings; int lastStringIndex; void outputDataSec; token value data types union int ival; char str; Starting nonterminal start wholeprogramtype program functions function statements statement funcall arguments argument expression Token types token KWPROGRAM KWCALL ID STRING KWFUNCTION token LBRACE RBRACE SEMICOLON LPAREN RPAREN COMMA NUMBER token PLUS Rules wholeprogram: functions program int argRegNum ; if debug fprintfstderr"wholeprogram rule
; printf#
# RISCV assembly output
#
; outputDataSec; printf#
# Program instructions
#
ttext
program:
s$; printftlita
tlita
tecall
; printf#
# Functions
#
s
$; printf#
# Library functions
#
; printf# Print a nullterminated string: arg: a string address
printStr:
tlita
tecall
tret
; printf# Print a decimal integer: arg: a value
printInt:
tlita
tecall
tret
; program: KWPROGRAM LBRACE statements RBRACE if debug printfyacc: program block
; $$ "program block parsed"; $$ strdup$; functions: function functions if debug printfyacc: multiple functions
; char code char mallocstrlen$ strlen$; strcpycode $; strcatcode $; $$ code; empty if debug printfyacc: no functions
; $$ strdup; function: KWFUNCTION ID LPAREN RPAREN LBRACE statements RBRACE if debug printfyacc: function definition
; char code char mallocstrlen$; Assembly code for function sprintfcodes:
stret
$ $; $$ code; statements: statement statementsif debug printfyacc: multiple statements
; join both statements space for both statements char code char mallocstrlen$ strlen$; strcpycode $; strcatcode $; $$ code; emptyif debug printfyacc: no statements
; $$ strdup; statement: funcall if debug printfyacc: function call
; $$ $; funcall: KWCALL ID LPAREN arguments RPAREN SEMICOLON if debug printffunction call!
; if debug fprintfstderr "function call rule
; char code char mallocstrlen$strlen$; bytes of assembly code sprintfcodestjalts
$$; RISCV instruction $$ code; argRegNum ; arguments: empty $$
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
