예제 #1
0
        ////*******************************************************************************************
        ////***  FUNCTION ParseExpresionFile
        ////*** ***************************************************************************************
        ////***  DESCRIPTION  :  Parses the Expresion File
        ////***  INPUT ARGS   :  SymbolTable symbolTable, LiteralTable literalTable, string filePath
        ////***  OUTPUT ARGS :  N/A
        ////***  IN/OUT ARGS   :  N/A
        ////***  RETURN :  N/A
        ////*******************************************************************************************
        //public static void ParseExpresionFile(SymbolTable symbolTable, LiteralTable literalTable, string filePath)
        //{
        //    try
        //    {
        //        using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.SequentialScan))
        //        {

        //            try
        //            {
        //                using (StreamReader streamReader = new StreamReader(fileStream))
        //                {
        //                    int LineNumber = 1;
        //                    Chronicler.WriteLine("EXPRESION\tVALUE\tRELOCATABLE\tN-Bit\tI-Bit\tX-Bit");
        //                    while (!streamReader.EndOfStream)
        //                    {
        //                        //get the line and trim whitespace
        //                        string currentLine = streamReader.ReadLine().Trim();
        //                        if (ResolveF3F4Expresion(symbolTable, literalTable, currentLine, currentLine, out Globals.Symbol? symbol))
        //                        {
        //                            if (symbol != null)
        //                            {
        //                                StringBuilder sb = new StringBuilder("");
        //                                for (int x = 0; x < (16 - currentLine.Length); x++)
        //                                {
        //                                    sb.Append(" ");
        //                                }
        //                                Chronicler.Write(currentLine + sb.ToString());
        //                                Chronicler.Write(symbol.Value.value.ToString());
        //                                Chronicler.Write("\t" + ((symbol.Value.RFlag) ? "RELOCATABLE" : "ABSOLUTE"));
        //                                Chronicler.NewLine();
        //                            }
        //                        }
        //                        else
        //                        {
        //                            Chronicler.LogError("Line: \"" + LineNumber + "\" Skipping: \"" + currentLine + "\"", "Expresion File Parsing");
        //                        }
        //                        LineNumber++;
        //                    }
        //                    Chronicler.LogInfo("DONE loading symbols!");
        //                }
        //            }
        //            catch (IOException e)
        //            {
        //                Chronicler.WriteLine(e.Message);
        //                Chronicler.LogError("failed to open File: " + filePath);
        //            }
        //        }
        //    }
        //    catch (IOException e)
        //    {
        //        Chronicler.WriteLine(e.Message);
        //        Chronicler.LogError("failed to open File: " + filePath);
        //    }
        //}

        //*******************************************************************************************
        //***  FUNCTION ResolveF3F4Expresion
        //*** ***************************************************************************************
        //***  DESCRIPTION  :  Resolves an expresion and adds a literal or gets a symbol
        //***  INPUT ARGS   :  SymbolTable symbolTable, LiteralTable literalTable,
        //***                   string expresion, string currentLine
        //***  OUTPUT ARGS :  out Globals.Symbol? symbol
        //***  IN/OUT ARGS   :  N/A
        //***  RETURN :  bool rtnVal
        //*******************************************************************************************
        public static bool ResolveF3F4Expresion(Globals.DataStructures dataStructures, string expresionString, string currentLine, out Globals.ExpresionData expresionData, string callingModule = "ExpresionHandler")
        {
            expresionData = new Globals.ExpresionData();
            bool  rtnVal     = true;
            Regex testXValue = new Regex(@"(^[^=][^,;]*(?<x>,x|X){0,1}.*$)|(^[\t ]*=.*$)");
            bool  hasXValue  = testXValue.Match(expresionString).Groups["x"].Value != "";

            expresionString = expresionString.Trim();
            if (Parser.guessOperandType(expresionString) == Parser.OperandType.NEW_STYLE_LITERAL || Parser.guessOperandType(expresionString) == Parser.OperandType.OLD_STYLE_LITERAL)
            {
                Chronicler.LogInfo("Parsing as literal: " + expresionString);
                if (Parser.guessOperandType(expresionString) == Parser.OperandType.NEW_STYLE_LITERAL)
                {
                    LiteralTable.LiteralValue tmp = new LiteralTable.LiteralValue();
                    string comment = "";
                    Parser.ParseNewStyleLiteral(expresionString, out tmp, out comment, callingModule);
                    expresionData.literal = tmp;
                    dataStructures.literalTable.add(tmp);
                }
                else if (Parser.guessOperandType(expresionString) == Parser.OperandType.OLD_STYLE_LITERAL)
                {
                    LiteralTable.LiteralValue tmp = new LiteralTable.LiteralValue();
                    string comment = "";
                    Parser.ParseOldStyleLiteral(expresionString, out tmp, out comment, callingModule);
                    expresionData.literal = tmp;
                }
            }
            else if (expresionString.Length > 0 && expresionString[0] == '@')
            {
                expresionString = expresionString.Substring(1, expresionString.Length - 1);
                hasXValue       = testXValue.Match(expresionString).Groups["x"].Value != "";
                if (hasXValue != true)
                {
                    if (ParseTerms(dataStructures, expresionString, currentLine, out expresionData) != true)
                    {
                        rtnVal = false;
                    }
                    expresionData.N = true;
                    expresionData.I = false;
                }
                else
                {
                    rtnVal = false;
                    Chronicler.LogError("Can not apply both indirect adressing \n\tand x register indexing, skipping: \"" + currentLine + "\"", "Resovling Expresion");
                }
            }
            else if (expresionString.Length > 0 && expresionString[0] == '#')
            {
                expresionString = expresionString.Substring(1, expresionString.Length - 1);
                hasXValue       = testXValue.Match(expresionString).Groups["x"].Value != "";
                if (hasXValue != true)
                {
                    if (ParseTerms(dataStructures, expresionString, currentLine, out expresionData) != true)
                    {
                        rtnVal = false;
                    }
                    expresionData.N = false;
                    expresionData.I = false;
                }
                else
                {
                    rtnVal = false;
                    Chronicler.LogError("Can not apply both immediate adressing \n\tand x register indexing, skipping:\"" + currentLine + "\"", "Resovling Expresion");
                }
            }
            else if (hasXValue == true)
            {
                expresionString = testXValue.Replace(expresionString, "$2$4$5");
                if (ParseTerms(dataStructures, expresionString, currentLine, out expresionData) != true)
                {
                    rtnVal = false;
                }
                expresionData.N = true;
                expresionData.I = true;
                expresionData.X = true;
            }
            else
            {
                rtnVal = ParseTerms(dataStructures, expresionString, currentLine, out expresionData);
            }
            return(rtnVal);
        }