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

📄 cm_parse.v

📁 小型编译系统的源代码
💻 V
📖 第 1 页 / 共 3 页
字号:
    0  $accept : program $end

    1  program : declaration_list

    2  declaration_list : declaration_list declaration
    3                   | empty

    4  declaration : var_declaration
    5              | fun_declaration
    6              | fun_definition

    7  var_declaration : type_specifier idlist SEMICOLON

    8  idlist : idlist COMMA id
    9         | idlist COMMA array
   10         | array
   11         | id

   12  $$1 :

   13  array : id LBRACKET NUM $$1 RBRACKET

   14  type_specifier : INT
   15                 | CHAR
   16                 | FLOAT
   17                 | VOID

   18  id : ID

   19  fun_declaration : type_specifier id LPAREN params RPAREN SEMICOLON
   20                  | type_specifier id LPAREN RPAREN SEMICOLON

   21  fun_definition : type_specifier id LPAREN params RPAREN compound_stmt
   22                 | type_specifier id LPAREN RPAREN compound_stmt

   23  params : param_list
   24         | VOID
   25         | empty

   26  param_list : param_list COMMA param
   27             | param

   28  param : type_specifier ID

   29  $$2 :

   30  param : type_specifier ID $$2 LBRACKET RBRACKET

   31  compound_stmt : LBRACE local_declarations RBRACE
   32                | LBRACE local_declarations statement_list RBRACE
   33                | LBRACE RBRACE
   34                | LBRACE statement_list RBRACE

   35  local_declarations : local_declarations var_declaration
   36                     | var_declaration

   37  statement_list : statement_list statement
   38                 | statement

   39  statement : expression_stmt
   40            | compound_stmt
   41            | selection_stmt
   42            | while_stmt
   43            | for_stmt
   44            | return_stmt

   45  expression_stmt : expression SEMICOLON
   46                  | SEMICOLON

   47  selection_stmt : IF LPAREN expression RPAREN statement ELSE statement
   48                 | IF LPAREN expression RPAREN statement

   49  while_stmt : WHILE LPAREN expression RPAREN statement

   50  for_stmt : FOR LPAREN for_expression SEMICOLON for_expression SEMICOLON for_expression RPAREN statement

   51  return_stmt : RETURN SEMICOLON
   52              | RETURN expression SEMICOLON

   53  expression : var ASSIGN expression
   54             | or_expression

   55  for_expression : var ASSIGN expression
   56                 | or_expression
   57                 | empty

   58  empty :

   59  var : ID

   60  $$3 :

   61  var : ID $$3 LBRACKET expression RBRACKET

   62  or_expression : or_expression OR and_expression
   63                | and_expression

   64  and_expression : and_expression AND additive_expression
   65                 | additive_expression

   66  additive_expression : additive_expression EQ rel_expression
   67                      | additive_expression LT rel_expression
   68                      | additive_expression GT rel_expression
   69                      | additive_expression LE rel_expression
   70                      | additive_expression GE rel_expression
   71                      | additive_expression NE rel_expression
   72                      | rel_expression

   73  rel_expression : rel_expression PLUS term
   74                 | rel_expression MINUS term
   75                 | term

   76  term : term TIMES factor
   77       | term OVER factor
   78       | factor

   79  factor : LPAREN expression RPAREN
   80         | var
   81         | call
   82         | NUM
   83         | FLOATNUM
   84         | CONSTCHAR
   85         | NOT factor

   86  call : id LPAREN arg_list RPAREN
   87       | id LPAREN RPAREN

   88  arg_list : expression COMMA arg_list
   89           | expression


state 0
	$accept : . program $end
	empty : .  (58)

	.  reduce 58

	program goto 1
	declaration_list goto 2
	empty goto 3


state 1
	$accept : program . $end  (0)

	$end  accept


state 2
	program : declaration_list .  (1)
	declaration_list : declaration_list . declaration

	INT  shift 4
	CHAR  shift 5
	FLOAT  shift 6
	VOID  shift 7
	.  reduce 1

	declaration goto 8
	var_declaration goto 9
	fun_declaration goto 10
	fun_definition goto 11
	type_specifier goto 12


state 3
	declaration_list : empty .  (3)

	.  reduce 3


state 4
	type_specifier : INT .  (14)

	.  reduce 14


state 5
	type_specifier : CHAR .  (15)

	.  reduce 15


state 6
	type_specifier : FLOAT .  (16)

	.  reduce 16


state 7
	type_specifier : VOID .  (17)

	.  reduce 17


state 8
	declaration_list : declaration_list declaration .  (2)

	.  reduce 2


state 9
	declaration : var_declaration .  (4)

	.  reduce 4


state 10
	declaration : fun_declaration .  (5)

	.  reduce 5


state 11
	declaration : fun_definition .  (6)

	.  reduce 6


state 12
	var_declaration : type_specifier . idlist SEMICOLON
	fun_declaration : type_specifier . id LPAREN params RPAREN SEMICOLON
	fun_declaration : type_specifier . id LPAREN RPAREN SEMICOLON
	fun_definition : type_specifier . id LPAREN params RPAREN compound_stmt
	fun_definition : type_specifier . id LPAREN RPAREN compound_stmt

	ID  shift 13

	idlist goto 14
	id goto 15
	array goto 16


state 13
	id : ID .  (18)

	.  reduce 18


state 14
	var_declaration : type_specifier idlist . SEMICOLON
	idlist : idlist . COMMA id
	idlist : idlist . COMMA array

	SEMICOLON  shift 17
	COMMA  shift 18


state 15
	idlist : id .  (11)
	array : id . LBRACKET NUM $$1 RBRACKET
	fun_declaration : type_specifier id . LPAREN params RPAREN SEMICOLON
	fun_declaration : type_specifier id . LPAREN RPAREN SEMICOLON
	fun_definition : type_specifier id . LPAREN params RPAREN compound_stmt
	fun_definition : type_specifier id . LPAREN RPAREN compound_stmt

	LPAREN  shift 19
	LBRACKET  shift 20
	.  reduce 11


state 16
	idlist : array .  (10)

	.  reduce 10


state 17
	var_declaration : type_specifier idlist SEMICOLON .  (7)

	.  reduce 7


state 18
	idlist : idlist COMMA . id
	idlist : idlist COMMA . array

	ID  shift 13

	id goto 21
	array goto 22


19: shift-reduce conflict (shift 24, reduce 58) on RPAREN
state 19
	fun_declaration : type_specifier id LPAREN . params RPAREN SEMICOLON
	fun_declaration : type_specifier id LPAREN . RPAREN SEMICOLON
	fun_definition : type_specifier id LPAREN . params RPAREN compound_stmt
	fun_definition : type_specifier id LPAREN . RPAREN compound_stmt
	empty : .  (58)

	INT  shift 4
	CHAR  shift 5
	FLOAT  shift 6
	VOID  shift 23
	RPAREN  shift 24

	empty goto 25
	type_specifier goto 26
	params goto 27
	param_list goto 28
	param goto 29


state 20
	array : id LBRACKET . NUM $$1 RBRACKET

	NUM  shift 30


state 21
	idlist : idlist COMMA id .  (8)
	array : id . LBRACKET NUM $$1 RBRACKET

	LBRACKET  shift 20
	.  reduce 8


state 22
	idlist : idlist COMMA array .  (9)

	.  reduce 9


state 23
	type_specifier : VOID .  (17)
	params : VOID .  (24)

	RPAREN  reduce 24
	.  reduce 17


state 24
	fun_declaration : type_specifier id LPAREN RPAREN . SEMICOLON
	fun_definition : type_specifier id LPAREN RPAREN . compound_stmt

	SEMICOLON  shift 31
	LBRACE  shift 32

	compound_stmt goto 33


state 25
	params : empty .  (25)

	.  reduce 25


state 26
	param : type_specifier . ID
	param : type_specifier . ID $$2 LBRACKET RBRACKET

	ID  shift 34


state 27
	fun_declaration : type_specifier id LPAREN params . RPAREN SEMICOLON
	fun_definition : type_specifier id LPAREN params . RPAREN compound_stmt

	RPAREN  shift 35


state 28
	params : param_list .  (23)
	param_list : param_list . COMMA param

	COMMA  shift 36
	.  reduce 23


state 29
	param_list : param .  (27)

	.  reduce 27


state 30
	array : id LBRACKET NUM . $$1 RBRACKET
	$$1 : .  (12)

	.  reduce 12

	$$1 goto 37


state 31
	fun_declaration : type_specifier id LPAREN RPAREN SEMICOLON .  (20)

	.  reduce 20


state 32
	compound_stmt : LBRACE . local_declarations RBRACE
	compound_stmt : LBRACE . local_declarations statement_list RBRACE
	compound_stmt : LBRACE . RBRACE
	compound_stmt : LBRACE . statement_list RBRACE

	INT  shift 4
	CHAR  shift 5
	FLOAT  shift 6
	VOID  shift 7
	IF  shift 38
	WHILE  shift 39
	FOR  shift 40
	RETURN  shift 41
	ID  shift 42
	NUM  shift 43
	FLOATNUM  shift 44
	CONSTCHAR  shift 45
	NOT  shift 46
	LPAREN  shift 47
	SEMICOLON  shift 48
	LBRACE  shift 32
	RBRACE  shift 49

	var_declaration goto 50
	type_specifier goto 51
	id goto 52
	compound_stmt goto 53
	local_declarations goto 54
	statement_list goto 55
	statement goto 56
	expression_stmt goto 57
	selection_stmt goto 58
	while_stmt goto 59
	for_stmt goto 60
	return_stmt goto 61
	expression goto 62
	var goto 63
	or_expression goto 64
	and_expression goto 65
	additive_expression goto 66
	rel_expression goto 67
	term goto 68
	factor goto 69
	call goto 70


state 33
	fun_definition : type_specifier id LPAREN RPAREN compound_stmt .  (22)

	.  reduce 22


state 34
	param : type_specifier ID .  (28)
	param : type_specifier ID . $$2 LBRACKET RBRACKET
	$$2 : .  (29)

	LBRACKET  reduce 29
	.  reduce 28

	$$2 goto 71


state 35
	fun_declaration : type_specifier id LPAREN params RPAREN . SEMICOLON
	fun_definition : type_specifier id LPAREN params RPAREN . compound_stmt

	SEMICOLON  shift 72
	LBRACE  shift 32

	compound_stmt goto 73


state 36
	param_list : param_list COMMA . param

	INT  shift 4
	CHAR  shift 5
	FLOAT  shift 6
	VOID  shift 7

	type_specifier goto 26
	param goto 74


state 37
	array : id LBRACKET NUM $$1 . RBRACKET

	RBRACKET  shift 75


state 38
	selection_stmt : IF . LPAREN expression RPAREN statement ELSE statement
	selection_stmt : IF . LPAREN expression RPAREN statement

	LPAREN  shift 76


state 39
	while_stmt : WHILE . LPAREN expression RPAREN statement

	LPAREN  shift 77


state 40
	for_stmt : FOR . LPAREN for_expression SEMICOLON for_expression SEMICOLON for_expression RPAREN statement

	LPAREN  shift 78


state 41
	return_stmt : RETURN . SEMICOLON
	return_stmt : RETURN . expression SEMICOLON

	ID  shift 42
	NUM  shift 43
	FLOATNUM  shift 44
	CONSTCHAR  shift 45
	NOT  shift 46
	LPAREN  shift 47
	SEMICOLON  shift 79

	id goto 52
	expression goto 80
	var goto 63
	or_expression goto 64
	and_expression goto 65
	additive_expression goto 66
	rel_expression goto 67
	term goto 68
	factor goto 69
	call goto 70


state 42
	id : ID .  (18)
	var : ID .  (59)
	var : ID . $$3 LBRACKET expression RBRACKET
	$$3 : .  (60)

	LPAREN  reduce 18
	LBRACKET  reduce 60
	.  reduce 59

	$$3 goto 81


state 43
	factor : NUM .  (82)

	.  reduce 82


state 44
	factor : FLOATNUM .  (83)

	.  reduce 83


state 45
	factor : CONSTCHAR .  (84)

	.  reduce 84


state 46
	factor : NOT . factor

	ID  shift 42
	NUM  shift 43
	FLOATNUM  shift 44
	CONSTCHAR  shift 45
	NOT  shift 46
	LPAREN  shift 47

	id goto 52
	var goto 82
	factor goto 83
	call goto 70


state 47
	factor : LPAREN . expression RPAREN

	ID  shift 42
	NUM  shift 43
	FLOATNUM  shift 44
	CONSTCHAR  shift 45
	NOT  shift 46
	LPAREN  shift 47

	id goto 52
	expression goto 84
	var goto 63
	or_expression goto 64
	and_expression goto 65
	additive_expression goto 66
	rel_expression goto 67
	term goto 68
	factor goto 69
	call goto 70


state 48
	expression_stmt : SEMICOLON .  (46)

	.  reduce 46


state 49
	compound_stmt : LBRACE RBRACE .  (33)

	.  reduce 33


state 50
	local_declarations : var_declaration .  (36)

	.  reduce 36


state 51
	var_declaration : type_specifier . idlist SEMICOLON

	ID  shift 13

⌨️ 快捷键说明

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