From 50fea9020210a022d34d79f380ce1bd5e7d12050 Mon Sep 17 00:00:00 2001 From: handa Date: Wed, 16 Sep 2009 00:04:27 +0000 Subject: [PATCH] *** empty log message *** --- XmlExpr.cs | 46 ++++++++++++++++++++++++++++++++++++---------- xex.txt | 9 +++++---- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/XmlExpr.cs b/XmlExpr.cs index 5a696ae..a3e2b30 100644 --- a/XmlExpr.cs +++ b/XmlExpr.cs @@ -177,16 +177,41 @@ namespace System.Xml.Expression internal class Lambda : Function { - internal Xex[] args; + internal bool args_evaled = true; + internal Name[] args; internal Xex[] body; - public Lambda (Name name, int min_arg, int max_arg) - : base (name, min_arg, max_arg) - { - } - - public void SetArgs (XmlNode node, int nargs, Domain domain) + public Lambda (XmlNode node) { + Name name = node.Attributes[Nfname].Value; + int nargs = 0, noptions = 0, nrest = 0; + XmlNode n; + + node = node.FirstChild; + if (node != null && node.Name == Nargs) + { + for (XmlNode n = node.FirstChild; n != null; n = n.NextSibling) + { + if (n.Name == Noptional || n.Name == Nrest) + break; + nargs++; + } + if (n != null && n.Name == Noptional) + for (n = n.NextSibling; n != null; n = n.NextSibling) + { + if (n.Name == Nrest) + break; + noptions++; + } + if (n != null && n.Name == Nrest) + for (n = n.NextSibling; n != null; n = n.NextSibling) + nrest++; + min_arg = nargs; + max_arg = nargs + noptions + nrest; + if (nrest == 1) + max_arg = - max_arg; + + args = new Xex[nargs]; node = node.FirstChild; for (int i = 0; i < nargs; node = node.NextSibling) @@ -462,8 +487,8 @@ namespace System.Xml.Expression = new Function.SpecialForm (builtin, name, min_arg, max_arg); } - private static Name ParseHead (XmlNode node, - out int min_arg, out int max_arg) + private static Name ParseHead (XmlNode node, out bool evaled, + out int min_arg, out int max_arg) { Name name = node.Attributes[Nfname].Value; int nargs = 0, noptions = 0, nrest = 0; @@ -494,8 +519,9 @@ namespace System.Xml.Expression internal Function.Lambda RegisterFunction (XmlNode node) { + bool evaled; int min_arg, max_arg; - Name name = ParseHead (node, out min_arg, out max_arg); + Name name = ParseHead (node, out evaled, out min_arg, out max_arg); Function.Lambda lambda = new Function.Lambda (name, min_arg, max_arg); functions[name] = lambda; diff --git a/xex.txt b/xex.txt index ced1f80..8926360 100644 --- a/xex.txt +++ b/xex.txt @@ -6,19 +6,20 @@ TERM = [ VAR | DIRECT | FUNCALL ] TYPE = 'integer' | 'string' | 'boolean' | 'symbol' | 'list' DEFUN = - '' + '' ARGS ? TERM * '' ARGS = - '' [ SYMBOL | VAR ] * OPTIONAL ? REST ? '' + '' SYMBOL * OPTIONAL ? REST ? '' + | '' SYMBOL * OPTIONAL ? REST ? '' OPTIONAL = - '' [ SYMBOL | VAR ] * + '' SYMBOL * REST = - '' [ SYMBOL | VAR ] + '' SYMBOL DEFVAR = DEFVAR-INT DEFVAR-STR DEFVAR-BOOL -- 1.7.10.4