Beispiel #1
0
 /// <summary>
 /// Looks for a function in a FuncTable.
 /// Raises Exception if func is not found.
 /// </summary>
 /// <param name="sexpr"></param>
 /// <returns></returns>
 private Function FindFunction(ParsedSExpr sexpr)
 {
     if (sexpr.Members[0].ParsedValueType == ParsedValuesTypes.PARSEDIDENTIFIER)
     {
         string funcName = (sexpr.Members[0] as ParsedIdentifier).Name;
         if (FuncDefs.ContainsKey(funcName))
             return FuncDefs[funcName];
         throw new Exception("CG.FindFunction: Unknown symbol " + funcName + "!");
     }
     else
         throw new Exception("CG.FindFunction: Not a function call!");
 }
        /// <summary>
        /// Recursively gets function call arguments types list.
        /// </summary>
        /// <param name="sexpr"></param>
        /// <returns></returns>
        private List<VarType> GetFuncCallArguments(ParsedSExpr sexpr)
        {
            List<VarType> result = new List<VarType>();

            foreach (IParsedValue val in sexpr.Members)
            {
                switch (val.ParsedValueType)
                {
                    case ParsedValuesTypes.PARSEDCHARCONST:
                        result.Add(VarType.Char);
                        break;
                    case ParsedValuesTypes.PARSEDIDENTIFIER:
                        result.Add(VarType.Any);
                        break;
                    case ParsedValuesTypes.PARSEDINTEGERCONST:
                        result.Add(VarType.Integer);
                        break;
                    case ParsedValuesTypes.PARSEDSEXPR:
                        result.Add(FindFunction(val as ParsedSExpr).RetType);
                        break;
                    case ParsedValuesTypes.PARSEDSTRINGCONST:
                        result.Add(VarType.String);
                        break;
                    default:
                        break;
                }
            }

            // remove function name
            result.RemoveAt(0);

            return result;
        }