Beispiel #1
0
 /// <summary>
 /// VarDecl -> Type IdentifierList ; VarDecl |
 ///            FinalT Type IdT = NumT ; VarDecl |
 ///            ε
 /// </summary>
 private void VarDecl()
 {
     if (Token == Tokens.FinalT)
     {
         Match(Tokens.FinalT);
         Type();
         TableEntry entry = symbolTable.CreateTableEntry();
         VarNames.Add(Lexeme);
         Match(Tokens.IdT);
         Match(Tokens.AssignOpT);
         BpOffsetName = $"_bp-{Offset}";
         symbolTable.ConvertEntryToConstant(entry);
         Match(Tokens.NumT);
         LocalVarsSize += Size;
         Offset        += Size;
         Match(Tokens.SemiT);
         VarDecl();
     }
     else if (Types.Contains(Token))
     {
         Type();
         IdentifierList();
         Match(Tokens.SemiT);
         VarDecl();
     }
 }
Beispiel #2
0
        public void Unpack(BinaryReader reader)
        {
            Id = reader.ReadUInt32();

            var num_varnames = reader.ReadUInt16();

            for (uint i = 0; i < num_varnames; i++)
            {
                VarNames.Add(reader.ReadUnicodeString());
            }

            var num_vars = reader.ReadUInt16();

            for (uint i = 0; i < num_vars; i++)
            {
                Vars.Add(reader.ReadUnicodeString());
            }

            var num_strings = reader.ReadUInt32();

            for (uint i = 0; i < num_strings; i++)
            {
                Strings.Add(reader.ReadUnicodeString());
            }

            var num_comments = reader.ReadUInt32();

            for (uint i = 0; i < num_comments; i++)
            {
                Comments.Add(reader.ReadUInt32());
            }

            Unknown = reader.ReadByte();
        }
Beispiel #3
0
 /// <summary>
 /// IdentifierList -> IdT IdentifierListTail
 /// </summary>
 private void IdentifierList()
 {
     if (Token == Tokens.IdT)
     {
         TableEntry entry = symbolTable.CreateTableEntry();
         BpOffsetName = $"_bp-{Offset}";
         symbolTable.ConvertEntryToVariable(entry);
         VarNames.Add(Lexeme);
         LocalVarsSize += Size;
         Offset        += Size;
         Match(Tokens.IdT);
         IdentifierListTail();
     }
     else
     {
         ErrorHandler.LogError($"expected an identifier, found \"{Lexeme}\"");
     }
 }
Beispiel #4
0
        /// <summary>
        /// IdentifierListTail -> , IdT IdentifierListTail | ε
        /// </summary>
        private void IdentifierListTail()
        {
            if (Token == Tokens.CommaT)
            {
                Match(Tokens.CommaT);
                TableEntry entry = symbolTable.CreateTableEntry();
                BpOffsetName = $"_bp-{Offset}";
                symbolTable.ConvertEntryToVariable(entry);
                VarNames.Add(Lexeme);
                LocalVarsSize += Size;
                Offset        += Size;
                Match(Tokens.IdT);

                if (Token == Tokens.IdT)
                {
                    ErrorHandler.LogError("expected \",\" before next identifier");
                }

                IdentifierListTail();
            }
        }