[Gridflow-cvs] [svn] commit: r6285 - /trunk/src/classes4.cxx

svn-gridflow at artengine.ca svn-gridflow at artengine.ca
Sun Sep 19 16:54:28 EDT 2010


Author: matju
Date: Sun Sep 19 16:54:28 2010
New Revision: 6285

Log:
just starting to code [gf/expr]

Modified:
    trunk/src/classes4.cxx

Modified: trunk/src/classes4.cxx
==============================================================================
--- trunk/src/classes4.cxx (original)
+++ trunk/src/classes4.cxx Sun Sep 19 16:54:28 2010
@@ -18,6 +18,60 @@
 	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
 
+#include "gridflow.hxx.fcs"
+
+// FOR FUTURE USE
+\class GFExpr : FObject {
+	#define A_OP    t_atomtype(0x1000)
+	#define A_VAR   t_atomtype(0x1001) /* for $f1-style variables, not other variables */
+	#define A_OPEN  t_atomtype(0x1002) /* only between next() and parse() */
+	#define A_CLOSE t_atomtype(0x1003) /* only between next() and parse() */
+
+	vector<t_atom2> toks;
+	vector<t_atom2> code;
+	t_atom2 tok;
+	void next (const char *&s) {
+		while (*s && isspace(*s)) s++;
+		if (!*s) tok.a_type=A_NULL;
+		else if (isdigit(*s) || *s=='.') {char *e; tok = strtof(s,&e); s=(const char *)e;}
+		else if (strchr("+-*/",*s)) {char t[2]={0,0}; *t=*s; tok.a_type=A_OP; tok.a_symbol=gensym(t); post("%c",*s); s++;}
+		else if (*s=='(') {s++; tok.a_type=A_OPEN;}
+		else if (*s==')') {s++; tok.a_type=A_CLOSE;}
+		else if (*s==';') {s++; tok.a_type=A_SEMI;}
+		else if (*s==',') {s++; tok.a_type=A_COMMA;}
+		else RAISE("syntax error at character '%c'",*s);
+		toks.push_back(tok);
+	}
+	void parse (const char *s, int level=0) { // should be storing last token for look-ahead...
+		next(s);
+		switch (int(tok.a_type)) {
+		  case A_FLOAT: case A_SYMBOL: case A_VAR:
+			code.push_back(tok);
+			next(s);
+			switch (int(tok.a_type)) {
+				case A_OP: {t_atom2 tok2=tok; parse(s,level+1); code.push_back(tok2);} break;
+				case A_NULL: return;
+				default: {string z=tok.to_s(); RAISE("syntax error (%db) tok=%s",level,z.data());}
+			}
+		  break;
+		  case A_OPEN: parse(s,level+1); break;
+		  case A_CLOSE: return; // may be uncaught syntax error
+		  case A_COMMA: RAISE("can't use comma there");
+		  case A_SEMI:  RAISE("semi not supported");
+		  case A_NULL:  return; // may be uncaught syntax error
+		  default: {string z=tok.to_s(); RAISE("syntax error (%db) tok=%s",level,z.data());} // A_CANT, A_OP
+		};
+	}
+	\constructor (...) {
+		string s = join(argc,argv);
+		try {parse(s.data());}
+		catch (Barf &oozy) {oozy.error(gensym("gf/expr"),argc,argv);}
+		string t = join(toks.size(),toks.data()); post("gf/expr toks: %s",t.data());
+		string c = join(code.size(),code.data()); post("gf/expr code: %s",c.data());
+	}
+};
+\end class {install("gf/expr",1,1);}
+
 void startup_classes4 () {
 	\startall
 }



More information about the Gridflow-cvs mailing list