⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 yabasic.bison

📁 Linux下VB解释器
💻 BISON
📖 第 1 页 / 共 3 页
字号:
%{/*    YABASIC ---  a simple Basic Interpreter    written by Marc-Oliver Ihm 1995-2005    homepage: www.yabasic.de    BISON part         This file is part of yabasic and may be copied only     under the terms of either the Artistic License or     the GNU General Public License (GPL), both of which     can be found at www.yabasic.de*/#ifndef YABASIC_INCLUDED#include "yabasic.h"     /* definitions of yabasic */#endif#ifdef WINDOWS#include <malloc.h>#else#ifdef HAVE_MALLOC_H#include <malloc.h>#else#include <stdlib.h>#endif#endif#if HAVE_ALLOCA_H#ifndef WINDOWS#include <alloca.h>#endif#endifvoid __yy_bcopy(char *,char *,int); /* prototype missing */int tileol; /* true, read should go to eon of line */int yylineno=1; /* line number; counts fresh in every new file */int main_lineno=1; /* line number of main */int function_type=ftNONE; /* contains function type while parsing function */char *current_function=NULL; /* name of currently parsed function */int exported=FALSE; /* true, if function is exported */int yylex(void);extern struct libfile_name *current_libfile; /*  defined in main.c: name of currently parsed file */int missing_endif=0;int missing_endif_line=0;int missing_endsub=0;int missing_endsub_line=0;int missing_next=0;int missing_next_line=0;int missing_wend=0;int missing_wend_line=0;int missing_until=0;int missing_until_line=0;int missing_loop=0;int missing_loop_line=0;int in_loop=0;void report_missing(int severity,char *text) {  if (missing_loop || missing_endif || missing_next || missing_until || missing_wend) {    error(severity,text);    string[0]='\0';    if (missing_endif)      sprintf(string,"if statement starting at line %d has seen no 'endif' yet",missing_endif_line);    else if (missing_next)      sprintf(string,"for-loop starting at line %d has seen no 'next' yet",missing_next_line);    else if (missing_wend)      sprintf(string,"while-loop starting at line %d has seen no 'wend' yet",missing_wend_line);    else if (missing_until)      sprintf(string,"repeat-loop starting at line %d has seen no 'until' yet",missing_until_line);    else if (missing_loop)      sprintf(string,"do-loop starting at line %d has seen no 'loop' yet",missing_wend_line);    if (string[0]) error(severity,string);  }}     %}%union {  double fnum;          /* double number */  int inum;             /* integer number */  int token;            /* token of command */  int sep;              /* number of newlines */  char *string;         /* quoted string */  char *symbol;         /* general symbol */  char *digits;         /* string of digits */  char *docu;		/* embedded documentation */}%type <fnum> const%type <fnum> number%type <symbol> symbol_or_lineno%type <symbol> function_name%type <symbol> function_or_array%type <symbol> stringfunction_or_array%type <sep> tSEP sep_list%token <fnum> tFNUM%token <symbol> tSYMBOL%token <symbol> tSTRSYM%token <symbol> tDOCU%token <digits> tDIGITS%token <string> tSTRING%token tFOR tTO tSTEP tNEXT tWHILE tWEND tREPEAT tUNTIL tIMPORT%token tGOTO tGOSUB tLABEL tON tSUB tENDSUB tLOCAL tSTATIC tEXPORT tERROR %token tEXECUTE tEXECUTE2 tCOMPILE tRUNTIME_CREATED_SUB%token tINTERRUPT tBREAK tCONTINUE tSWITCH tSEND tCASE tDEFAULT tLOOP tDO tSEP tEOPROG%token tIF tTHEN tELSE tELSIF tENDIF tUSING%token tPRINT tINPUT tLINE tRETURN tDIM tEND tEXIT tAT tSCREEN %token tREVERSE tCOLOUR tBACKCOLOUR%token tAND tOR tNOT tEOR%token tNEQ tLEQ tGEQ tLTN tGTN tEQU tPOW%token tREAD tDATA tRESTORE%token tOPEN tCLOSE tSEEK tTELL tAS tREADING tWRITING tORIGIN%token tWINDOW tDOT tLINE tCIRCLE tTRIANGLE tTEXT tCLEAR tFILL tPRINTER%token tWAIT tBELL tLET tARDIM tARSIZE tBIND%token tRECT tGETBIT tPUTBIT tGETCHAR tPUTCHAR tNEW tCURVE%token tSIN tASIN tCOS tACOS tTAN tATAN tEXP tLOG%token tSQRT tSQR tMYEOF tABS tSIG%token tINT tFRAC tMOD tRAN tLEN tVAL tLEFT tRIGHT tMID tLEN tMIN tMAX%token tSTR tINKEY tCHR tASC tHEX tDEC tBIN tUPPER tLOWER tMOUSEX tMOUSEY tMOUSEB tMOUSEMOD%token tTRIM tLTRIM tRTRIM tINSTR tRINSTR%token tSYSTEM tSYSTEM2 tPEEK tPEEK2 tPOKE %token tDATE tTIME tTOKEN tTOKENALT tSPLIT tSPLITALT tGLOB%left tOR%left tAND%left tNOT%left tNEQ%left tGEQ%left tLEQ%left tLTN%left tGTN%left tEQU%left '-' '+'%left '*' '/'%nonassoc UMINUS%left tPOW%%program: statement_list tEOPROG {YYACCEPT;}  ;statement_list: statement  | statement_list {if (errorlevel<=ERROR) {YYABORT;}}     tSEP {if ($3>=0) yylineno+=$3; else switchlib();} statement  ;statement:  /* empty */  | string_assignment   | tLET string_assignment   | assignment  | tLET assignment  | tIMPORT {report_missing(ERROR,"do not import a library in a loop or an if-statement");switchlib();}  | tERROR string_expression {add_command(cERROR,NULL);}  | for_loop   | switch_number_or_string  | repeat_loop  | while_loop  | do_loop  | tBREAK {add_command(cBREAK,NULL);if (!in_loop) error(ERROR,"break outside loop");}  | tCONTINUE {add_command(cCONTINUE,NULL);if (!in_loop) error(ERROR,"continue outside loop");}  | function_definition  | function_or_array {create_call($1);add_command(cPOP,NULL);}  | stringfunction_or_array {create_call($1);add_command(cPOP,NULL);}  | tLOCAL {if (function_type==ftNONE) error(ERROR,"no use for 'local' outside functions");} local_list  | tSTATIC {if (function_type==ftNONE) error(ERROR,"no use for 'static' outside functions");} static_list  | if_clause  | short_if  | tGOTO symbol_or_lineno {create_goto((function_type!=ftNONE)?dotify($2,TRUE):$2);}  | tGOSUB symbol_or_lineno {create_gosub((function_type!=ftNONE)?dotify($2,TRUE):$2);}  | tON tINTERRUPT tBREAK {create_exception(TRUE);}  | tON tINTERRUPT tCONTINUE {create_exception(FALSE);}  | tON expression tGOTO {add_command(cSKIPPER,NULL);}    goto_list {add_command(cNOP,NULL);}  | tON expression tGOSUB {add_command(cSKIPPER,NULL);}     gosub_list {add_command(cNOP,NULL);}  | tLABEL symbol_or_lineno {create_label((function_type!=ftNONE)?dotify($2,TRUE):$2,cLABEL);}  | open_clause {add_command(cCHECKOPEN,NULL);}  | tCLOSE hashed_number {add_command(cCLOSE,NULL);}  | seek_clause {add_command(cCHECKSEEK,NULL);}  | tCOMPILE string_expression {add_command(cCOMPILE,NULL);}  | tEXECUTE '(' call_list ')' {create_execute(0);add_command(cPOP,NULL);add_command(cPOP,NULL);}  | tEXECUTE2 '(' call_list ')' {create_execute(1);add_command(cPOP,NULL);add_command(cPOP,NULL);}  | tPRINT printintro printlist {create_colour(0);create_print('n');create_pps(cPOPSTREAM,0);}   | tPRINT printintro printlist ';' {create_colour(0);create_pps(cPOPSTREAM,0);}  | tPRINT printintro printlist ',' {create_colour(0);create_print('t');create_pps(cPOPSTREAM,0);}  | tINPUT {tileol=FALSE;} inputbody  | tLINE tINPUT {tileol=TRUE;} inputbody  | tCOLOUR expression ',' expression ',' expression {add_command(cGCOLOUR,NULL);}  | tCOLOUR string_expression {add_command(cGCOLOUR2,NULL);}  | tBACKCOLOUR expression ',' expression ',' expression {add_command(cGBACKCOLOUR,NULL);}  | tBACKCOLOUR string_expression {add_command(cGBACKCOLOUR2,NULL);}  | tREAD readlist  | tDATA datalist  | tRESTORE {create_restore("");}  | tRESTORE symbol_or_lineno {create_restore((function_type!=ftNONE)?dotify($2,TRUE):$2);}  | tRETURN {if (get_switch_id()) create_clean_switch_mark(0,TRUE);             if (function_type!=ftNONE) {	       add_command(cCLEARREFS,NULL);lastcmd->nextref=firstref;	       add_command(cPOPSYMLIST,NULL);               create_retval(ftNONE,function_type);               add_command(cRET_FROM_FUN,NULL);            } else {               add_command(cRETURN,NULL);            }}  | tRETURN expression {if (get_switch_id()) create_clean_switch_mark(1,TRUE); if (function_type==ftNONE) {error(ERROR,"can not return value"); YYABORT;} add_command(cCLEARREFS,NULL);lastcmd->nextref=firstref;add_command(cPOPSYMLIST,NULL);create_retval(ftNUMBER,function_type);add_command(cRET_FROM_FUN,NULL);}  | tRETURN string_expression {if (get_switch_id()) create_clean_switch_mark(1,TRUE); if (function_type==ftNONE) {error(ERROR,"can not return value"); YYABORT;} add_command(cCLEARREFS,NULL);lastcmd->nextref=firstref;add_command(cPOPSYMLIST,NULL);create_retval(ftSTRING,function_type);add_command(cRET_FROM_FUN,NULL);}  | tDIM dimlist  | tOPEN tWINDOW expression ',' expression {create_openwin(FALSE);}  | tOPEN tWINDOW expression ',' expression ',' string_expression          {create_openwin(TRUE);}  | tWINDOW tORIGIN string_expression {add_command(cMOVEORIGIN,NULL);}  | tDOT coordinates {add_command(cDOT,NULL);}  | tCLEAR tDOT coordinates {add_command(cDOT,NULL);putindrawmode(dmCLEAR);}  | tLINE coordinates to coordinates {create_line(2);}  | tCLEAR tLINE coordinates to coordinates {create_line(2);putindrawmode(dmCLEAR);}  | tLINE tTO coordinates {create_line(1);}  | tLINE coordinates {create_line(1);}  | tCLEAR tLINE tTO coordinates {create_line(1);putindrawmode(dmCLEAR);}  | tCLEAR tLINE coordinates {create_line(1);putindrawmode(dmCLEAR);}  | tPUTBIT string_expression to expression ',' expression ',' string_expression {add_command(cPUTBIT,NULL);}  | tPUTBIT string_expression to expression ',' expression {create_pushstr("solid"); add_command(cPUTBIT,NULL);}  | tPUTCHAR string_expression to expression ',' expression {add_command(cPUTCHAR,NULL);}  | tNEW tCURVE {create_line(-1);}  | tCLOSE tCURVE {create_line(0);}  | clear_fill_clause tCIRCLE coordinates ',' expression {add_command(cCIRCLE,NULL);putindrawmode(0);}  | clear_fill_clause tTRIANGLE coordinates to coordinates to coordinates {add_command(cTRIANGLE,NULL);putindrawmode(0);}  | tTEXT coordinates ',' string_expression {add_command(cTEXT1,NULL);}  | tTEXT coordinates ',' string_expression ',' string_expression {add_command(cTEXT2,NULL);}  | tTEXT coordinates ',' string_expression ',' string_expression ',' string_expression {add_command(cTEXT3,NULL);}  | clear_fill_clause tRECT coordinates to coordinates {add_command(cRECT,NULL);putindrawmode(0);}  | tCLOSE tWINDOW {add_command(cCLOSEWIN,NULL);}  | tCLEAR tWINDOW {add_command(cCLEARWIN,NULL);}  | tCLEAR tSCREEN {add_command(cCLEARSCR,NULL);}  | tOPEN tPRINTER {create_openprinter(0);}  | tOPEN tPRINTER string_expression {create_openprinter(1);}  | tCLOSE tPRINTER {add_command(cCLOSEPRN,NULL);}  | tWAIT expression {add_command(cWAIT,NULL);}  | tBELL {add_command(cBELL,NULL);}  | tINKEY {create_pushdbl(-1);create_function(fINKEY);add_command(cPOP,NULL);}  | tINKEY '(' ')' {create_pushdbl(-1);create_function(fINKEY);add_command(cPOP,NULL);}  | tINKEY '(' expression ')' {create_function(fINKEY);add_command(cPOP,NULL);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -