📄 ycmm.y
字号:
%{#include <stdio.h>#include <string.h>#include "tree.h"#include "c-tree.h"%}%start program%union { long itype; union tree_node * ttype; enum tree_code code; char * filename; int lineno;}%token IDENTIFIER CONSTANT%token GE_OP LE_OP EQ_OP NE_OP AND_OP OR_OP%token INT REAL%token WHILE WRITE READ IF ELSE%nonassoc IF%nonassoc ELSE%right <code> '='%left <code> OR_OP%left <code> AND_OP%left <code> '>' '<' EQ_OP NE_OP LE_OP GE_OP%left <code> '+' '-'%left <code> '*' '/' '%'%right <code> UNARY%left <code> '.' '(' '['%type <code> unop%type <ttype> IDENTIFIER primary CONSTANT expr expr_no_commas%%program : decls fndefs ;fndefs : fndef | fndefs fndef;fndef : typed_declspecs declarator compstmtunop : '-' { $$ = NEGATE_EXPR; } | '+' { $$ = CONVERT_EXPR; } | '~' { $$ = ADDR_EXPR; } | '!' { $$ = TRUTH_NOT_EXPR; }expr : nonnull_exprlist ;exprlist : /* empty */ | nonnull_exprlist ;nonnull_exprlist : expr_no_commas | nonnull_exprlist ',' expr_no_commas ;unary_expr : primary | unop cast_expr %prec UNARY ;cast_expr : unary_expr ;expr_no_commas : cast_expr | expr_no_commas '+' expr_no_commas | expr_no_commas '-' expr_no_commas | expr_no_commas '*' expr_no_commas | expr_no_commas '/' expr_no_commas | expr_no_commas '%' expr_no_commas | expr_no_commas '=' expr_no_commas | expr_no_commas '<' expr_no_commas | expr_no_commas '>' expr_no_commas | expr_no_commas EQ_OP expr_no_commas | expr_no_commas NE_OP expr_no_commas | expr_no_commas LE_OP expr_no_commas | expr_no_commas GE_OP expr_no_commas | expr_no_commas AND_OP expr_no_commas | expr_no_commas OR_OP expr_no_commasprimary : IDENTIFIER { $$ = $1; printf("identifier:%s\n",$1->identifier.name); } | CONSTANT { $$ = $1; if (TREE_CODE($1) == REAL_CST) printf("real:%f\n",$1->real_cst.value); else if (TREE_CODE($1) == INTEGER_CST) printf("int:%d\n",$1->int_cst.value); } | '(' expr ')' { $$ = $2; } | primary '[' expr ']' | primary '(' exprlist ')' ;lineno_decl :decl ;decls : lineno_decl | decls lineno_decl ;decl : typed_declspecs initdecls ';' ;typed_declspecs : typespec ;typespec : INT | REAL ;initdecls : initdcl | initdecls ',' initdcl ;initdcl : declarator '=' init | declarator ;init : expr_no_commas | '{' '}' | '{' initlist '}' | '{' initlist ',' '}'initlist : init | initlist ',' init ;declarator : notype_declarator ;notype_declarator : IDENTIFIER | notype_declarator '[' expr ']' | notype_declarator '[' ']' | notype_declarator '(' parmlist_or_identifiers | '(' notype_declarator ')' ;stmts : lineno_stmt_or_label | stmts lineno_stmt_or_label ;lineno_stmt_or_label : save_filename save_lineno stmt_or_label ;stmt_or_label : stmt | label ;label : IDENTIFIER ':' ;xstmts : | stmts ;compstmt : '{' decls xstmts '}' | '{' xstmts '}' ;simple_if : if_prefix lineno_labeled_stmt ;if_prefix : IF '(' expr ')' ;save_filename : ;save_lineno : ;lineno_labeled_stmt : save_filename save_lineno stmt ;stmt : compstmt | expr ';' | simple_if ELSE lineno_labeled_stmt | simple_if %prec IF | WHILE '(' expr ')' lineno_labeled_stmt | WRITE '(' expr ')' ';' | READ '(' identifiers ')' ';' parmlist_or_identifiers : parms ')' | identifiers ')' | ')' ;parms : parm | parms ',' parm ;parm : typed_declspecs notype_declarator ;identifiers : IDENTIFIER | identifiers ',' IDENTIFIER ;%%int main () { yyparse();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -