Пример #1
0
 public constantType(string lex, Lexer.Symbol token, int dpth, constantType cd) : base(lex, token, dpth)
 {
     Value          = cd.Value;
     ValueR         = cd.ValueR;
     Offset         = cd.Offset;
     TypeOfConstant = cd.TypeOfConstant;
 }
Пример #2
0
        //inserts into symbol table after going through checks
        public void insert(string lex, Lexer.Symbol token, int dpth, EntryType et, VarType vt, LinkedList <parameterType> p = null, constantType c = null)
        {
            int  key   = hash(lex);
            bool found = false;

            foreach (var i in symTable)
            {
                if (i != null)
                {
                    foreach (var j in i)
                    {
                        if (j.Lexeme == lex && j.depth == dpth)
                        {
                            found = true;
                        }
                    }
                }
            }

            if (found)
            {
                Console.WriteLine($"Error Found: {lex} already exits at depth: {dpth}");
                Console.ReadLine();
                Environment.Exit(0);
            }
            else
            {
                if (symTable[key] == null)
                {
                    symTable[key] = new LinkedList <symTableRecord>();
                }
                switch (et)
                {
                case EntryType.varEntry:
                    symTable[key].AddFirst(new varType(lex, token, dpth, vt, calcVarOffset(dpth)));
                    break;

                case EntryType.constEntry:
                    symTable[key].AddFirst(new constantType(lex, token, dpth, c));
                    break;

                case EntryType.functionEntry:
                    symTable[key].AddFirst(new functionType(lex, token, dpth, vt, p));
                    break;

                case EntryType.parameterEntry:
                    int totalOffset = 0;
                    for (int i = 0; i < TableSize; i++)
                    {
                        if (symTable[i] != null)
                        {
                            var TsymTable = new LinkedList <symTableRecord>(symTable[i]);
                            foreach (parameterType item in TsymTable.OfType <parameterType>())
                            {
                                if (item.depth == dpth)
                                {
                                    totalOffset = item.Size + totalOffset;
                                }
                            }
                        }
                    }
                    symTable[key].AddFirst(new parameterType(lex, dpth, vt, totalOffset));
                    break;
                }
            }
        }