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

📄 yabbison.txt

📁 一个小巧的BASIC解释器的源代码很小可它的确做到了
💻 TXT
📖 第 1 页 / 共 2 页
字号:
  | '-' expression %prec UMINUS {add_command(cNEGATE);}
  ;

mapping: expression ',' expression
  | tMAP '(' expression ',' expression ')' {add_command(cMAP);}
  ;

function: tSIN '(' expression ')' {create_function(fSIN);}
  | tASIN '(' expression ')' {create_function(fASIN);}
  | tCOS '(' expression ')' {create_function(fCOS);}
  | tACOS '(' expression ')' {create_function(fACOS);}
  | tTAN '(' expression ')' {create_function(fTAN);}
  | tATAN '(' expression ')' {create_function(fATAN);}
  | tATAN '(' expression ',' expression  ')' {create_function(fATAN2);}
  | tEXP '(' expression ')' {create_function(fEXP);}
  | tLOG '(' expression ')' {create_function(fLOG);}
  | tSQRT '(' expression ')' {create_function(fSQRT);}
  | tINT '(' expression ')' {create_function(fINT);}
  | tFRAC '(' expression ')' {create_function(fFRAC);}
  | tMOD '(' expression ',' expression ')' {create_function(fMOD);}
  | tRAN '(' expression ')' {create_function(fRAN);}
  | tRAN '(' ')' {create_function(fRAN2);}
  | tMIN '(' expression ',' expression ')' {create_function(fMIN);}
  | tMAX '(' expression ',' expression ')' {create_function(fMAX);}
  | tXMAP '(' expression ')' {create_function(fXMAP);}
  | tYMAP '(' expression ')' {create_function(fYMAP);}
  | tLEN '(' string_expression ')' {create_function(fLEN);}
  | tVAL '(' string_expression ')' {create_function(fVAL);}
  | tASC '(' string_expression ')' {create_function(fASC);}
  | tINSTR '(' string_expression ',' string_expression ')' {create_function(fINSTR);}
  | tSYSTEM2 '(' string_expression ')' {create_function(fSYSTEM2);}
  | tPEEK '(' string_expression ')' {create_function(fPEEK);}
  ;

const: number {$$=$1;}
  | '+' number {$$=$2;}
  | '-' number {$$=-$2;}
  ;

number: tFNUM {$$=$1;}
  | tDIGITS {$$=atoi($1);}
  ;

intnum: tDIGITS {$$=atoi($1);}
  ;

symbol_or_lineno: tDIGITS {$$=$1;}
  | tSYMBOL {$$=$1;}
  ;

dimlist: tSYMBOL '(' {pushcounter();} indexlist ')' {create_dim($1,'d');}
  | dimlist ',' tSYMBOL '(' {pushcounter();} indexlist ')' {create_dim($3,'d');}
  | tSTRSYM '(' {pushcounter();} indexlist ')' {create_dim($1,'s');}
  | dimlist ',' tSTRSYM '(' {pushcounter();} indexlist ')' {create_dim($3,'s');}
  ;

indexlist: expression {inccounter();}
  | indexlist ',' expression {inccounter();}
  ;
 
for_loop: tFOR tSYMBOL tEQU expression 
            {pushname($2); /* will be used by next_symbol to check equality */
	     add_command(cDUPLICATE);
	     create_popdblsym($2);} /* for-variable gets value of expression */
	  tTO expression 
	  step_part { /* pushes another expression */
	     newfor();
	     pushfor();
	     create_forprepare();
	     pushgoto(); /* creates a label implicitly */
	     create_pushdblsym($2);
	     pushfor();
	     create_forcheck();
	     add_command(cDECIDE);
             pushlabel();}
	  tSEP {yylineno+=$10;}
	     {pushfor();}
          statement_list {
	     create_pushdblsym($2);
	     create_forincrement();
	     create_popdblsym($2);
             swap();popgoto();poplabel();}
          next_or_eofile next_symbol
  ;

next_or_eofile: tNEXT
  | tEOFILE {end_of_file=TRUE;
	    error(ERROR,"'next' statement is missing"); YYABORT;}

step_part: {create_pushdbl(1.0);} /* can be omitted */
  | tSTEP expression
  ;

next_symbol:  {pop();}/* can be omitted */
  | tSYMBOL {if (strcmp(pop()->pointer,$1)) 
             {error(ERROR,"'for' and 'next' do not match"); YYABORT;}
           }
  ;

if_clause: tIF condition {add_command(cDECIDE);pushlabel();}
           tTHEN statement_list {pushlabel();swap();poplabel();}
           else_part {poplabel();}
           endif_or_eof
  ;

endif_or_eof: tENDIF
  | tEOFILE {end_of_file=TRUE;
            error(ERROR,"'endif'-statement is missing"); YYABORT;}

condition: '(' condition ')'
  | condition tOR condition {create_boole('|');}
  | condition tAND condition {create_boole('&');}
  | tNOT condition {create_boole('!');}
  | string_expression tEQU string_expression {create_strrelop('=');}
  | string_expression tNEQ string_expression {create_strrelop('!');}
  | string_expression tLTN string_expression {create_strrelop('<');}
  | string_expression tLEQ string_expression {create_strrelop('{');}
  | string_expression tGTN string_expression {create_strrelop('>');}
  | string_expression tGEQ string_expression {create_strrelop('}');}
  | expression tEQU expression {create_dblrelop('=');}
  | expression tNEQ expression {create_dblrelop('!');}
  | expression tLTN expression {create_dblrelop('<');}
  | expression tLEQ expression {create_dblrelop('{');}
  | expression tGTN expression {create_dblrelop('>');}
  | expression tGEQ expression {create_dblrelop('}');}
  | tMYEOF '(' hashed_number ')' {create_testeof($3);}
  ;

else_part: /* can be omitted */
  | tELSE statement_list
  ;

inputlist: input
  | input ',' {add_command(cCHKPROMPT);} inputlist
  ;

input: tSYMBOL {create_myread('d',tileol);create_popdblsym($1);}
  | tSYMBOL '(' {pushcounter();} indexlist ')' 
    {create_myread('d',tileol);create_doarray($1,ASSIGNARRAY);}
  | tSTRSYM {create_myread('s',tileol);create_popstrsym($1);}
  | tSTRSYM '(' {pushcounter();} indexlist ')' 
    {create_myread('s',tileol);create_doarray($1,ASSIGNSTRINGARRAY);}
  ;

readlist: readitem
  | readlist ',' readitem
  ;

readitem: tSYMBOL {create_readdata('d');create_popdblsym($1);}
  | tSYMBOL '(' {pushcounter();} indexlist ')' 
    {create_readdata('d');create_doarray($1,ASSIGNARRAY);}
  | tSTRSYM {create_readdata('s');create_popstrsym($1);}
  | tSTRSYM '(' {pushcounter();} indexlist ')' 
    {create_readdata('s');create_doarray($1,ASSIGNSTRINGARRAY);}
  ;

datalist: tSTRING {create_strdata($1);}
  | const {create_dbldata($1);}
  | datalist ','  tSTRING {create_strdata($3);}
  | datalist ',' const {create_dbldata($3);}
  ;

printlist:  /* possible empty */
  | expression {create_print('d');}
  | printlist ',' expression {create_print('d');} 
  | string_expression {create_print('s');} 
  | printlist ',' string_expression {create_print('s');}
  ;

inputintro: stream
  | {create_myswitch(0);} prompt 
  | position {create_myswitch(0);} prompt
  ;

printintro: {create_myswitch(0);} /* can be empty */
  | stream
  | tREVERSE {create_revert(TRUE);create_myswitch(0);}
  | position {create_myswitch(0);}
  | tREVERSE position {create_revert(TRUE);create_myswitch(0);}
  ;  

prompt: /* empty */ {create_onestring("?");}
  | tSTRING {create_onestring($1);}
  | tSTRING ',' {create_onestring($1);}
  ;

position: tAT '(' expression ',' expression ')' {add_command(cMOVE);}
  ;

stream: '#' intnum {create_myswitch($2);}
  ;

hashed_number: '#' intnum {$$=$2;}
  | intnum {$$=$1;} /* need not contain hash */
  ;

semicolon: /* can be left out */ {create_print('n');}
  | ';'
  ;

goto_list: symbol_or_lineno {create_goto($1);add_command(cFINDNOP);}
  | goto_list ',' symbol_or_lineno {create_goto($3);add_command(cFINDNOP);}
  ;

gosub_list: symbol_or_lineno {create_gosub($1);add_command(cFINDNOP);}
  | gosub_list ',' symbol_or_lineno {create_gosub($3);add_command(cFINDNOP);}
  ;

⌨️ 快捷键说明

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