Question: Please provide code in C language. I need code for staticsemantic.c and staticsemantic.h Please provide code according to local option: You may process all variables
Please provide code in C language. I need code for staticsemantic.c and staticsemantic.h
Please provide code according to local option:
You may process all variables using local scope rules, or process variables before program as global and all other variables as local.
Software support
Implement a stack adapter according to the following
Stack item type is String or whatever was your identifier token instance the stack will process identifiers. You may also store line number or the entire token for more detailed error messaging
You can assume no more than items in a program and generate stack overflow if more
Interface
void pushString;
just push the argument on the stack
void popvoid;
just remove
int findString;
the exact interface may change, see below
find the first occurrence of the argument on the stack, starting from the top and going down to the bottom of the stack
return the distance from the TOS top of stack where the item was found if at TOS or if not found
Static semantics
Perform left to right traversal, and perform different actions depending on subtree and node visited
when working in before program, process the identifiers there as in the global option or process as local if desired using similar mechanism as below
when working in a or the of a func
set varCount for this block
in of this assume ID token v
when varCount call findv and errorexit if it returns nonnegative number varCount means that multiple definition in this block
pushv and varCount
when identifier token found in any nonvar node variable use
call findv if try STVverifyvif STV used for the global variables and error if still not found
when leaving the block, call pop varCount times note that varCount must be specific to each block
Stat Semantics Definition
The only static semantics we impose that can be processed by the compiler static are proper definition and use of variables.
Variable
A variable has to be defined before being used for the first time after satisfying syntax
create Identifier : Integer defines the variable named Identifier. We can assume that it will be initially set to the value in Integer.
Identifier showing up in any statement is the variable's use
Variable name can only be defined once in a scope but can possibly be reused in another scope.
Global option for all variables max
There is only one scope, the global scope, regardless of where a variable is defined.
Note that this option in P will likely force you to use the easier option in P resulting in about loss on P
Local option max
Variables defined before the tape keyword are considered in the global scope, those inside of any block or func are considered scoped in that block.
We will use the same scoping rules as in C a variable is for use in a scope if it is defined in this scope, any of its enclosing scopes, or the global scope static scoping rules except for one change. If two variables exist in the same scope, then it is an error. So if you had a global variable called "dog" and a local variable called "dog" this would be a problem.
This option here will allow you to use the full option in P or the easier one if you so choose.
Do not display the tree any more.
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
