ã ãã ãç¶ãã¾ã
æ
æãå¤ã
é¢æ°å¼ã³åºããæï¼ï¼
statement : sub_call { $$ = gb_stmt_new_call (buffer, $1) } | object_list '=' expr { $$ = gb_stmt_new_assignment (buffer, $1, $3); } | dim_statement { $$ = NULL; } | static_statement { $$ = NULL; } | GB_REDIM { gb_parse_data_inside_dim (buffer); } opt_preserve var_name '(' subscripts ')' { gb_parse_data_dim_finish (buffer); $$ = gb_stmt_new_redim (buffer, $4, $6, $3); } | GB_ERASE var_name { $$ = gb_stmt_new_erase (buffer, $2); } | GB_SET object_list '=' opt_new object_list { $$ = gb_stmt_new_set (buffer, $2, $4, $5); } | GB_ON GB_ERROR on_error { $$ = $3; } | GB_EXIT nesting { $$ = gb_stmt_new_exit (buffer, $2); } | GB_DO opt_while_until eostmt statements GB_LOOP opt_while_until { $$ = gb_stmt_new_do_while (buffer, $2, $6, $4); } | GB_SELECT GB_CASE expr eostmt case_stmts GB_END GB_SELECT { $$ = gb_stmt_new_select (buffer, $3, $5); } | GB_WHILE expr eostmt statements GB_WEND { $$ = gb_stmt_new_do_while (buffer, $2, NULL, $4); } | GB_FOR NAME '=' expr GB_TO expr opt_step eostmt statements GB_NEXT opt_name /* TODO : add check for NAME == opt_name */ { $$ = gb_stmt_new_forloop (buffer, $2, $4, $6, $7, $9); } | GB_FOR GB_EACH NAME GB_IN object_list eostmt statements GB_NEXT opt_name /* TODO : add check for NAME == opt_name */ { $$ = gb_stmt_new_foreach (buffer, $3, $5, $7); } | GB_WITH object_list eostmt { gb_module_with_depth_inc (buffer, $2); } statements GB_END GB_WITH { $$ = gb_stmt_new_with (buffer, $2, $5); } | GB_IF expr GB_THEN if_body { $$ = gb_stmt_if_set_cond ((GBStatement *)$4, $2); } | GB_BEEP { $$ = NULL; } | GB_DATE '=' expr { $$ = NULL; } | GB_RANDOMIZE opt_expr { $$ = gb_stmt_new_randomize (buffer, $2); } | GB_LOAD expr { $$ = gb_stmt_new_load (buffer, $2); } | GB_UNLOAD expr { $$ = gb_stmt_new_unload (buffer, $2); } /* THIS LOOKS EXTREMELY BROKEN ! */ | object_refs '.' GB_LINE '(' expr ',' expr ')' '-' opt_line_step '(' expr ',' expr ')' ',' expr ',' expr { } | object_refs '.' GB_LINE '(' expr ',' expr ')' '-' opt_line_step '(' expr ',' expr ')' ',' expr { } | object_refs '.' GB_SCALE '(' expr ',' expr ')' '-' '(' expr ',' expr ')' { } /* File handling related statements */ | GB_OPEN expr GB_FOR open_mode GB_AS expr opt_open_len { $$ = gb_stmt_new_open (buffer, $2, $4, $6, $7); } | GB_OPEN expr GB_FOR open_mode GB_AS '#' expr opt_open_len { $$ = gb_stmt_new_open (buffer, $2, $4, $7, $8); } | GB_INPUT '#' expr ',' expr_csv { $$ = gb_stmt_new_input (buffer, $3, $5); } | GB_LINE GB_INPUT '#' expr ',' expr { $$ = gb_stmt_new_line_input (buffer, $4, $6); } | GB_CLOSE expr_csv { $$ = gb_stmt_new_close (buffer, $2); } | GB_CLOSE handles { $$ = gb_stmt_new_close (buffer, $2); } | GB_GET '#' expr ',' opt_expr ',' expr { $$ = gb_stmt_new_get (buffer, $3, $5, $7); } | GB_PUT '#' expr ',' opt_expr ',' expr { $$ = gb_stmt_new_put (buffer, $3, $5, $7); } | GB_SEEK '#' expr ',' expr { $$ = gb_stmt_new_seek (buffer, $3, $5); } | GB_PRINT '#' expr ',' expr_csv { $$ = gb_stmt_new_print (buffer, $3, $5); } /* End of File handling related statements */ | GB_GOTO NAME { $$ = gb_stmt_new_goto (buffer, $2); } | GB_GOTO_LABEL { $$ = gb_stmt_new_label (buffer, $1); } ;
å¼
expr : value { $$ = gb_expr_new_value ($1); } | object_list { $$ = $1; } | '+' expr { $$ = gb_expr_new_unary (GB_EXPR_POSITIVE, $2);} | '-' expr { $$ = gb_expr_new_unary (GB_EXPR_NEGATIVE, $2);} | GB_NOT expr { $$ = gb_expr_new_unary (GB_EXPR_NOT, $2);} | '(' expr ')' { $$ = gb_expr_new_unary (GB_EXPR_PAREN, $2); } | expr '&' expr { $$ = gb_expr_new_binary ($1, GB_EXPR_CONCAT, $3); } | expr GB_AND expr { $$ = gb_expr_new_binary ($1, GB_EXPR_AND, $3); } | expr GB_OR expr { $$ = gb_expr_new_binary ($1, GB_EXPR_OR, $3); } | expr GB_XOR expr { $$ = gb_expr_new_binary ($1, GB_EXPR_XOR, $3); } | expr '>' expr { $$ = gb_expr_new_binary ($1, GB_EXPR_GT, $3); } | expr GB_GE expr { $$ = gb_expr_new_binary ($1, GB_EXPR_GE, $3); } | expr '=' expr { $$ = gb_expr_new_binary ($1, GB_EXPR_EQ, $3); } | expr GB_IS expr { $$ = gb_expr_new_binary ($1, GB_EXPR_EQ, $3); } | expr GB_NE expr { $$ = gb_expr_new_binary ($1, GB_EXPR_NE, $3); } | expr GB_LE expr { $$ = gb_expr_new_binary ($1, GB_EXPR_LE, $3); } | expr '<' expr { $$ = gb_expr_new_binary ($1, GB_EXPR_LT, $3); } | expr '-' expr { $$ = gb_expr_new_binary ($1, GB_EXPR_SUB, $3); } | expr '+' expr { $$ = gb_expr_new_binary ($1, GB_EXPR_ADD, $3); } | expr '*' expr { $$ = gb_expr_new_binary ($1, GB_EXPR_MULT, $3); } | expr '/' expr { $$ = gb_expr_new_binary ($1, GB_EXPR_DIV, $3); } | expr '''' expr { $$ = gb_expr_new_binary ($1, GB_EXPR_INT_DIV, $3); } | expr '^' expr { $$ = gb_expr_new_binary ($1, GB_EXPR_POW, $3); } | expr GB_EQV expr { $$ = gb_expr_new_binary ($1, GB_EXPR_EQV, $3); } | expr GB_IMP expr { $$ = gb_expr_new_binary ($1, GB_EXPR_IMP, $3); } ;
以ä¸ã®ãããªé¢æ°å¼ã³åºãã¯
func(a)
- method_array_ref
- object_ref
- object_refs
- object_list
- expr
ã¨ãã風ã«ãªãã¥ã¼ã¹ãããã®ã§ãå¼ã®ä¸ã«é¢æ°å¼ã³åºããæ¸ããã
method_array_ref : GB_OBJ_NAME_LPAR opt_parms ')' { $$ = gb_obj_ref_new ($1, TRUE, $2); } ; object_ref : prop_ref { $$ = $1; } | method_array_ref { $$ = $1; } ; object_refs : object_refs '.' object_ref { $$ = g_slist_prepend ($1, $3); } | object_refs '!' obj_name { $$ = g_slist_prepend ($1, gb_obj_ref_new (NULL, TRUE, g_slist_prepend (NULL, (gpointer) gb_expr_new_string ($3)))); } | object_ref { $$ = g_slist_prepend (NULL, $1); } | GB_SPACE_DOT object_ref { $$ = g_slist_prepend (NULL, $2); } ; object_list : object_refs { $$ = gb_expr_new_obj_list ($1); } ;
åã調ã¹ã
TypeName ã使ãã¾ã
alert(TypeName(document.createElement("div")))
é¢æ°å®£è¨ãã¦ããä»£å ¥ã¯ãã¡
dim_statement ã®å®ç¾©ã以ä¸ã®ããã«ãªã£ã¦ããã®ã§ã
dim_statement : GB_DIM { gb_parse_data_inside_dim (buffer); } var_decls { gb_parse_data_dim_finish (buffer); } ; var_decls : var_decls ',' var_decl | var_decl ; var_decl : opt_events var_name opt_subscripts dim_type { gb_parse_data_add_var (buffer, gb_var_new ($2, $4.as_new, $3.is_array, $3.indices, $4.name)); }
DIm elm = document.createElement("div")
ãªã©ã¯ãææ³ã¨ã©ã¼
ä»£å ¥ã¯æï¼ããããã¢ãï¼
代å
¥ã¯æãªã®ã§ã以ä¸ã®ããã«ã¯æ¸ãã¾ããã
ã¨ãæãããæ¸ãã¾ãã
a = b = 1
- æåã®ã¤ã³ã¼ã«ã¯ãä»£å ¥æã®ä¸é¨ã¨ãã¦è©ä¾¡ããã
- 次ã®ã¤ã³ã¼ã«ã¯æ¯è¼å¼ã®ã¤ã³ã¼ã«ã¨ãã¦è©ä¾¡ããã¾ãã
ã¤ã¾ãã b 㨠1 ãæ¯è¼ããçµæã a ã«ä»£å ¥ããã¨ãããã¨ã«ãªãã¾ãã
ãªãã¸ã§ã¯ãã®ä»£å ¥ã ãã¯ç¹æ®
以ä¸ã®ããã«ãªãã¸ã§ã¯ããä»£å ¥æã§ä»£å ¥ããã¨ãã¯æ³¨æãå¿ è¦ã§ãã
Dim elm elm = document.createElement("div")
ããããã㨠elm ã« "[object]" ã¨ããæååã代å
¥ããã¾ãã
JavaScript çã«è¨ãã¨ãªãã¸ã§ã¯ãã¯é常ã®ä»£å
¥æã« valueOf ãå¼ã³åºããã¦ãã¾ãã®ã§ããã
ãªã®ã§ããªãã¸ã§ã¯ãåã®å¤ã代å
¥ããå ´åã«éã£ã¦ Set ãå¿
è¦ã«ãªãã¾ãã
Dim elm Set elm = document.createElement("div")
ããã Set æï¼Set ã¹ãã¼ãã¡ã³ãï¼ã¨ããã¾ãã
http://msdn.microsoft.com/ja-jp/library/cc392465.aspx
ã³ã¡ã³ã
' ã³ã¡ã³ãã¯ã¢ãã¹ãããã£
æã®åºåã
æã®åºåãã¯æ¹è¡
alert(0) alert(1) alert(2)
ã¾ãã¯ãã³ãã³
alert(0): alert(1): alert(2)
è¿ãå¤
' 1 ã足ãã¦è¿ã ' é¢æ°ã¨åãååã®å¤æ°ã«ä»£å ¥ãã Function succ(a) succ = a + 1 End Function alert(succ(succ(0))) ' 2
' return ã®ããã«é¢æ°ã®æå¾ãããªãã¦ããã Function succ(a) succ = a + 1 alert(succ) End Function alert(succ(succ(0))) ' 2
Sub 㨠Function ã¯åã風ã«ä½¿ããããã Sub ã«ã¯è¿ãå¤ã®æ©è½ã¯ãªã
é¢æ°å¼ã³åºãã® () ã¯çç¥ OK
é¢æ°åã®ã·ã³ãã«ãå¼ã®ä¸ã§è©ä¾¡ãããã¨é¢æ°ã¯å¼æ°ãªãã§å¼ã³åºããã
ãããã¸ã㯠Perl ã¨åã
Function foo: alert(0): End Function foo ' foo() 㨠foo ã¯åã Function bar(a): alert(a): End Function bar 1 ' bar(1) ã¨åã a = foo ' foo ã®è¿ãå¤ã a ã«ä»£å ¥
é¢æ°ã®å®£è¨æã¯ãä»£å ¥æãå¼æããå ã«å®è¡ããã
foo Function foo: alert(0): End Function
ãã㯠JavaScript ã¨åã
Eval 㨠Execute ã®éã
Eval ã¯å¼ã®è©ä¾¡ Execute ã¯æã®è©ä¾¡ãè¡ãã
ãããã Eval ã¯å¼ï¼é¢æ°ï¼ã§ Execute ã¯æï¼å¤ã¯æããªãï¼ã
' Eval ã¯å¼ã¨ãã¦è©ä¾¡ããã®ã§ a = 1 ã¯æ¯è¼å¼ã«ãªã Eval("a = 1") ' Eval èªèº«ãå¼ãªã®ã§å¤ãæ㤠alert(Eval("1 = 1")) ' True ' Execute ã¯å¼ã¨ãã¦è©ä¾¡ããã®ã§ a = 1 ã¯ä»£å ¥æã«ãªã Execute "a = 1" ' è¤æ°ã®æãä¸ã¤ã® Execute ã§å®è¡ã§ãã Execute "dim a: a = 1: alert(a)" ' Execute èªèº«ãå¼ãªã®ã§æã®éä¸ã«ã¯æ¸ããªã ' alert(Execute("a = 1")) ã¯ã¨ã©ã¼
Execute ã使ãã¨åçã«é¢æ°ã宣è¨ã§ãã
Execute "Function foo: alert(1): End Function"
é¢æ°ãå¤ã¨ãã¦ä½¿ã
GetRef ã使ã
Function foo: alert(1): End Function Dim bar Set bar = GetRef("foo") ' é¢æ°åãæååã§æå®ãã bar() ' ãã㯠() ã®çç¥ãã§ããªããçç¥ãã¦ãå®è¡ãããªãã alert(TypeName(bar))
JavaScript ããè¦ã VBScript ã®é¢æ°
<script language="vbscript" type="text/vbscript"> Function foo foo = 1 End Function </script> <script language="javascript" type="text/javascript"> alert(foo()); // å¼ã³åºãã alert(typeof foo); // unknown alert(typeof window.foo); // unknown try { var bar = foo; // ããã¯ã¨ã©ã¼ã«ãªã } catch(e) { alert(e.message); } </script>
ããã§ã¯ä¸ä¾¿ãããã®ã§ã GetRef ãã¦ããã¨æ®éã® JavaScript ã®é¢æ°ã®ããã«æ±ãã
<script language="vbscript" type="text/vbscript"> Function foo_ foo_ = 1 End Function Dim foo Set foo = GetRef("foo_") </script> <script language="javascript" type="text/javascript"> alert(foo()) alert(typeof foo); // object alert(typeof window.foo); // object try { var bar = foo; // ãããã¨ã©ã¼ã«ãªããªã alert(bar()); alert(bar.apply); // ã ãã© apply ãªã©ã® Function.prototype ã«ä¾åãããã®ã¯æã£ã¦ããªã } catch(e) { alert(e.message); } </script>
VBScript ããè¦ã JavaScript ã®é¢æ°
<script language="javascript" type="text/javascript"> function foo() { return 1 } </script> <script language="vbscript" type="text/vbscript"> ' JavaScript ã®é¢æ°ã¯ã¡ããã© GetRef ããã VBScript ã®é¢æ°ã¨åãæ±ãã«ãªã alert(foo) ' å¼ã³åºãããªã alert(foo()) ' å¼ã³åºããã Dim bar Set bar = foo ' ä»£å ¥å¯è½ alert(bar) alert(bar()) </script>
ã¯ã©ã¹
ãªãããããã©ããªã£ã¦ããã®ã§åãã¨ããã ãw
ã²ãã¿ã¼(Get) ã»ãã¿ã¼(Set/Let)
Class Foo Property Let foo(a): alert("Let " + TypeName(a)): End Property Property Set foo(a): alert("Set " + TypeName(a)): End Property Property Get foo: foo = 1: End Property End Class
Let ã¯æ®éã®ä»£å ¥æã Set 㯠Set æ
Dim f Set f = new Foo f.foo = "hoge" 'Let ãå¼ã°ãã Set f.foo = "hoge" ' Set ãå¼ã°ãã alert(f.foo) ' Get ãå¼ã°ãã
JavaScript ããã使ãã
alert(f.foo); // Get ãå¼ã°ãã f.foo = "hoge"; // æååã 㨠Let ãå¼ã°ãã f.foo = {}; // ãªãã¸ã§ã¯ãã 㨠Set ãå¼ã°ãã
Public Default
ãªãã¸ã§ã¯ãã Callable ã«ãã
<script language="vbscript" type="text/vbscript"> Class Foo Public Default Function item(a, b, c) alert(a) alert(b) alert(c) item = "fuga" End Function End Class alert(1) Dim bar Set bar = New Foo alert(bar(1, 2, 3)) </script> <script language="javascript" type="text/javascript"> alert(bar(1, 2, 3));
Setter ã Getter ã¨ã Callable 㯠JScript ããã¯åºæ¥ãªãã®ã§éå®ãããã