Esempio n. 1
0
 internal DeclarationStatement(LexLocation location, Type type, DeclarationList list,
                               bool c = false) : base(location)
 {
     this.type       = type;
     declarationList = list;
     constant        = c;
 }
Esempio n. 2
0
        public Node Program()
        {
            var decList  = new DeclarationList();
            var stmtList = new StatementList();

            while (firstOfDeclaration.Contains(CurrentToken))
            {
                decList.Add(Declaration());
            }

            var result = new Program()
            {
                AnchorToken = Expect(TokenCategory.PROG)
            };

            while (firstOfStatement.Contains(CurrentToken))
            {
                stmtList.Add(Statement());
            }

            Expect(TokenCategory.END);
            Expect(TokenCategory.SEMICOL);
            Expect(TokenCategory.EOF);

            result.Add(decList);
            result.Add(stmtList);

            return(result);
        }
Esempio n. 3
0
        public override bool Visit(DeclarationList node)
        {
            CallableDeclaration insideFunction = declEnv.GetDeclaringRoutine();
            Section             outside        = insideFunction.declaringSection;

            for (int i = node.nodes.Count - 1; i >= 0; i--)
            {
                if (insideFunction != null && node.nodes[i] is CallableDeclaration)
                {
                    string name = node.nodes[i].ToString();
                    Console.WriteLine("Nesting: " + name);
                    CallableDeclaration decl = node.nodes[i] as CallableDeclaration;

                    string oldname = decl.name;
                    string newname = insideFunction.name + "_" + decl.name;
                    replacements[oldname] = newname;
                    decl.name             = newname;

                    node.nodes.RemoveAt(i);
                    if (!outside.decls.Contains(decl))
                    {
                        outside.decls.AddStart(decl);
                    }

                    traverse(decl);

                    //replacements.Remove(oldname);
                }
                else
                {
                    traverse(node.nodes[i]);
                }
            }
            return(true);
        }
Esempio n. 4
0
        public void compareResourceEOE(String resourceName)
        {
            String expected = getResourceAsString(resourceName);
            // Console.WriteLine(expected);
            // parse e source code
            DeclarationList dle = parseEString(expected);

            context = Context.newGlobalsContext();
            dle.register(context);
            // rewrite as o
            CodeWriter writer = new CodeWriter(Dialect.O, context);

            dle.ToDialect(writer);
            String o = writer.ToString();
            // Console.WriteLine(o);
            // parse o source code
            DeclarationList dlo = parseOString(o);

            context = Context.newGlobalsContext();
            dlo.register(context);
            // rewrite as e
            writer = new CodeWriter(Dialect.E, context);
            dlo.ToDialect(writer);
            String actual = writer.ToString();

            // Console.WriteLine(actual);
            // ensure equivalent
            assertEquivalent(expected, actual);
        }
Esempio n. 5
0
        /****************************************************************
         *                    Declarations List Node
         ***************************************************************/

        private Node EvaluateDeclarations()
        {
            var decls = new DeclarationList();

            while (firstOfDeclaration.Contains(CurrentToken))
            {
                if (CurrentToken == TokenCategory.PARAMETER)
                {
                    decls.Add(Parameter());
                }
                else if (CurrentToken == TokenCategory.COMMON)
                {
                    decls.Add(Common());
                }
                else if (CurrentToken == TokenCategory.DATA)
                {
                    decls.Add(Data());
                }
                else
                {
                    decls.Add(Declaration());
                }
            }
            return(decls);
        }
Esempio n. 6
0
        public void testNative()
        {
            DeclarationList stmts = parseResource("native/method.pec");

            Assert.IsNotNull(stmts);
            Assert.AreEqual(2, stmts.Count);
        }
Esempio n. 7
0
        public void testNativeAttribute()
        {
            DeclarationList stmts = parseString("attribute id: Integer;");

            stmts.register(context);
            stmts.check(context);
        }
Esempio n. 8
0
        public void testAttribute()
        {
            DeclarationList stmts = parseResource("methods/attribute.pec");

            Assert.IsNotNull(stmts);
            Assert.AreEqual(7, stmts.Count);
        }
Esempio n. 9
0
        public void testSpecified()
        {
            DeclarationList stmts = parseResource("methods/specified.pec");

            Assert.IsNotNull(stmts);
            Assert.AreEqual(6, stmts.Count);
        }
Esempio n. 10
0
        public void testEmpty()
        {
            DeclarationList stmts = parseString("");

            Assert.IsNotNull(stmts);
            Assert.AreEqual(0, stmts.Count);
        }
Esempio n. 11
0
        public void testEnumeratedCategory()
        {
            DeclarationList stmts = parseResource("enums/categoryEnum.pec");

            Assert.IsNotNull(stmts);
            Assert.AreEqual(7, stmts.Count);
        }
Esempio n. 12
0
        public override bool Visit(CallableDeclaration node)
        {
            ProceduralType pp = node.type as ProceduralType;

            traverse(pp.funcret);
            string name = node.name as string;

            outputCode(name, false, false);
            outputCode("(", false, false);

            DeclarationList p = [email protected];
            int             i = 0;

            foreach (ParamDeclaration pd in p)
            {
                if (i > 0)
                {
                    outputCode(", ", false, false);
                }
                traverse(pd);
                i++;
            }
            outputCode(")", false, true);
            traverse(node.Directives);
            return(true);
        }
Esempio n. 13
0
        public Node Program()
        {
            var declList = new DeclarationList();
            var stmtList = new StatementList();

            while (firstOfDeclaration.Contains(CurrentToken))
            {
                declList.Add(Declaration());
            }

            while (firstOfStatement.Contains(CurrentToken))
            {
                stmtList.Add(Statement());
            }

            Expect(TokenCategory.EOF);

            // This refers to the class that refers to the 'Program' token,
            // not this method's name.
            return(new Program()
            {
                declList,
                stmtList
            });
        }
Esempio n. 14
0
        public void compareResourceOMO(String resourceName)
        {
            String expected = getResourceAsString(resourceName);
            // Console.WriteLine(expected);
            // parse o source code
            DeclarationList dlo = parseOString(expected);

            context = Context.newGlobalsContext();
            dlo.register(context);
            // rewrite as p
            CodeWriter writer = new CodeWriter(Dialect.M, context);

            dlo.ToDialect(writer);
            String m = writer.ToString();
            // Console.WriteLine(p);
            // parse m source code
            DeclarationList dlp = parseMString(m);

            context = Context.newGlobalsContext();
            dlp.register(context);
            // rewrite as o
            writer = new CodeWriter(Dialect.O, context);
            dlp.ToDialect(writer);
            String actual = writer.ToString();

            // Console.WriteLine(actual);
            // ensure equivalent
            assertEquivalent(expected, actual);
        }
 //-----------------------------------------------------------
 public Type VisitFirst(DeclarationList node)
 {
     foreach (var decl in node)
     {
         VisitFirst((dynamic)decl);
     }
     return(Type.VOID);
 }
Esempio n. 16
0
 public virtual T Visit(DeclarationList node)
 {
     foreach (Node n in node.nodes)
     {
         traverse(n);
     }
     return(DefaultReturnValue());
 }
Esempio n. 17
0
        protected void loadResource(String resourceName)
        {
            DeclarationList decls = parseResource(resourceName);

            Assert.IsNotNull(decls);
            decls.register(context);
            decls.check(context);
        }
Esempio n. 18
0
 public override bool Visit(DeclarationList node)
 {
     foreach (Node n in node.nodes)
     {
         TraversePrint(n);
     }
     return(true);
 }
Esempio n. 19
0
        public void testList()
        {
            DeclarationList stmts = parseString("method testMethod (Text value) {" +
                                                "list = [ \"john\" , \"jim\" ];" +
                                                "elem = list[1]; }");

            stmts.register(context);
            stmts.check(context);
        }
Esempio n. 20
0
        public void testCategoryAttribute()
        {
            DeclarationList stmts = parseString("attribute id: Integer;" +
                                                "category Person(id);" +
                                                "attribute person: Person;");

            stmts.register(context);
            stmts.check(context);
        }
Esempio n. 21
0
        public void testDict()
        {
            DeclarationList stmts = parseString("method testMethod (Text value) {" +
                                                "dict = < \"john\":123, \"jim\":345 >;" +
                                                "elem = dict[\"john\"]; }");

            stmts.register(context);
            stmts.check(context);
        }
Esempio n. 22
0
        public void testList()
        {
            DeclarationList stmts = parseString("define testMethod as method receiving Text value doing:\r\n" +
                                                "\tlist = [ \"john\" , \"jim\" ]\r\n" +
                                                "\telem = list[1]\r\n");

            stmts.register(context);
            stmts.check(context);
        }
Esempio n. 23
0
        public void testDict()
        {
            DeclarationList stmts = parseString("define testMethod as method receiving Text value doing:\r\n" +
                                                "\tdict = < \"john\":123, \"jim\":345 >\r\n" +
                                                "\telem = dict[\"john\"]\r\n");

            stmts.register(context);
            stmts.check(context);
        }
Esempio n. 24
0
        public void testCategory()
        {
            DeclarationList stmts = parseString("define id as Integer attribute\r\n" +
                                                "define Person as category with attribute id\r\n" +
                                                "define Employee as Person");

            stmts.register(context);
            stmts.check(context);
        }
Esempio n. 25
0
        DeclarationList CreateDecls(ArrayList ids, CreateDecl func)
        {
            var list = new DeclarationList();

            foreach (String s in ids)
            {
                list.Add(func(s));
            }
            return(list);
        }
Esempio n. 26
0
        public void registerCategoryTypes()
        {
            DeclarationList stmts = parseString("define id as Integer attribute\r\n" +
                                                "define name as String attribute\r\n" +
                                                "define Root as category with attribute id\r\n" +
                                                "define Derived as Root with attribute name\r\n" +
                                                "define Unrelated as category with attributes id and name\r\n");

            stmts.register(context);
        }
Esempio n. 27
0
        public void testMethod()
        {
            DeclarationList stmts = parseString("define print as native method receiving Text value doing:\r\n" +
                                                "\tC#: System.Console.WriteLine(value);\r\n" +
                                                "define name as Text attribute\r\n" +
                                                "define printName as method receiving name doing:\r\n" +
                                                "\tprint with \"name\" + name as value");

            stmts.register(context);
            stmts.check(context);
        }
Esempio n. 28
0
        public void testMethod()
        {
            DeclarationList stmts = parseString("native method print( Text value) {" +
                                                "C#: System.Console.WriteLine(value); }" +
                                                "attribute name: Text;" +
                                                "method printName(name ) {" +
                                                "print( value = \"name\" + name ); }");

            stmts.register(context);
            stmts.check(context);
        }
Esempio n. 29
0
        public void register()
        {
            context = Context.newGlobalsContext();
            DeclarationList stmts = parseString("define id as Integer attribute\r\n" +
                                                "define name as String attribute\r\n" +
                                                "define other as String attribute\r\n" +
                                                "define Simple as category with attribute name\r\n" +
                                                "define Root as category with attribute id\r\n" +
                                                "define DerivedWithOther as Root with attribute other\r\n" +
                                                "define DerivedWithName as Root with attribute name\r\n");

            stmts.register(context);
        }
Esempio n. 30
0
        public void testCategoryWithUndeclaredAttribute()
        {
            DeclarationList stmts = parseString("category Person(id);");

            try
            {
                stmts.register(context);
                stmts.check(context);
                Assert.Fail("Should fail since id not declared !");
            }
            catch (SyntaxError)
            {
            }
        }
Esempio n. 31
0
            void PrintDeclarationList(DeclarationList v, int d)
            {
                Indent(d);
                SayLn("DeclarationList(");
                if (v != null)
                {
                    SayLn("");
                    PrintDeclaration(v.Head, d + 1);
                    SayLn(",");
                    PrintDeclarationList(v.Tail, d + 1);
                }

                Say(")");
            }
 public LetExpression(Position pos, DeclarationList decs, Expression body)
 {
     Pos = pos;
     Decs = decs;
     Body = body;
 }
Esempio n. 33
0
 public DeclarationList(Declaration head, DeclarationList tail)
 {
     Head = head;
     Tail = tail;
 }