Ejemplo n.º 1
0
        public static ADDeclaration global_decl_list(ADDeclaration declaration = null)
        {
            if (MainFSM.PeekNextToken().Type == TokenType.longType)
            {
                if (declaration == null)
                {
                    declaration = new ADDeclaration();
                }

                declaration.Variables = declaration.Variables.Concat(glob_decl().ToList()).ToList();
            }
            else if (MainFSM.PeekNextToken().Type == TokenType.idType ||
                     MainFSM.PeekNextToken().Type == TokenType.eofType)
            {
                STablesStack.Peek().Records.Clear();

                foreach (var item in declaration.Variables)
                {
                    STRecord newRecord = null;

                    if (item.Type == ADVariable.VarType.variable)
                    {
                        newRecord = new STRecord()
                        {
                            Access  = STAccess.global,
                            Type    = STType.variable,
                            Name    = item.Name,
                            Address = (item.STRecord != null) ? item.STRecord.Address : ""
                        };
                    }
                    else if (item.Type == ADVariable.VarType.array)
                    {
                        newRecord = new STRecord()
                        {
                            Access  = STAccess.global,
                            Type    = STType.array,
                            Name    = item.Name,
                            Address = (item.STRecord != null) ? item.STRecord.Address : ""
                        };
                    }

                    item.STRecord = newRecord;
                    STablesStack.Peek().Records.Add(newRecord);
                }

                return(declaration);
            }
            else
            {
                SyntaxError("Byla ocekavana deklarace globalni promenne, deklarace funkce nebo konec programu");
            }

            global_decl_list(declaration);

            return(declaration);
        }
Ejemplo n.º 2
0
        public static string DeclareGlobalVariables(ADDeclaration variables)
        {
            string result = string.Empty;

            foreach (var variable in variables.Variables)
            {
                variable.STRecord.Address = variable.Name;
                Console.WriteLine($"{variable.STRecord.Name}:");

                if (variable.STRecord.Type == Parser.SymbolTable.STType.array)
                {
                    if (variable.ArrayDimensions.Count > 0)
                    {
                        foreach (var dimension in variable.ArrayDimensions)
                        {
                            if (dimension.Values.Count > 0)
                            {
                                foreach (var item in dimension.Values)
                                {
                                    Console.WriteLine($".8byte {(item as ADConstant).Value}");
                                }
                            }
                            else if (dimension.ValuesCount != null)
                            {
                                Console.WriteLine($".rept {(dimension.ValuesCount as ADConstant).Value}");
                                Console.WriteLine(".8byte 0");
                                Console.WriteLine(".endr");
                            }
                        }
                    }
                }
                else if (variable.STRecord.Type == Parser.SymbolTable.STType.variable)
                {
                    Console.WriteLine($".8byte 0");

                    if (variable.Value != null)
                    {
                        result += PrintExpression(variable.Value) + Environment.NewLine;
                        result += PrintAssignRdx(variable) + Environment.NewLine;
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        public static void PrintDeclaration(ADDeclaration declaration, string tab)
        {
            foreach (var variable in declaration.Variables)
            {
                Console.WriteLine($"{tab}|- Decl: {variable.Name}");
                Console.WriteLine($"{tab}|\tType: {variable.Type}");
                Console.WriteLine($"{tab}|\tAccess: {variable.STRecord.Access}");

                if (variable.Type == Parser.ADT.Operands.ADVariable.VarType.array)
                {
                    Console.WriteLine($"{tab}|\tDimensions: {variable.ArrayDimensions.Count}");

                    foreach (var dimension in variable.ArrayDimensions)
                    {
                        if (dimension.ValuesCount != null)
                        {
                            Console.WriteLine($"{tab}|\tCount:");
                            PrintExpression(dimension.ValuesCount, tab + "\t\t");
                        }

                        if (dimension.Values.Count > 0)
                        {
                            Console.WriteLine($"{tab}|\tValues:");
                        }
                        foreach (var value in dimension.Values)
                        {
                            PrintExpression(value, tab + "\t\t");
                        }
                    }
                }
                else if (variable.Type == ADVariable.VarType.variable)
                {
                    if (variable.Value != null)
                    {
                        Console.WriteLine($"{tab}|\tValue:");
                        PrintExpression(variable.Value, tab + "\t\t");
                    }
                }
            }
        }