コード例 #1
0
        ConstantDeclaration ParseConstantDeclaration()
        {
            ReadNextToken();              //skip constant

            string identifier = fCurrentToken.Value;

            ReadNextToken();              //skip identifier
            fCurrentToken = fLexicalAnalyser.SkipExpected(TokenType.Symbol, ":");

            string subtypeIndication = fCurrentToken.Value;

            ReadNextToken();



            //FIX 25.06.19: This is a fix to allow for constants of record type. This issue was realised when parsing intea_pif_p.vhd
            //Need to make class for record type constant
            if (RecordTypeList.Any(x => x.Identifier == subtypeIndication))
            {
                RecordTypeDeclaration recordConstant = RecordTypeList.Find(x => x.Identifier == subtypeIndication);
                ConstantRecordTypeList.Add(recordConstant);
                ConstantDeclaration ParsedConstant = new ConstantDeclaration(identifier, null, 0);
                fCurrentToken = fLexicalAnalyser.SkipOver(TokenType.Symbol, ";");
                return(ParsedConstant);
            }
            else
            {
                // In a package, a constant may be deferred. This means its value is defined in the package body. the value may be changed by re-analysing only the package body. we do not want this
                if (!fCurrentToken.Equals(TokenType.Symbol, ":="))
                {
                    throw new ParserException("Constants value definition must not be deferred to body");
                }

                ReadNextToken();

                Node result = ParseExpression();
                ConstantDeclaration ParsedConstant = new ConstantDeclaration(identifier, subtypeIndication, result.Eval());
                ConstantList.Add(ParsedConstant);
                ReadNextToken();
                return(ParsedConstant);
            }
        }
コード例 #2
0
        List <RecordTypeDeclaration> orderDependencies(List <RecordTypeDeclaration> unorganisedList)
        {
            bool stillGoing = true;

            while (stillGoing)
            {
                stillGoing = false;
                for (int i = 0; i < unorganisedList.Count - 1; i++)
                {
                    RecordTypeDeclaration x = unorganisedList[i];
                    RecordTypeDeclaration y = unorganisedList[i + 1];
                    if (x.SubtypeList.Any(q => q.getIdentifier() == y.getIdentifier()))
                    {
                        unorganisedList[i]     = y;
                        unorganisedList[i + 1] = x;
                        stillGoing             = true;
                    }
                }
            }
            return(unorganisedList);
        }
コード例 #3
0
        SignalType ParseTypeDeclaration()
        {
            ReadNextToken();              //skip type
            SignalType fType;

            string identifier = fCurrentToken.Value;

            fCurrentToken = fLexicalAnalyser.SkipOver(TokenType.Word, "is");

            if (fCurrentToken.Equals(TokenType.Word, "array"))
            {
                fCurrentToken = fLexicalAnalyser.SkipOver(TokenType.Symbol, "(");
                Node from = ParseExpression();
                //Used to have skip over "to" here but it can also be "downto"
                ReadNextToken();
                Node to = ParseExpression();
                fCurrentToken = fLexicalAnalyser.SkipOver(TokenType.Word, "of");
                string subtypeIndication = fCurrentToken.Value;
                fType         = FindDefinedType();
                fCurrentToken = fLexicalAnalyser.SkipOver(TokenType.Symbol, ";");

                ArrayTypeDeclaration ParsedArrayType = new ArrayTypeDeclaration(identifier, from.Eval(), to.Eval(), fType);
                ArrayTypeList.Add(ParsedArrayType);
                return(ParsedArrayType);
            }
            else if (fCurrentToken.Equals(TokenType.Word, "record"))
            {
                List <string>     identifierList        = new List <string> ();
                List <SignalType> subtypeIndicationList = new List <SignalType> ();
                ReadNextToken();                  //skip "record"

                CheckForUnexpectedEndOfSource();

                while (!fCurrentToken.Equals(TokenType.Word, "end"))
                {
                    identifierList.Add(fCurrentToken.Value);
                    fCurrentToken = fLexicalAnalyser.SkipOver(TokenType.Symbol, ":");
                    //Searches for the type of each record entry.
                    fType = FindDefinedType();
                    subtypeIndicationList.Add(fType);
                    fCurrentToken = fLexicalAnalyser.SkipOver(TokenType.Symbol, ";");
                }
                //Skip Over: end record;
                fCurrentToken = fLexicalAnalyser.SkipOver(TokenType.Symbol, ";");



                RecordTypeDeclaration ParsedRecordType = new RecordTypeDeclaration(identifier, identifierList, subtypeIndicationList);
                RecordTypeList.Add(ParsedRecordType);
                return(ParsedRecordType);
            }
            else
            {
                List <string> enumerationList = new List <string> ();
                fCurrentToken = fLexicalAnalyser.SkipOver(TokenType.Symbol, "(");

                while (!fCurrentToken.Equals(TokenType.Symbol, ";"))
                {
                    enumerationList.Add(fCurrentToken.Value);
                    //Can't use skip over "," since no "," after last entry
                    ReadNextToken();
                    ReadNextToken();
                }

                ReadNextToken();
                EnumerationTypeDeclaration ParsedEnumerationType = new EnumerationTypeDeclaration(identifier, enumerationList);
                EnumerationTypeList.Add(ParsedEnumerationType);
                return(ParsedEnumerationType);
            }
        }