public override List <string> ExecuteSemanticAction(Stack <SemanticRecord> semanticRecordTable, Stack <SymbolTable> symbolTable, IToken lastToken, MoonCodeResult moonCode)
        {
            SymbolTable currentTable = symbolTable.Peek();

            // Get the last created variable
            SemanticRecord variableRecord = semanticRecordTable.Pop();

            Entry variableEntry = new VarParamEntry(currentTable, variableRecord.getVariable(), EntryKinds.variable);

            // Only declare variables for functions (not class member variables)
            //if(currentTable.getParent() is FunctionEntry)
            {
                int    size    = variableRecord.getVariable().GetSize();
                string address = variableEntry.getAddress();

                if (size <= 0)
                {
                    moonCode.AddGlobal(string.Format("% {0} res 0", address));
                }
                else if (size == 4)
                {
                    moonCode.AddGlobal(string.Format("{0} dw 0", address));
                }
                else
                {
                    moonCode.AddGlobal(string.Format("{0} res {1}{2}align", address, size, Environment.NewLine));
                }
            }


            return(new List <string>());
        }
        public override List <string> ExecuteSemanticAction(Stack <SemanticRecord> semanticRecordTable, Stack <SymbolTable> symbolTable, IToken lastToken)
        {
            SymbolTable currentTable = symbolTable.Peek();

            // Get the last created variable
            SemanticRecord variableRecord = semanticRecordTable.Pop();

            Entry variableEntry = new VarParamEntry(currentTable, variableRecord.getVariable(), EntryKinds.variable);

            return(new List <string>());
        }
        public override List <string> ExecuteSemanticAction(Stack <SemanticRecord> semanticRecordTable, Stack <SymbolTable> symbolTable, IToken lastToken, MoonCodeResult moonCode)
        {
            SymbolTable currentTable = symbolTable.Peek();

            LinkedList <Variable> foundParameters = new LinkedList <Variable>();

            bool          entryCreated = false;
            string        funcName     = string.Empty;
            List <string> errors       = new List <string>();

            // Iterate over the semantic stack and consume records relevant to this function
            while (!entryCreated)
            {
                SemanticRecord topRecord = semanticRecordTable.Pop();

                // Handle the record depending on its type
                switch (topRecord.recordType)
                {
                case RecordTypes.Variable:
                    // Encountered paramenters
                    foundParameters.AddFirst(topRecord.getVariable());
                    break;

                case RecordTypes.IdName:
                    // The name of this function
                    funcName = topRecord.getValue();
                    break;

                case RecordTypes.TypeName:
                    // If we encounter a type we are done collecting and can create the entry
                    FunctionEntry funcEntry = new FunctionEntry(currentTable, funcName, topRecord.getType());
                    funcEntry.AddParameters(foundParameters);

                    // Push the function's scope to the stack of symbol tables
                    symbolTable.Push(funcEntry.getChild());

                    entryCreated = true;

                    break;

                default:
                    // This should only fail if there is an error in the grammar.
                    errors.Add("Grammar error, parsed rule that placed unexpected character on semantic stack");
                    break;
                }
            }

            return(errors);
        }