internal DeclarationStatement(LexLocation location, Type type, DeclarationList list, bool c = false) : base(location) { this.type = type; declarationList = list; constant = c; }
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); }
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); }
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); }
/**************************************************************** * 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); }
public void testNative() { DeclarationList stmts = parseResource("native/method.pec"); Assert.IsNotNull(stmts); Assert.AreEqual(2, stmts.Count); }
public void testNativeAttribute() { DeclarationList stmts = parseString("attribute id: Integer;"); stmts.register(context); stmts.check(context); }
public void testAttribute() { DeclarationList stmts = parseResource("methods/attribute.pec"); Assert.IsNotNull(stmts); Assert.AreEqual(7, stmts.Count); }
public void testSpecified() { DeclarationList stmts = parseResource("methods/specified.pec"); Assert.IsNotNull(stmts); Assert.AreEqual(6, stmts.Count); }
public void testEmpty() { DeclarationList stmts = parseString(""); Assert.IsNotNull(stmts); Assert.AreEqual(0, stmts.Count); }
public void testEnumeratedCategory() { DeclarationList stmts = parseResource("enums/categoryEnum.pec"); Assert.IsNotNull(stmts); Assert.AreEqual(7, stmts.Count); }
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); }
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 }); }
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); }
public virtual T Visit(DeclarationList node) { foreach (Node n in node.nodes) { traverse(n); } return(DefaultReturnValue()); }
protected void loadResource(String resourceName) { DeclarationList decls = parseResource(resourceName); Assert.IsNotNull(decls); decls.register(context); decls.check(context); }
public override bool Visit(DeclarationList node) { foreach (Node n in node.nodes) { TraversePrint(n); } return(true); }
public void testList() { DeclarationList stmts = parseString("method testMethod (Text value) {" + "list = [ \"john\" , \"jim\" ];" + "elem = list[1]; }"); stmts.register(context); stmts.check(context); }
public void testCategoryAttribute() { DeclarationList stmts = parseString("attribute id: Integer;" + "category Person(id);" + "attribute person: Person;"); stmts.register(context); stmts.check(context); }
public void testDict() { DeclarationList stmts = parseString("method testMethod (Text value) {" + "dict = < \"john\":123, \"jim\":345 >;" + "elem = dict[\"john\"]; }"); stmts.register(context); stmts.check(context); }
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); }
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); }
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); }
DeclarationList CreateDecls(ArrayList ids, CreateDecl func) { var list = new DeclarationList(); foreach (String s in ids) { list.Add(func(s)); } return(list); }
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); }
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); }
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); }
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); }
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) { } }
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; }
public DeclarationList(Declaration head, DeclarationList tail) { Head = head; Tail = tail; }