From 1886ee749147f8dd59897f13a3f4501ff483565a Mon Sep 17 00:00:00 2001 From: handa Date: Wed, 2 Dec 2009 00:07:29 +0000 Subject: [PATCH] *** empty log message *** --- XmlExpr.cs | 71 ++++++++++++++++++++++++++++++++++++++++++++++++------------ xex.txt | 2 +- 2 files changed, 58 insertions(+), 15 deletions(-) diff --git a/XmlExpr.cs b/XmlExpr.cs index 4d2f76b..08954e8 100644 --- a/XmlExpr.cs +++ b/XmlExpr.cs @@ -86,6 +86,7 @@ namespace System.Xml public static Symbol VariableRangeConflict = "variable-range-conflict"; public static Symbol VariableWrongRange = "variable-wrong-range"; public static Symbol VariableWrongValue = "variable-wrong-value"; + public static Symbol UnknownFunction = "unknown-function"; public static Symbol MacroExpansionError = "macro-expansion-error"; public static Symbol NoVariableName = "no-variable-anme"; @@ -739,11 +740,15 @@ namespace System.Xml internal void ThrowSymbol (Term tag) { + int i = catch_count; foreach (CatchTag elt in catch_stack) { - catch_count--; + i--; if (elt.Tag.Matches (tag)) - return; + { + catch_count = i; + return; + } } throw new Error (Error.UncaughtThrow, "No corresponding catch: {0}", tag); @@ -856,8 +861,20 @@ namespace System.Xml internal Variable Defvar (Symbol name) { - Variable vari = new Variable (this, name, Zero); - variables[name] = vari; + Variable vari; + + if (variables.TryGetValue (name, out vari)) + { + Variable.Typed typed = vari as Variable.Typed; + if (typed != null) + throw new Error (Error.VariableTypeConflict, + "Not a non-typed variable: {0}", name); + } + else + { + vari = new Variable (this, name, Zero); + variables[name] = vari; + } return vari; } @@ -1390,16 +1407,26 @@ namespace System.Xml private static Term Fand (Domain domain, Variable vari, Term[] args) { foreach (Term arg in args) - if (! arg.Eval (domain).IsTrue) - return Zero; + { + Term result = arg.Eval (domain); + if (domain.Thrown ()) + result; + if (! result.IsTrue) + return Zero; + } return One; } private static Term For (Domain domain, Variable vari, Term[] args) { foreach (Term arg in args) - if (arg.Eval (domain).IsTrue) - return One; + { + Term result = arg.Eval (domain); + if (domain.Thrown ()) + return result; + if (result.IsTrue) + return One; + } return Zero; } @@ -1413,13 +1440,21 @@ namespace System.Xml Term result = One; foreach (Term arg in args) - result = arg.Eval (domain); + { + result = arg.Eval (domain); + if (domain.Thrown ()) + return result; + } return result; } private static Term Fif (Domain domain, Variable vari, Term[] args) { - if (args[0].Eval (domain).IsTrue) + Term result = args[0].Eval (domain); + + if (domain.Thrown) + return result; + if (result.IsTrue) return args[1].Eval (domain); if (args.Length == 2) return Zero; @@ -1428,11 +1463,19 @@ namespace System.Xml private static Term Fwhen (Domain domain, Variable vari, Term[] args) { - if (! args[0].Eval (domain).IsTrue) + Term result = args[0].Eval (domain); + + if (domain.Thrown) + return result; + if (! result.IsTrue) return Zero; - Term result = One; + result = One; for (int i = 1; i < args.Length; i++) - result = args[i].Eval (domain); + { + result = args[i].Eval (domain); + if (domain.Thrown) + return result; + } return result; } @@ -1565,7 +1608,7 @@ namespace System.Xml { result = terms[i].Eval (domain); if (domain.Thrown (out caught)) - break; + return result; } return result; } diff --git a/xex.txt b/xex.txt index 0adac9b..055a0eb 100644 --- a/xex.txt +++ b/xex.txt @@ -181,7 +181,7 @@ CONCAT = '' [ STRTERM | INTTERM | LISTTERM ] + '' LENGTH = '' [ STRTERM | LISTTERM ] '' NTH = '' INTTERM [ STRTERM | LISTTERM ] '' -COPY = '' LISTTERM '' +COPY = '' [ STRTERM | LISTTERM ] '' INS = '' INTTERM [ STRTERM | LISTTERM ] '' DEL = '' INTTERM INTTERM '' -- 1.7.10.4