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

📄 pas.y.old

📁 this is a lp0 compilator new
💻 OLD
📖 第 1 页 / 共 3 页
字号:
		     $$->AdoptChildren (2, EXPRESSION_LABEL, orphans); }		;procedure_call  : ident actual_params		   { $$ = new syntaxNode (PROCEDURE_CALL_LABEL);		     orphans[0] = $1;		     orphans[1] = $2;		     $$->AdoptChildren (2, PROCEDURE_CALL_PARTS_LABEL, orphans); }		;actual_params   :  /*empty*/		   { $$ = new syntaxNode (EMPTY_LABEL);		     $$->AdoptChildren (0, EMPTY_PARAMS, orphans); }		| '(' actuals_list ')'		   { $$ = new syntaxNode (ACTUAL_PARAMS_LABEL);		     orphans[0] = $2;		     $$->AdoptChildren (1, ACTUALS_LIST_LABEL, orphans); }		;actuals_list    : actuals_list ',' actual_param		   { $$ = new syntaxNode (ACTUALS_LIST_LABEL);		     orphans[0] = $1;		     orphans[1] = $3;		     $$->AdoptChildren (2, SEQUENTIAL_PARAMS_LABEL, orphans); }		| actual_param		   { $$ = new syntaxNode (ACTUALS_LIST_LABEL);		     orphans[0] = $1;		     $$->AdoptChildren (1, ACTUAL_PARAM_LABEL, orphans); }		;actual_param    : expression    /* which could be a variable or a proc/fn id */		   { $$ = new syntaxNode (ACTUAL_PARAM_LABEL);		     orphans[0] = $1;		     $$->AdoptChildren (1, EXPRESSION_LABEL, orphans); }		| expression colon_things  /* only in i/o */		   { $$ = new syntaxNode (ACTUALS_LIST_LABEL);		     orphans[0] = $1;		     orphans[1] = $2;		     $$->AdoptChildren (2, COLON_THINGS_LABEL, orphans); }		;colon_things    : ':' expression        /*integer*/		   { $$ = new syntaxNode (ACTUALS_LIST_LABEL);		     orphans[0] = $2;		     $$->AdoptChildren (1, EXPRESSION_LABEL, orphans); }		| ':' expression ':' expression 		   { $$ = new syntaxNode (ACTUALS_LIST_LABEL);		     orphans[0] = $2;		     orphans[1] = $4;		     $$->AdoptChildren (2, SEQUENTIAL_COLON_LABEL, orphans); }		;case_list       : case_list ';' case_list_elem		   { $$ = new syntaxNode (CASE_LIST_LABEL);		     orphans[0] = $1;		     orphans[1] = $3;		     $$->AdoptChildren (2, SEQUENTIAL_CASE_OPTION_LABEL, orphans); }		| case_list_elem		   { $$ = new syntaxNode (CASE_LIST_LABEL);		     orphans[0] = $1;		     $$->AdoptChildren (1, CASE_OPTION_LABEL, orphans); }		;case_list_elem  : case_label_list ':' statement		   { $$ = new syntaxNode (CASE_LIST_ELEM_LABEL);		     orphans[0] = $3;		     $$->AdoptChildren (1, STATEMENT_LABEL, orphans); }		| /*empty*/		   { $$ = new syntaxNode (CASE_LIST_ELEM_LABEL);		     $$->AdoptChildren (0, EMPTY_CASE_LIST_ELEM, orphans); }		;case_label_list : case_label_list ',' case_label { /*nothing*/ }		| case_label { /*nothing*/ }		;case_label      : constant { /*nothing*/ }		;rec_var_list    : rec_var_list ',' record_var { /*nothing*/ }		| record_var { /*nothing*/ }		;expression      : simple_expr		   { $$ = new syntaxNode (EXPRESSION_LABEL);		     orphans[0] = $1;		     $$->AdoptChildren (1, SIMPLE_EXPR_LABEL, orphans); }		| simple_expr relational_op simple_expr		   { $$ = new syntaxNode (EXPRESSION_LABEL);		     orphans[0] = $1;		     orphans[1] = $3;		     $$->AdoptChildren (2, RELATIONAL_OP_LABEL, orphans); }		;relational_op   : '=' { /*nothing*/ }		| '<' { /*nothing*/ } 		| '>' { /*nothing*/ }		| LE  { /*nothing*/ }		| GE  { /*nothing*/ }		| NE  { /*nothing*/ }		| IN  { /*nothing*/ }		;simple_expr     : term		   {  $$ = new syntaxNode (SIMPLE_EXPR_LABEL);		      orphans[0] = $1;		      $$->AdoptChildren (1, TERM_LABEL, orphans); }		| '+' term		   {  $$ = new syntaxNode (SIMPLE_EXPR_LABEL);		      orphans[0] = $2;		      $$->AdoptChildren (1, UNARY_PLUS_LABEL, orphans); }		| '-' term		   {  $$ = new syntaxNode (SIMPLE_EXPR_LABEL);		      orphans[0] = $2;		      $$->AdoptChildren (1, UNARY_MINUS_LABEL, orphans); }		| simple_expr add_op term		   {  $$ = new syntaxNode (SIMPLE_EXPR_LABEL);		      orphans[0] = $1;		      orphans[1] = $2;		      orphans[2] = $3;		      $$->AdoptChildren (3, ADD_OP_LABEL, orphans); }		;add_op          : '+'		   {  $$ = new syntaxNode (ADD_OP_LABEL);		      $$->AdoptChildren (0, PLUS_LABEL, orphans); }		| '-'		   {  $$ = new syntaxNode (ADD_OP_LABEL);		      $$->AdoptChildren (1, MINUS_LABEL, orphans); }		| OR_TOK		   {  $$ = new syntaxNode (ADD_OP_LABEL);		      $$->AdoptChildren (0, OR_TOK, orphans); }		;term            : factor		   {  $$ = new syntaxNode (TERM_LABEL);		      orphans[0] = $1;		      $$->AdoptChildren (1, FACTOR_LABEL, orphans); }		| term mult_op factor		   {  $$ = new syntaxNode (TERM_LABEL);		      orphans[0] = $1;		      orphans[1] = $2;		      orphans[2] = $3;		      $$->AdoptChildren (3, MULTI_OP_LABEL, orphans); }		;mult_op         : '*'		   {  $$ = new syntaxNode (MULTI_OP_LABEL);		      $$->AdoptChildren (0, '*', orphans); }		| '/'		   {  $$ = new syntaxNode (MULTI_OP_LABEL);		      $$->AdoptChildren (0, '/', orphans); }		| DIV		   {  $$ = new syntaxNode (MULTI_OP_LABEL);		      $$->AdoptChildren (0, DIV, orphans); }		| MOD		   {  $$ = new syntaxNode (MULTI_OP_LABEL);		      $$->AdoptChildren (0, MOD, orphans); }		| AND_TOK		   {  $$ = new syntaxNode (MULTI_OP_LABEL);		      $$->AdoptChildren (0, AND_TOK, orphans); }		;factor          : variable              /* could be a const_ident of fn_call*/		   {  $$ = new syntaxNode (FACTOR_LABEL);		      orphans[0] = $1;		      $$->AdoptChildren (1, VARIABLE_LABEL, orphans); }		| unsigned_lit		   {  $$ = new syntaxNode (FACTOR_LABEL);		      orphans[0] = $1;		      $$->AdoptChildren (1, UNSIGNED_LIT_LABEL, orphans); }		| '(' expression ')'		   {  $$ = new syntaxNode (FACTOR_LABEL);		      orphans[0] = $2;		      $$->AdoptChildren (1, EXPRESSION_LABEL, orphans); }		| set		   {  $$ = new syntaxNode (FACTOR_LABEL);		      orphans[0] = $1;		      $$->AdoptChildren (1, SET_RULE_LABEL, orphans); }		| procedure_call		   {  $$ = new syntaxNode (FACTOR_LABEL);		      orphans[0] = $1;		      $$->AdoptChildren (1, PROCEDURE_CALL_LABEL, orphans); }		| NOT_TOK factor		   {  $$ = new syntaxNode (FACTOR_LABEL);		      orphans[0] = $2;		      $$->AdoptChildren (1, NOT_FACTOR_LABEL, orphans); }		;unsigned_lit    : unsigned_num		   {  $$ = new syntaxNode (UNSIGNED_LIT_LABEL);		      orphans[0] = $1;		      $$->AdoptChildren (1, UNSIGNED_NUM_LABEL, orphans); }		| STRING                        /*type is char if len=1*/		   {  $$ = new syntaxNode (UNSIGNED_LIT_LABEL);		      $$->AdoptChildren (0, STRING, orphans); }		| NIL		   {  $$ = new syntaxNode (UNSIGNED_LIT_LABEL);		      $$->AdoptChildren (0, NIL, orphans); }		;set             : '[' member_list ']'		   {  $$ = new syntaxNode (SET_RULE_LABEL);		      orphans[0] = $2;		      $$->AdoptChildren (1, MEMBER_LIST_LABEL, orphans); }		;member_list     : /*empty*/		   {  $$ = new syntaxNode (MEMBER_LIST_LABEL);		      $$->AdoptChildren (0, EMPTY_MEMBER_LIST, orphans); }		| members		   {  $$ = new syntaxNode (MEMBER_LIST_LABEL);		      orphans[0] = $1;		      $$->AdoptChildren (1, MEMBERS_LABEL, orphans); }		;members         : members ',' member		   {  $$ = new syntaxNode (MEMBERS_LABEL);		      orphans[0] = $1;		      orphans[1] = $3;		      $$->AdoptChildren (2, SEQUENTIAL_MEMBERS_LABEL, orphans); }		| member		   {  $$ = new syntaxNode (MEMBERS_LABEL);		      orphans[0] = $1;		      $$->AdoptChildren (1, MEMBER_LABEL, orphans); }		;member          : expression		   {  $$ = new syntaxNode (MEMBER_LABEL);		      orphans[0] = $1;		      $$->AdoptChildren (1, EXPRESSION_LABEL, orphans); }		| expression DOTDOT expression		   {  $$ = new syntaxNode (MEMBER_LABEL);		      orphans[0] = $1;		      orphans[1] = $3;		      $$->AdoptChildren (2, EXPRESSION_DOTDOT_LABEL, orphans); }		;variable        : ident		   {  $$ = new syntaxNode (VARIABLE_LABEL);		      orphans[0] = $1;		      $$->AdoptChildren (1, IDENT_LABEL, orphans); }		| variable '[' expressions ']'		   {  $$ = new syntaxNode (VARIABLE_LABEL);		      orphans[0] = $1;		      orphans[1] = $3;		      $$->AdoptChildren (2, ARRAY_LABEL, orphans); }		| variable '.' ident		   {  $$ = new syntaxNode (VARIABLE_LABEL);		      orphans[0] = $1;		      orphans[1] = $3;		      $$->AdoptChildren (2, RECORD_LABEL, orphans); }		| variable '^'		   {  $$ = new syntaxNode (VARIABLE_LABEL);		      orphans[0] = $1;		      $$->AdoptChildren (1, POINTER_LABEL, orphans); }		;expressions     : expressions ',' expression		   {  $$ = new syntaxNode (EXPRESSIONS_LABEL);		      orphans[0] = $1;		      orphans[1] = $3;		      $$->AdoptChildren (2, SEQUENTIAL_EXPR_LABEL, orphans); }		| expression		   {  $$ = new syntaxNode (EXPRESSIONS_LABEL);		      orphans[0] = $1;		      $$->AdoptChildren (1, EXPRESSION_LABEL, orphans); }		;record_var      : variable { /*nothing*/ }		;ident           : IDENTIFIER		   {  $$ = new syntaxNode (IDENT_LABEL);		      $$->AdoptChildren (0, IDENTIFIER, orphans); 		      $$->SetLexeme (last_id_token); }		;newident        : IDENTIFIER		   {  if (param_level < 2)			 last_id_token->SetExistence (its_a);		      $$ = new syntaxNode (NEWIDENT_LABEL); 		      $$->AdoptChildren (0, IDENTIFIER, orphans); 		      $$->SetLexeme (last_id_token); }		;%%//---------------------------------------------------------------------//                            USER CODE SECTION//---------------------------------------------------------------------char* token_name(int i){    static char buf[10];    switch(i)    {	default  : if(i<256)		   {		       if(i<32 || i>126)			   sprintf(buf, "0%o", i);		       else			   sprintf(buf, "%c", i);		       return buf;		   }		   else		       return("<Unknown token>");	case   0 : return("<End of input>");    }}int yyerror (char *msg){    if(msg==NULL || *msg=='\0')	fprintf(stderr, "Error at %s near line %d\n",				token_name(yychar), yylineno);    else	fprintf(stderr, "Error at %s near line %d : %s\n",				token_name(yychar), yylineno, msg);    exit(1);}parser_info(){    printf("\n%d line%s parsed\n", yylineno, plural(yylineno));}internal_error(int s, int a1, int a2, int a3, int a4){    fprintf(stderr, "Internal error: ");    exit(2);}warning(int fmt, int a1, int a2, int a3, int a4){    fprintf(stderr, "Warning line %d: ", yylineno);    fprintf(stderr, "\n");}

⌨️ 快捷键说明

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