Beispiel #1
0
        public override List <string> ExecuteSemanticAction(Stack <SemanticRecord> semanticRecordTable, Stack <SymbolTable> symbolTable, IToken lastToken)
        {
            Variable      variable = new Variable();
            List <string> errors   = new List <string>();

            while (semanticRecordTable.Peek().recordType == RecordTypes.IdName ||
                   semanticRecordTable.Peek().recordType == RecordTypes.TypeName ||
                   semanticRecordTable.Peek().recordType == RecordTypes.Size)
            {
                SemanticRecord topRecord = semanticRecordTable.Pop();
                switch (topRecord.recordType)
                {
                case RecordTypes.Size:
                    variable.AddDimension(int.Parse(topRecord.getValue()));
                    break;

                case RecordTypes.IdName:
                    variable.SetName(topRecord.getValue());
                    break;

                case RecordTypes.TypeName:
                    variable.SetType(topRecord.getType());
                    SemanticRecord variableRecord = new SemanticRecord(variable);
                    semanticRecordTable.Push(variableRecord);
                    break;

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

            return(errors);
        }