?? ael.y
字號:
%{/* * Asterisk -- An open source telephony toolkit. * * Copyright (C) 2006, Digium, Inc. * * Steve Murphy <murf@parsetree.com> * * See http://www.asterisk.org for more information about * the Asterisk project. Please do not directly contact * any of the maintainers of this project for assistance; * the project provides a web site, mailing lists and IRC * channels for your use. * * This program is free software, distributed under the terms of * the GNU General Public License Version 2. See the LICENSE file * at the top of the source tree. *//*! \file * * \brief Bison Grammar description of AEL2. * */#include "asterisk.h"ASTERISK_FILE_VERSION(__FILE__, "$Revision: 153743 $")#include <stdio.h>#include <stdlib.h>#include <string.h>#include "asterisk/logger.h"#include "asterisk/lock.h"#include "asterisk/hashtab.h"#include "asterisk/ael_structs.h"#include "asterisk/utils.h"extern struct ast_flags ast_compat;pval * linku1(pval *head, pval *tail);static void set_dads(pval *dad, pval *child_list);void reset_parencount(yyscan_t yyscanner);void reset_semicount(yyscan_t yyscanner);void reset_argcount(yyscan_t yyscanner ); #define YYLEX_PARAM ((struct parse_io *)parseio)->scanner#define YYERROR_VERBOSE 1extern char *my_file;#ifdef AAL_ARGCHECKint ael_is_funcname(char *name);#endifstatic char *ael_token_subst(const char *mess);static int only_one_app_set_warning = 0;%}%union { int intval; /* integer value, typically flags */ char *str; /* strings */ struct pval *pval; /* full objects */}%{ /* declaring these AFTER the union makes things a lot simpler! */void yyerror(YYLTYPE *locp, struct parse_io *parseio, char const *s);int ael_yylex (YYSTYPE * yylval_param, YYLTYPE * yylloc_param , void * yyscanner);/* create a new object with start-end marker */pval *npval(pvaltype type, int first_line, int last_line, int first_column, int last_column);/* create a new object with start-end marker, simplified interface. * Must be declared here because YYLTYPE is not known before */static pval *npval2(pvaltype type, YYLTYPE *first, YYLTYPE *last);/* another frontend for npval, this time for a string */static pval *nword(char *string, YYLTYPE *pos);/* update end position of an object, return the object */static pval *update_last(pval *, YYLTYPE *);%}%token KW_CONTEXT LC RC LP RP SEMI EQ COMMA COLON AMPER BAR AT%token KW_MACRO KW_GLOBALS KW_IGNOREPAT KW_SWITCH KW_IF KW_IFTIME KW_ELSE KW_RANDOM KW_ABSTRACT KW_EXTEND%token EXTENMARK KW_GOTO KW_JUMP KW_RETURN KW_BREAK KW_CONTINUE KW_REGEXTEN KW_HINT%token KW_FOR KW_WHILE KW_CASE KW_PATTERN KW_DEFAULT KW_CATCH KW_SWITCHES KW_ESWITCHES%token KW_INCLUDES KW_LOCAL%right BAR COMMA%token <str> word%type <pval>includes%type <pval>includeslist%type <pval>switchlist%type <pval>eswitches%type <pval>switches%type <pval>macro_statement%type <pval>macro_statements%type <pval>case_statement%type <pval>case_statements%type <pval>eval_arglist%type <pval>application_call%type <pval>application_call_head%type <pval>macro_call%type <pval>target jumptarget%type <pval>statement%type <pval>switch_statement%type <pval>if_like_head%type <pval>statements%type <pval>extension%type <pval>ignorepat%type <pval>element%type <pval>elements%type <pval>arglist%type <pval>assignment%type <pval>local_assignment%type <pval>global_statements%type <pval>globals%type <pval>macro%type <pval>context%type <pval>object%type <pval>objects%type <pval>file/* XXX lr changes */%type <pval>opt_else%type <pval>timespec%type <pval>included_entry%type <str>opt_word%type <str>context_name%type <str>timerange%type <str>goto_word%type <str>word_list%type <str>word3_list hint_word%type <str>test_expr%type <str>opt_pri%type <intval>opt_abstract/* * OPTIONS */%locations /* track source location using @n variables (yylloc in flex) */%pure-parser /* pass yylval and yylloc as arguments to yylex(). */%name-prefix="ael_yy"/* * add an additional argument, parseio, to yyparse(), * which is then accessible in the grammar actions */%parse-param {struct parse_io *parseio}/* there will be two shift/reduce conflicts, they involve the if statement, where a single statement occurs not wrapped in curlies in the "true" section the default action to shift will attach the else to the preceeding if. */%expect 3%error-verbose/* * declare destructors for objects. * The former is for pval, the latter for strings. * NOTE: we must not have a destructor for a 'file' object. */%destructor { destroy_pval($$); prev_word=0; } includes includeslist switchlist eswitches switches macro_statement macro_statements case_statement case_statements eval_arglist application_call application_call_head macro_call target jumptarget statement switch_statement if_like_head statements extension ignorepat element elements arglist assignment local_assignment global_statements globals macro context object objects opt_else timespec included_entry%destructor { free($$);} word word_list goto_word word3_list opt_word context_name timerange test_expr opt_pri%%file : objects { $$ = parseio->pval = $1; } ;objects : object {$$=$1;} | objects object { $$ = linku1($1, $2); } | objects error {$$=$1;} ;object : context {$$=$1;} | macro {$$=$1;} | globals {$$=$1;} | SEMI {$$=0;/* allow older docs to be read */} ;context_name : word { $$ = $1; } | KW_DEFAULT { $$ = strdup("default"); } ;context : opt_abstract KW_CONTEXT context_name LC elements RC { $$ = npval2(PV_CONTEXT, &@1, &@6); $$->u1.str = $3; $$->u2.statements = $5; set_dads($$,$5); $$->u3.abstract = $1;} ;/* optional "abstract" keyword XXX there is no regression test for this */opt_abstract: KW_ABSTRACT { $$ = 1; } | /* nothing */ { $$ = 0; } | KW_EXTEND { $$ = 2; } | KW_EXTEND KW_ABSTRACT { $$=3; } | KW_ABSTRACT KW_EXTEND { $$=3; } ;macro : KW_MACRO word LP arglist RP LC macro_statements RC { $$ = npval2(PV_MACRO, &@1, &@8); $$->u1.str = $2; $$->u2.arglist = $4; $$->u3.macro_statements = $7; set_dads($$,$7);} ;globals : KW_GLOBALS LC global_statements RC { $$ = npval2(PV_GLOBALS, &@1, &@4); $$->u1.statements = $3; set_dads($$,$3);} ;global_statements : { $$ = NULL; } | assignment global_statements {$$ = linku1($1, $2); } | error global_statements {$$=$2;} ;assignment : word EQ { reset_semicount(parseio->scanner); } word SEMI { $$ = npval2(PV_VARDEC, &@1, &@5); if (!ast_compat_app_set && !only_one_app_set_warning && strchr($4,'"')) { ast_log(LOG_NOTICE,"Note: In asterisk.conf, in the [compat] section, the app_set is set to 1.6 or greater. The Set() function no longer removes double quotes from the value. If this is a surprise to you, you can set app_set to 1.4.\n"); only_one_app_set_warning = 1; } $$->u1.str = $1; $$->u2.val = $4; } ;local_assignment : KW_LOCAL word EQ { reset_semicount(parseio->scanner); } word SEMI { $$ = npval2(PV_LOCALVARDEC, &@1, &@6); $$->u1.str = $2; $$->u2.val = $5; } ;/* XXX this matches missing arguments, is this desired ? */arglist : /* empty */ { $$ = NULL; } | word { $$ = nword($1, &@1); } | arglist COMMA word { $$ = linku1($1, nword($3, &@3)); } | arglist error {$$=$1;} ;elements : {$$=0;} | element elements { $$ = linku1($1, $2); } | error elements { $$=$2;} ;element : extension {$$=$1;} | includes {$$=$1;} | switches {$$=$1;} | eswitches {$$=$1;} | ignorepat {$$=$1;} | assignment {$$=$1;} | local_assignment {$$=$1;} | word error {free($1); $$=0;} | SEMI {$$=0;/* allow older docs to be read */} ;ignorepat : KW_IGNOREPAT EXTENMARK word SEMI { $$ = npval2(PV_IGNOREPAT, &@1, &@4); $$->u1.str = $3;} ;extension : word EXTENMARK statement { $$ = npval2(PV_EXTENSION, &@1, &@3); $$->u1.str = $1; $$->u2.statements = $3; set_dads($$,$3);} | word AT word EXTENMARK statement { $$ = npval2(PV_EXTENSION, &@1, &@3); $$->u1.str = malloc(strlen($1)+strlen($3)+2); strcpy($$->u1.str,$1); strcat($$->u1.str,"@"); strcat($$->u1.str,$3); free($1); $$->u2.statements = $5; set_dads($$,$5);} | KW_REGEXTEN word EXTENMARK statement { $$ = npval2(PV_EXTENSION, &@1, &@4); $$->u1.str = $2; $$->u2.statements = $4; set_dads($$,$4); $$->u4.regexten=1;} | KW_HINT LP hint_word RP word EXTENMARK statement { $$ = npval2(PV_EXTENSION, &@1, &@7); $$->u1.str = $5; $$->u2.statements = $7; set_dads($$,$7); $$->u3.hints = $3;} | KW_REGEXTEN KW_HINT LP hint_word RP word EXTENMARK statement { $$ = npval2(PV_EXTENSION, &@1, &@8); $$->u1.str = $6; $$->u2.statements = $8; set_dads($$,$8); $$->u4.regexten=1; $$->u3.hints = $4;} ;/* list of statements in a block or after a case label - can be empty */statements : /* empty */ { $$ = NULL; } | statement statements { $$ = linku1($1, $2); } | error statements {$$=$2;} ;/* hh:mm-hh:mm, due to the way the parser works we do not * detect the '-' but only the ':' as separator */timerange: word3_list COLON word3_list COLON word3_list { if (asprintf(&$$, "%s:%s:%s", $1, $3, $5) < 0) { ast_log(LOG_WARNING, "asprintf() failed\n"); $$ = NULL; } else { free($1); free($3); free($5); } } | word { $$ = $1; } ;/* full time specification range|dow|*|* */timespec : timerange BAR word3_list BAR word3_list BAR word3_list { $$ = nword($1, &@1); $$->next = nword($3, &@3); $$->next->next = nword($5, &@5); $$->next->next->next = nword($7, &@7); } ;/* expression used in if, random, while, switch */test_expr : LP { reset_parencount(parseio->scanner); } word_list RP { $$ = $3; } ;/* 'if' like statements: if, iftime, random */if_like_head : KW_IF test_expr { $$= npval2(PV_IF, &@1, &@2); $$->u1.str = $2; } | KW_RANDOM test_expr { $$ = npval2(PV_RANDOM, &@1, &@2); $$->u1.str=$2;} | KW_IFTIME LP timespec RP { $$ = npval2(PV_IFTIME, &@1, &@4); $$->u1.list = $3; prev_word = 0; } ;/* word_list is a hack to fix a problem with context switching between bison and flex; by the time you register a new context with flex, you've already got a look-ahead token from the old context, with no way to put it back and start afresh. So, we kludge this and merge the words back together. */word_list : word { $$ = $1;} | word word { if (asprintf(&($$), "%s%s", $1, $2) < 0) { ast_log(LOG_WARNING, "asprintf() failed\n"); $$ = NULL; } else { free($1); free($2); prev_word = $$; } } ;hint_word : word { $$ = $1; } | hint_word word { if (asprintf(&($$), "%s %s", $1, $2) < 0) { ast_log(LOG_WARNING, "asprintf() failed\n"); $$ = NULL; } else { free($1); free($2); } } | hint_word COLON word { if (asprintf(&($$), "%s:%s", $1, $3) < 0) { ast_log(LOG_WARNING, "asprintf() failed\n"); $$ = NULL; } else { free($1); free($3); } } | hint_word AMPER word { /* there are often '&' in hints */ if (asprintf(&($$), "%s&%s", $1, $3) < 0) { ast_log(LOG_WARNING, "asprintf() failed\n"); $$ = NULL; } else { free($1); free($3); } } ;word3_list : word { $$ = $1;} | word word { if (asprintf(&($$), "%s%s", $1, $2) < 0) { ast_log(LOG_WARNING, "asprintf() failed\n"); $$ = NULL; } else { free($1); free($2); prev_word = $$; } } | word word word { if (asprintf(&($$), "%s%s%s", $1, $2, $3) < 0) { ast_log(LOG_WARNING, "asprintf() failed\n"); $$ = NULL; } else { free($1); free($2); free($3); prev_word=$$; } } ;goto_word : word { $$ = $1;} | word word { if (asprintf(&($$), "%s%s", $1, $2) < 0) { ast_log(LOG_WARNING, "asprintf() failed\n"); $$ = NULL; } else { free($1); free($2); }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -