Пример #1
0
        public override object VisitEnumTypeDefDecl(PParser.EnumTypeDefDeclContext context)
        {
            // ENUM name=iden
            PEnum pEnum = (PEnum)nodesToDeclarations.Get(context);

            // LBRACE enumElemList RBRACE
            if (context.enumElemList() is PParser.EnumElemListContext elemList)
            {
                EnumElem[] elems = (EnumElem[])Visit(elemList);
                for (int i = 0; i < elems.Length; i++)
                {
                    EnumElem elem = elems[i];
                    elem.Value = i;
                    pEnum.AddElement(elem);
                }
            }
            // | LBRACE numberedEnumElemList RBRACE
            else if (context.numberedEnumElemList() is PParser.NumberedEnumElemListContext numberedElemList)
            {
                EnumElem[] numberedElems = (EnumElem[])Visit(numberedElemList);
                foreach (EnumElem elem in numberedElems)
                {
                    pEnum.AddElement(elem);
                }
            }
            else
            {
                Debug.Fail("grammar requires enum declarations to have element lists");
            }

            return(pEnum);
        }
Пример #2
0
        public override object VisitNumberedEnumElem(PParser.NumberedEnumElemContext context)
        {
            string   symbolName = context.name.GetText();
            EnumElem elem       = CurrentScope.Put(symbolName, context);

            nodesToDeclarations.Put(context, elem);
            return(null);
        }
Пример #3
0
        public EnumElem Put(string name, PParser.NumberedEnumElemContext tree)
        {
            EnumElem enumElem = new EnumElem(name, tree);

            CheckConflicts(enumElem, Namespace(enumElems), Namespace(events));
            enumElems.Add(name, enumElem);
            return(enumElem);
        }
Пример #4
0
        public override object VisitNumberedEnumElem(PParser.NumberedEnumElemContext context)
        {
            // name=iden ASSIGN value=IntLiteral
            EnumElem elem = (EnumElem)nodesToDeclarations.Get(context);

            elem.Value = int.Parse(context.value.Text);
            return(elem);
        }
Пример #5
0
        public bool Lookup(string name, out EnumElem tree)
        {
            Scope current = this;

            while (current != null)
            {
                if (current.Get(name, out tree))
                {
                    return(true);
                }

                current = current.Parent;
            }

            tree = null;
            return(false);
        }
Пример #6
0
 public string GetEnumElementName(EnumElem elem)
 {
     return(elem.Name);
 }
Пример #7
0
 public bool Get(string name, out EnumElem tree)
 {
     return(enumElems.TryGetValue(name, out tree));
 }
Пример #8
0
 public EnumElemRefExpr(ParserRuleContext sourceLocation, EnumElem enumElem)
 {
     SourceLocation = sourceLocation;
     EnumElem       = enumElem;
     Type           = new EnumType(EnumElem.ParentEnum);
 }