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;
 }
Esempio n. 2
0
        //<Num Term> ::= <Num Term> '*' <Num Unary>
        //            |  <Num Term> '/' <Num Unary>
        //            |  <Num Unary>
        private ASTNode GetNumTerm(string scaleName, NumericType numType)
        {
            ASTNode lhs = GetNumUnary(scaleName, numType);

            if (lhs == null)
            {
                return(null);
            }

            while ((m_symbol == Lexer.Symbol.Times) || (m_symbol == Lexer.Symbol.Div))
            {
                Lexer.Symbol operation = m_symbol;
                GetToken();

                ASTNode rhs = GetNumUnary(scaleName, numType);
                if (rhs == null)
                {
                    return(null);
                }
                else if (operation == Lexer.Symbol.Times)
                {
                    lhs = new ASTProduct(lhs, rhs);
                }
                else
                {
                    lhs = new ASTQuotient(lhs, rhs);
                }
            }
            return(lhs);
        }
Esempio n. 3
0
        //<Num Expr> ::= <Num Expr> '+' <Num Term>
        //            |  <Num Expr> '-' <Num Term>
        //            |  <Num Term>
        private ASTNode GetNumExpr(string scaleName, NumericType numType)
        {
            ASTNode lhs = GetNumTerm(scaleName, numType);

            if (lhs == null)
            {
                return(null);
            }

            while ((m_symbol == Lexer.Symbol.Plus) || (m_symbol == Lexer.Symbol.Minus))
            {
                Lexer.Symbol operation = m_symbol;

                GetToken();

                ASTNode rhs = GetNumTerm(scaleName, numType);
                if (rhs == null)
                {
                    return(null);
                }
                else if (operation == Lexer.Symbol.Plus)
                {
                    lhs = new ASTSum(lhs, rhs);
                }
                else
                {
                    lhs = new ASTDifference(lhs, rhs);
                }
            }
            return(lhs);
        }
        //<Dim Term> ::= <Dim Term> '*' <Dim Factor>
        //            |  <Dim Term> '^' <Dim Factor>
        //            |  <Dim Term> '/' <Dim Factor>
        //            |  <Dim Factor>
        private ASTNode GetDimTerm(UnitType candidate, NumericType numType)
        {
            ASTNode lhs = GetDimFactor(candidate, numType);

            if (lhs == null)
            {
                return(null);
            }

            while ((m_symbol == Lexer.Symbol.Times) || (m_symbol == Lexer.Symbol.Div) || (m_symbol == Lexer.Symbol.Wedge))
            {
                Lexer.Symbol operatorSymbol = m_symbol;
                string       operatorToken  = m_token;
                int          operatorLine   = m_lexer.TokenLine;
                int          operatorColumn = m_lexer.TokenColumn;

                GetToken();

                ASTNode rhs = GetDimFactor(candidate, numType);
                if (rhs == null)
                {
                    return(null);
                }

                else if (operatorSymbol == Lexer.Symbol.Div)
                {
                    lhs = new ASTQuotient(lhs, rhs);
                }

                else if (operatorSymbol == Lexer.Symbol.Times)
                {
                    lhs = new ASTProduct(lhs, rhs, iswedgeproduct: false);
                }

                else if (lhs.IsWedgeCompatible && rhs.IsWedgeCompatible)
                {
                    lhs = new ASTProduct(lhs, rhs, iswedgeproduct: true);
                }

                else
                {
                    string denote = "\u02C7\u02C7\u02C7{0}\u02C7\u02C7\u02C7";   //  ˇˇˇexprˇˇˇ
                    Note(operatorLine, operatorColumn, operatorToken,
                         String.Format("{0}: wedge product incompatible factor(s): {1} ^ {2}.", candidate.Name,
                                       lhs.IsWedgeCompatible ? lhs.ToString() : String.Format(denote, lhs),
                                       rhs.IsWedgeCompatible ? rhs.ToString() : String.Format(denote, rhs)
                                       )
                         );
                    return(null);
                }
            }
            return(lhs);
        }
 public constantType(string lex, Lexer.Symbol token, int dpth, VarType vt, int?val = null, double?valR = null) : base(lex, token, dpth)
 {
     TypeOfConstant = vt;
     Offset         = findOffset();
     if (val != null)
     {
         Value = val;
     }
     else if (valR != null)
     {
         ValueR = valR;
     }
     else
     {
         Console.WriteLine("Error! Values are null.");
     }
 }
Esempio n. 6
0
 private Lexer.Symbol GetToken()
 {
     m_symbol = m_lexer.GetToken();
     m_token  = m_lexer.TokenText;
     return(m_symbol);
 }
 public functionType(string lex, Lexer.Symbol token, int dpth, VarType returnType, LinkedList <parameterType> parameters) : base(lex, token, dpth)
 {
     ReturnType         = returnType;
     NumberOfParameters = parameters?.Count;
     SizeOfLocal        = SizeOfParameters(parameters);
 }
 public varType(string lex, Lexer.Symbol token, int dpth, VarType varT, int off) : base(lex, token, dpth)
 {
     TypeOfVariable = varT;
     Offset         = off + getSize(varT);
     size           = getSize(varT);
 }
 public varType(string lex, Lexer.Symbol token, int dpth) : base(lex, token, dpth)
 {
 }
Esempio n. 10
0
 public symTableRecord(string lex, Lexer.Symbol token, int dpth)
 {
     Lexeme = lex;
     depth  = dpth;
     Token  = token;
 }
Esempio n. 11
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;
                }
            }
        }