[asterisk-commits] murf: branch murf/fast-ast r41164 - in /team/murf/fast-ast: GOALS main/ast_var.y

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Aug 25 20:23:02 MST 2006


Author: murf
Date: Fri Aug 25 22:23:01 2006
New Revision: 41164

URL: http://svn.digium.com/view/asterisk?rev=41164&view=rev
Log:
Changed goals just a bit.
After actually studying the code to evaluate
variable references, I've jotted down some basic
syntax for them. And modified my goals a little.
I'm now thinking about merging $[] and ${} into
a master string expr sort of thing... SNOBOL, anyone? 
(Just kidding!). I'm leaning toward preserving 
current syntax as much as possible.


Added:
    team/murf/fast-ast/main/ast_var.y   (with props)
Modified:
    team/murf/fast-ast/GOALS

Modified: team/murf/fast-ast/GOALS
URL: http://svn.digium.com/view/asterisk/team/murf/fast-ast/GOALS?rev=41164&r1=41163&r2=41164&view=diff
==============================================================================
--- team/murf/fast-ast/GOALS (original)
+++ team/murf/fast-ast/GOALS Fri Aug 25 22:23:01 2006
@@ -1,6 +1,16 @@
 Steps to speeding up the Asterisk dialplan engine:
 
 1. A 'formal' parser for ${ } expressions, with a parse-tree representation.
+   Goals change a bit... the current method repetitively scans the string
+   for ${} and $[] occurrences, and finds the matching closing bracket, and
+   recursively processes it until all such exprs are cut out, evaluated,
+   and the results pasted in their place.
+
+   After sitting and thinking a bit, for the sake of speedup, I'm going
+   to unify these two parsers into a single entity. Sorry, but what I'm
+   thinking about right now, is not exactly compatible with the current
+   syntax, which reminds me a bit of sh. This is OK for interpreters, but
+   I want something faster than that... we need to bind earlier. Sorry.
 
 2. See how much of a speedup from  hash-table for func/app names.
 
@@ -15,4 +25,4 @@
    structs, or, we can traverse the dialplan and remove ptrs associated with the
    removed app.
 
-4. Profit.
+4. Profit!!!!

Added: team/murf/fast-ast/main/ast_var.y
URL: http://svn.digium.com/view/asterisk/team/murf/fast-ast/main/ast_var.y?rev=41164&view=auto
==============================================================================
--- team/murf/fast-ast/main/ast_var.y (added)
+++ team/murf/fast-ast/main/ast_var.y Fri Aug 25 22:23:01 2006
@@ -1,0 +1,135 @@
+%{
+#include "asterisk.h"
+
+#ifndef STANDALONE
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+#endif
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <locale.h>
+#include <unistd.h>
+#include <ctype.h>
+#if !defined(SOLARIS) && !defined(__CYGWIN__)
+#include <err.h>
+#else
+#define quad_t int64_t
+#endif
+#include <errno.h>
+#include <regex.h>
+#include <limits.h>
+
+
+enum parttype {
+	PART_VARREF = 1,
+	PART_FUNC = 2,
+	PART_VARNAME = 3,
+	PART_SUBSTR = 4,
+	PART_STR = 5
+};
+
+
+
+struct part {
+	enum parttype type;
+
+	/* fields for VARREF:
+	   u1: name (func or varname or varref)
+	   u2: substr
+	   
+	   FUNC:
+	   u1: ref (func or varname or varref)
+	   u2: arglist
+	   u3: substr
+
+	   VARNAME:
+	   u1: ref (func or varname or varref)
+	   u2: substr
+
+	   STR:
+	   u1: string (char*) -- constant
+
+	   SUBSTR
+	   u1: offset  --- NOTE: these can be exprs to! 
+	   u2: length
+	*/
+
+	union 
+	{
+		struct part *name;
+		struct part *ref;
+		char *string;
+		int offset;
+	} u1;
+
+	union 
+	{
+		struct part *substr;
+		struct part *arglist;
+		int length;
+	} u2;
+
+	union 
+	{
+		struct part *substr;
+	} u2;
+	
+	struct part *next; /* to next arg */
+};
+
+struct part *new_part(enum parttype type);
+
+%}
+
+
+%union 
+{
+	struct part *part;
+}
+	 
+
+
+
+%left <part> DOLL LCURLY RCURLY LPAR RPAR COLON COMMA
+%left <part> Name Num
+
+%type <part> varref thing substr args arg 
+
+%%
+
+varref : DOLL LCURLY  thing RCURLY {}
+       ;
+
+
+thing : varref substr {$$=new_part(PART_VARNAME);$$->u1.ref=$1;}
+      | arg substr {$$=new_part(PART_VARNAME);$$->u1.ref=$1;$$->}
+      | arg LPAR args RPAR substr {$$=new_part(PART_FUNC);$$->u1.ref=$1; $$->u2.arglist=$3;}
+      | arg LPAR RPAR substr {$$=new_part(PART_FUNC);$$->u1.ref=$1; $$->u2.arglist=0; }
+      ;
+
+substr : /* nothing */ { $$ = 0; }
+       | COLON Num {$$ = new_part(PART_SUBSTR); $$->u1.offset = $2; $$->u2.length = MAX_INT;}
+       | COLON Num COLON Num {$$ = new_part(PART_SUBSTR); $$->u1.offset = $2; $$->u2.length = $4;}
+       ;
+
+args : arg {$$=$1;}
+     | args COMMA arg { $$=$1; $$->next = $3;}
+	 ;
+
+arg : Name {$$=new_part(PART_STR); $$->u1.string=$1;}
+    | Num {char numbuf[40]; $$=new_part(PART_STR); sprintf(numbuf,"%d",$1); $$->u1.string=strdup(numbuf);}
+	| varref {$$=$1;}
+    ;
+
+
+
+%%
+
+struct part *new_part(enum parttype type)
+{
+	struct part *x = (struct part *)calloc(1,sizeof(struct part));
+	x->type = type;
+	return x;
+}

Propchange: team/murf/fast-ast/main/ast_var.y
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/murf/fast-ast/main/ast_var.y
------------------------------------------------------------------------------
    svn:keywords = Author Id Date Revision

Propchange: team/murf/fast-ast/main/ast_var.y
------------------------------------------------------------------------------
    svn:mime-type = text/plain



More information about the asterisk-commits mailing list