- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
代码:
%{
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include "gener.h"
#include "sym_tab.h"
#include "scope.h"
#include "defs.h"
extern char *yytext;
#define YYPRINT(file, type, value) yyprint (file, type, value)
%}
%union
{
char *name;
char idtype;
decl_list idlist;
/*decl_list is in gener.h,
you should #include "gener.h"
*/
}
%token PROGRAM
%token IDENTIFIER
%token DECIMAL_CONSTANT
%token DECLARE ENDDECLARE
%token AND CALL DEFAULT
%token FUNCTION PROCEDURE IN INOUT
%token IF ELSE DO WHILE FOR OR NOT SELECT
%token RETURN EXIT PRINT
%token EQ_LT EQ_GT NE EXACT
%left '+' '-'
%right '*' '/'
%start program
%%
program
: %empty
| PROGRAM IDENTIFIER block
;
block
: "{" declarations subprograms sequence "}"
;
declarations
: %empty
| DECLARE varlist ENDDECLARE
;
varlist
: %empty
| assignment_stat identifier2
;
identifier2 : ',' assignment_stat
| ',' assignment_stat
;
subprograms
: func
| subprograms ','
;
func
: PROCEDURE IDENTIFIER funcbody
| FUNCTION IDENTIFIER funcbody
;
funcbody
: formalpars block
;
formalpars
: '('')'
| '(' formalparlist ')'
;
formalparlist
: formalparitem
| formalparlist ','
;
formalparitem
: IN IDENTIFIER
| INOUT IDENTIFIER
;
sequence
: statement statement_sequence
;
statement_sequence
: ";"statement
| ';' statement statement_sequence
;
brackets_seq
: '{' sequence '}'
;
brack_or_stat
: brackets_seq
| statement
;
statement
: %empty
| assignment_stat
| if_stat
| do_while_stat
| while_stat
| select_stat
| exit_stat
| return_stat
| print_stat
| call_stat
;
assignment_stat
: IDENTIFIER EXACT IDENTIFIER
;
if_stat
: IF '(' condition')' brack_or_stat elsepart
;
elsepart
: %empty
| ELSE brack_or_stat
;
while_stat
: WHILE '(' condition')' brack_or_stat
;
select_stat
: SELECT'(' IDENTIFIER')'
dec
DEFAULT":" brack_or_stat
;
dec
: DECIMAL_CONSTANT ':' brack_or_stat
| dec ','
;
do_while_stat
: DO brack_or_stat WHILE '(' condition ')'
;
exit_stat
: EXIT
;
return_stat
: RETURN '(' expression ')'
;
print_stat
: PRINT '('expression ')'
;
call_stat
: CALL IDENTIFIER actualpars
;
actualpars
: '('')'
| '('actualparlist')'
;
actualparlist
: actualparitem
| actualparlist ','
;
actualparitem
: IN expression
| INOUT IDENTIFIER
;
condition
: boolterm or_boolterm
;
or_boolterm
: OR boolterm
| OR boolterm or_boolterm
;
boolterm
: boolfactor and_boolfactor
;
and_boolfactor
: AND boolfactor
| AND boolfactor and_boolfactor
;
boolfactor
: NOT '[' condition ']'
| '[' condition ']'
| expression relational_oper expression
;
expression
: optional_sign term add_oper_term
;
add_oper_term
: add_oper term
| add_oper term add_oper_term
;
term
: factor mul_oper_factor
;
mul_oper_factor
: mul_oper factor
| mul_oper factor mul_oper_factor
;
factor
: DECIMAL_CONSTANT
| expression
| IDENTIFIER idtail
;
idtail
: %empty
| actualpars
;
relational_oper
: '='
| '<'
| "<="
| "<>"
| ">="
| '>'
;
add_oper
: '+'
| '-'
;
mul_oper
: '*'
| '/'
;
optional_sign
: add_oper
| %empty
;
%%
gram.y: warning: 44 nonterminals useless in grammar [-Wother]
gram.y: warning: 86 rules useless in grammar [-Wother]
gram.y:43.38-42: warning: nonterminal useless in grammar: block [-Wother]
| PROGRAM IDENTIFIER block
^^^^^
gram.y:47.23-34: warning: nonterminal useless in grammar: declarations [-Wother]
: "{" declarations subprograms sequence "}"
^^^^^^^^^^^^
gram.y:51.27-33: warning: nonterminal useless in grammar: varlist [-Wother]
| DECLARE varlist ENDDECLARE
^^^^^^^
gram.y:55.35-45: warning: nonterminal useless in grammar: identifier2 [-Wother]
| assignment_stat identifier2
^^^^^^^^^^^
gram.y:47.36-46: warning: nonterminal useless in grammar: subprograms [-Wother]
: "{" declarations subprograms sequence "}"
^^^^^^^^^^^
gram.y:63.19-22: warning: nonterminal useless in grammar: func [-Wother]
: func
^^^^
gram.y:67.40-47: warning: nonterminal useless in grammar: funcbody [-Wother]
: PROCEDURE IDENTIFIER funcbody
^^^^^^^^
gram.y:71.19-28: warning: nonterminal useless in grammar: formalpars [-Wother]
: formalpars block
^^^^^^^^^^
gram.y:75.23-35: warning: nonterminal useless in grammar: formalparlist [-Wother]
| '(' formalparlist ')'
^^^^^^^^^^^^^
gram.y:79.19-31: warning: nonterminal useless in grammar: formalparitem [-Wother]
: formalparitem
^^^^^^^^^^^^^
gram.y:47.48-55: warning: nonterminal useless in grammar: sequence [-Wother]
: "{" declarations subprograms sequence "}"
^^^^^^^^
gram.y:88.29-46: warning: nonterminal useless in grammar: statement_sequence [-Wother]
: statement statement_sequence
^^^^^^^^^^^^^^^^^^
gram.y:94.1-12: warning: nonterminal useless in grammar: brackets_seq [-Wother]
brackets_seq
^^^^^^^^^^^^
gram.y:97.1-13: warning: nonterminal useless in grammar: brack_or_stat [-Wother]
brack_or_stat
^^^^^^^^^^^^^
gram.y:88.19-27: warning: nonterminal useless in grammar: statement [-Wother]
: statement statement_sequence
^^^^^^^^^
gram.y:55.19-33: warning: nonterminal useless in grammar: assignment_stat [-Wother]
| assignment_stat identifier2
^^^^^^^^^^^^^^^
gram.y:106.19-25: warning: nonterminal useless in grammar: if_stat [-Wother]
| if_stat
^^^^^^^
gram.y:120.53-60: warning: nonterminal useless in grammar: elsepart [-Wother]
: IF '(' condition')' brack_or_stat elsepart
^^^^^^^^
gram.y:108.19-28: warning: nonterminal useless in grammar: while_stat [-Wother]
| while_stat
^^^^^^^^^^
gram.y:109.19-29: warning: nonterminal useless in grammar: select_stat [-Wother]
| select_stat
^^^^^^^^^^^
gram.y:131.19-21: warning: nonterminal useless in grammar: dec [-Wother]
dec
^^^
gram.y:107.19-31: warning: nonterminal useless in grammar: do_while_stat [-Wother]
| do_while_stat
^^^^^^^^^^^^^
gram.y:110.19-27: warning: nonterminal useless in grammar: exit_stat [-Wother]
| exit_stat
^^^^^^^^^
gram.y:111.19-29: warning: nonterminal useless in grammar: return_stat [-Wother]
| return_stat
^^^^^^^^^^^
gram.y:112.19-28: warning: nonterminal useless in grammar: print_stat [-Wother]
| print_stat
^^^^^^^^^^
gram.y:113.19-27: warning: nonterminal useless in grammar: call_stat [-Wother]
| call_stat
^^^^^^^^^
gram.y:151.35-44: warning: nonterminal useless in grammar: actualpars [-Wother]
: CALL IDENTIFIER actualpars
^^^^^^^^^^
gram.y:155.22-34: warning: nonterminal useless in grammar: actualparlist [-Wother]
| '('actualparlist')'
^^^^^^^^^^^^^
gram.y:158.19-31: warning: nonterminal useless in grammar: actualparitem [-Wother]
: actualparitem
^^^^^^^^^^^^^
gram.y:120.26-34: warning: nonterminal useless in grammar: condition [-Wother]
: IF '(' condition')' brack_or_stat elsepart
^^^^^^^^^
gram.y:166.28-38: warning: nonterminal useless in grammar: or_boolterm [-Wother]
: boolterm or_boolterm
^^^^^^^^^^^
gram.y:166.19-26: warning: nonterminal useless in grammar: boolterm [-Wother]
: boolterm or_boolterm
^^^^^^^^
gram.y:173.30-43: warning: nonterminal useless in grammar: and_boolfactor [-Wother]
: boolfactor and_boolfactor
^^^^^^^^^^^^^^
gram.y:173.19-28: warning: nonterminal useless in grammar: boolfactor [-Wother]
: boolfactor and_boolfactor
^^^^^^^^^^
gram.y:145.30-39: warning: nonterminal useless in grammar: expression [-Wother]
: RETURN '(' expression ')'
^^^^^^^^^^
gram.y:185.38-50: warning: nonterminal useless in grammar: add_oper_term [-Wother]
: optional_sign term add_oper_term
^^^^^^^^^^^^^
gram.y:185.33-36: warning: nonterminal useless in grammar: term [-Wother]
: optional_sign term add_oper_term
^^^^
gram.y:192.26-40: warning: nonterminal useless in grammar: mul_oper_factor [-Wother]
: factor mul_oper_factor
^^^^^^^^^^^^^^^
gram.y:192.19-24: warning: nonterminal useless in grammar: factor [-Wother]
: factor mul_oper_factor
^^^^^^
gram.y:201.30-35: warning: nonterminal useless in grammar: idtail [-Wother]
| IDENTIFIER idtail
^^^^^^
gram.y:182.30-44: warning: nonterminal useless in grammar: relational_oper [-Wother]
| expression relational_oper expression
^^^^^^^^^^^^^^^
gram.y:188.19-26: warning: nonterminal useless in grammar: add_oper [-Wother]
: add_oper term
^^^^^^^^
gram.y:195.19-26: warning: nonterminal useless in grammar: mul_oper [-Wother]
: mul_oper factor mul_oper_factor
^^^^^^^^
gram.y:185.19-31: warning: nonterminal useless in grammar: optional_sign [-Wother]
: optional_sign term add_oper_term
^^^^^^^^^^^^^
gram.y:43.19-42: warning: rule useless in grammar [-Wother]
| PROGRAM IDENTIFIER block
^^^^^^^^^^^^^^^^^^^^^^^^
gram.y:47.19-59: warning: rule useless in grammar [-Wother]
: "{" declarations subprograms sequence "}"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
gram.y:50.19-24: warning: rule useless in grammar [-Wother]
: %empty
^^^^^^
gram.y:51.19-44: warning: rule useless in grammar [-Wother]
| DECLARE varlist ENDDECLARE
^^^^^^^^^^^^^^^^^^^^^^^^^^
gram.y:54.19-24: warning: rule useless in grammar [-Wother]
: %empty
^^^^^^
gram.y:55.19-45: warning: rule useless in grammar [-Wother]
| assignment_stat identifier2
^^^^^^^^^^^^^^^^^^^^^^^^^^^
gram.y:58.19-37: warning: rule useless in grammar [-Wother]
identifier2 : ',' assignment_stat
^^^^^^^^^^^^^^^^^^^
gram.y:59.19-37: warning: rule useless in grammar [-Wother]
| ',' assignment_stat
^^^^^^^^^^^^^^^^^^^
gram.y:63.19-22: warning: rule useless in grammar [-Wother]
: func
^^^^
gram.y:64.19-33: warning: rule useless in grammar [-Wother]
| subprograms ','
^^^^^^^^^^^^^^^
gram.y:67.19-47: warning: rule useless in grammar [-Wother]
: PROCEDURE IDENTIFIER funcbody
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
gram.y:68.19-46: warning: rule useless in grammar [-Wother]
| FUNCTION IDENTIFIER funcbody
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
gram.y:71.19-34: warning: rule useless in grammar [-Wother]
: formalpars block
^^^^^^^^^^^^^^^^
gram.y:74.19-24: warning: rule useless in grammar [-Wother]
: '('')'
^^^^^^
gram.y:75.19-39: warning: rule useless in grammar [-Wother]
| '(' formalparlist ')'
^^^^^^^^^^^^^^^^^^^^^
gram.y:79.19-31: warning: rule useless in grammar [-Wother]
: formalparitem
^^^^^^^^^^^^^
gram.y:80.19-35: warning: rule useless in grammar [-Wother]
| formalparlist ','
^^^^^^^^^^^^^^^^^
gram.y:84.19-31: warning: rule useless in grammar [-Wother]
: IN IDENTIFIER
^^^^^^^^^^^^^
gram.y:85.19-34: warning: rule useless in grammar [-Wother]
| INOUT IDENTIFIER
^^^^^^^^^^^^^^^^
gram.y:88.19-46: warning: rule useless in grammar [-Wother]
: statement statement_sequence
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
gram.y:91.19-30: warning: rule useless in grammar [-Wother]
: ";"statement
^^^^^^^^^^^^
gram.y:92.19-50: warning: rule useless in grammar [-Wother]
| ';' statement statement_sequence
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
gram.y:95.19-34: warning: rule useless in grammar [-Wother]
: '{' sequence '}'
^^^^^^^^^^^^^^^^
gram.y:98.19-30: warning: rule useless in grammar [-Wother]
: brackets_seq
^^^^^^^^^^^^
gram.y:99.19-27: warning: rule useless in grammar [-Wother]
| statement
^^^^^^^^^
gram.y:104.19-24: warning: rule useless in grammar [-Wother]
: %empty
^^^^^^
gram.y:105.19-33: warning: rule useless in grammar [-Wother]
| assignment_stat
^^^^^^^^^^^^^^^
gram.y:106.19-25: warning: rule useless in grammar [-Wother]
| if_stat
^^^^^^^
gram.y:107.19-31: warning: rule useless in grammar [-Wother]
| do_while_stat
^^^^^^^^^^^^^
gram.y:108.19-28: warning: rule useless in grammar [-Wother]
| while_stat
^^^^^^^^^^
gram.y:109.19-29: warning: rule useless in grammar [-Wother]
| select_stat
^^^^^^^^^^^
gram.y:110.19-27: warning: rule useless in grammar [-Wother]
| exit_stat
^^^^^^^^^
gram.y:111.19-29: warning: rule useless in grammar [-Wother]
| return_stat
^^^^^^^^^^^
gram.y:112.19-28: warning: rule useless in grammar [-Wother]
| print_stat
^^^^^^^^^^
gram.y:113.19-27: warning: rule useless in grammar [-Wother]
| call_stat
^^^^^^^^^
gram.y:116.19-45: warning: rule useless in grammar [-Wother]
: IDENTIFIER EXACT IDENTIFIER
^^^^^^^^^^^^^^^^^^^^^^^^^^^
gram.y:120.19-60: warning: rule useless in grammar [-Wother]
: IF '(' condition')' brack_or_stat elsepart
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
gram.y:123.19-24: warning: rule useless in grammar [-Wother]
: %empty
^^^^^^
gram.y:124.19-36: warning: rule useless in grammar [-Wother]
| ELSE brack_or_stat
^^^^^^^^^^^^^^^^^^
gram.y:127.19-54: warning: rule useless in grammar [-Wother]
: WHILE '(' condition')' brack_or_stat
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
gram.y:130.19-132.42: warning: rule useless in grammar [-Wother]
: SELECT'(' IDENTIFIER')'
^^^^^^^^^
gram.y:135.19-52: warning: rule useless in grammar [-Wother]
: DECIMAL_CONSTANT ':' brack_or_stat
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
gram.y:136.19-25: warning: rule useless in grammar [-Wother]
| dec ','
^^^^^^^
gram.y:139.19-58: warning: rule useless in grammar [-Wother]
: DO brack_or_stat WHILE '(' condition ')'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
gram.y:142.19-22: warning: rule useless in grammar [-Wother]
: EXIT
^^^^
gram.y:145.19-43: warning: rule useless in grammar [-Wother]
: RETURN '(' expression ')'
^^^^^^^^^^^^^^^^^^^^^^^^^
gram.y:148.19-41: warning: rule useless in grammar [-Wother]
: PRINT '('expression ')'
^^^^^^^^^^^^^^^^^^^^^^^
gram.y:151.19-44: warning: rule useless in grammar [-Wother]
: CALL IDENTIFIER actualpars
^^^^^^^^^^^^^^^^^^^^^^^^^^
gram.y:154.19-24: warning: rule useless in grammar [-Wother]
: '('')'
^^^^^^
gram.y:155.19-37: warning: rule useless in grammar [-Wother]
| '('actualparlist')'
^^^^^^^^^^^^^^^^^^^
gram.y:158.19-31: warning: rule useless in grammar [-Wother]
: actualparitem
^^^^^^^^^^^^^
gram.y:159.19-35: warning: rule useless in grammar [-Wother]
| actualparlist ','
^^^^^^^^^^^^^^^^^
gram.y:162.19-31: warning: rule useless in grammar [-Wother]
: IN expression
^^^^^^^^^^^^^
gram.y:163.19-34: warning: rule useless in grammar [-Wother]
| INOUT IDENTIFIER
^^^^^^^^^^^^^^^^
gram.y:166.19-38: warning: rule useless in grammar [-Wother]
: boolterm or_boolterm
^^^^^^^^^^^^^^^^^^^^
gram.y:169.19-29: warning: rule useless in grammar [-Wother]
: OR boolterm
^^^^^^^^^^^
gram.y:170.19-41: warning: rule useless in grammar [-Wother]
| OR boolterm or_boolterm
^^^^^^^^^^^^^^^^^^^^^^^
gram.y:173.19-43: warning: rule useless in grammar [-Wother]
: boolfactor and_boolfactor
^^^^^^^^^^^^^^^^^^^^^^^^^
gram.y:176.19-32: warning: rule useless in grammar [-Wother]
: AND boolfactor
^^^^^^^^^^^^^^
gram.y:177.19-47: warning: rule useless in grammar [-Wother]
| AND boolfactor and_boolfactor
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
gram.y:180.19-39: warning: rule useless in grammar [-Wother]
: NOT '[' condition ']'
^^^^^^^^^^^^^^^^^^^^^
gram.y:181.19-35: warning: rule useless in grammar [-Wother]
| '[' condition ']'
^^^^^^^^^^^^^^^^^
gram.y:182.19-55: warning: rule useless in grammar [-Wother]
| expression relational_oper expression
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
gram.y:185.19-50: warning: rule useless in grammar [-Wother]
: optional_sign term add_oper_term
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
gram.y:188.19-31: warning: rule useless in grammar [-Wother]
: add_oper term
^^^^^^^^^^^^^
gram.y:189.19-45: warning: rule useless in grammar [-Wother]
| add_oper term add_oper_term
^^^^^^^^^^^^^^^^^^^^^^^^^^^
gram.y:192.19-40: warning: rule useless in grammar [-Wother]
: factor mul_oper_factor
^^^^^^^^^^^^^^^^^^^^^^
gram.y:195.19-49: warning: rule useless in grammar [-Wother]
: mul_oper factor mul_oper_factor
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
gram.y:196.19-33: warning: rule useless in grammar [-Wother]
| mul_oper factor
^^^^^^^^^^^^^^^
gram.y:199.19-34: warning: rule useless in grammar [-Wother]
: DECIMAL_CONSTANT
^^^^^^^^^^^^^^^^
gram.y:200.19-28: warning: rule useless in grammar [-Wother]
| expression
^^^^^^^^^^
gram.y:201.19-35: warning: rule useless in grammar [-Wother]
| IDENTIFIER idtail
^^^^^^^^^^^^^^^^^
gram.y:204.19-24: warning: rule useless in grammar [-Wother]
: %empty
^^^^^^
gram.y:205.19-28: warning: rule useless in grammar [-Wother]
| actualpars
^^^^^^^^^^
gram.y:208.19-21: warning: rule useless in grammar [-Wother]
: '='
^^^
gram.y:209.19-21: warning: rule useless in grammar [-Wother]
| '<'
^^^
gram.y:210.19-22: warning: rule useless in grammar [-Wother]
| "<="
^^^^
gram.y:211.19-22: warning: rule useless in grammar [-Wother]
| "<>"
^^^^
gram.y:212.19-22: warning: rule useless in grammar [-Wother]
| ">="
^^^^
gram.y:213.19-21: warning: rule useless in grammar [-Wother]
| '>'
^^^
gram.y:216.19-21: warning: rule useless in grammar [-Wother]
: '+'
^^^
gram.y:217.19-21: warning: rule useless in grammar [-Wother]
| '-'
^^^
gram.y:220.19-21: warning: rule useless in grammar [-Wother]
: '*'
^^^
gram.y:221.19-21: warning: rule useless in grammar [-Wother]
| '/'
^^^
gram.y:224.19-26: warning: rule useless in grammar [-Wother]
: add_oper
^^^^^^^^
gram.y:225.19-24: warning: rule useless in grammar [-Wother]
| %empty
^^^^^^
最佳答案
问题是您生产的subprograms
。
但是,对于您(以及可能偶然发现此问题和答案的任何同学)来说,了解如何自行查找此类问题可能更有用。
StackOverflow鼓励您提供一个"Minimal, Complete and Verifiable Example" (MCVE),您应该花一点时间阅读该帮助页面。要求不是因为我们喜欢让有疑问的人生活变得困难。这是因为将问题减少到最低程度是调试的关键部分,您会发现,随着习惯的发展,发现问题的能力越来越强。当然,由于它消除了所有不相关的噪音,它还可以帮助尝试解决问题的任何人。
但是MCVE不仅很小。它也是完整的:也就是说,它是摘录,实际上显示了问题所在。仅说“我认为问题出在这里,所以我将仅演示这一部分”是不够的。您必须通过创建最小示例并证明确实会产生相同的问题,来实际证明问题所在。
实际上,如果您牢记此策略,则将以不同的方式编写程序。您无需编写一千行代码,然后将其全部输入到编译器中,而是将编写一些独立的部分并在将它们组合成一个整体之前对其进行检查。这样,当您无法解决特定问题时,就已经拥有MCVE。
语法令人讨厌地相互联系,并且不像人们希望的程序那样模块化。一个生产中的少量更改会产生移位减少冲突,涉及另一个看似完全无关的生产。但是,您通常可以将语法分成或多或少的独立部分。例如,您可以仅从定义表达式的语法部分开始:
%token PROGRAM
%token IDENTIFIER
%token DECIMAL_CONSTANT
%token DECLARE ENDDECLARE
%token AND CALL DEFAULT
%token FUNCTION PROCEDURE IN INOUT
%token IF ELSE DO WHILE FOR OR NOT SELECT
%token RETURN EXIT PRINT
%token EQ_LT EQ_GT NE EXACT
%left '+' '-'
%right '*' '/'
%%
expression
: optional_sign term add_oper_term
;
add_oper_term
: add_oper term
| add_oper term add_oper_term
;
term
: factor mul_oper_factor
;
mul_oper_factor
: mul_oper factor
| mul_oper factor mul_oper_factor
;
factor
: DECIMAL_CONSTANT
| expression
| IDENTIFIER idtail
;
idtail
: %empty
| actualpars
;
add_oper
: '+'
| '-'
;
mul_oper
: '*'
| '/'
;
optional_sign
: add_oper
| %empty
;
actualpars
: '('')'
| '('actualparlist')'
;
actualparlist
: actualparitem
| actualparlist ','
;
actualparitem
: IN expression
| INOUT IDENTIFIER
;
%token
声明留在了适当的位置,因此上述内容并不是很简单。Bison不在乎是否声明了从未使用过的端子,因此将其保留在下一个位置更容易脚步。)
condition
,其中涉及添加:
condition
: boolterm or_boolterm
;
or_boolterm
: OR boolterm
| OR boolterm or_boolterm
;
boolterm
: boolfactor and_boolfactor
;
and_boolfactor
: AND boolfactor
| AND boolfactor and_boolfactor
;
boolfactor
: NOT '[' condition ']'
| '[' condition ']'
| expression relational_oper expression
;
relational_oper
: '='
| '<'
| "<="
| "<>"
| ">="
| '>'
;
brack_or_stat
,它已定义:
brack_or_stat
: brackets_seq
| statement
;
brackets_seq
,我们可以将其临时添加到终端列表中。 (这是隐藏语法细节的标准技术。)稍后,当我们包含
brackets_seq
的产生式时,我们可以删除
%token
声明。)因此,我们现在添加
%token brackets_seq
before the `%%`, and the statement productions after it:
brack_or_stat
: brackets_seq
| statement
;
statement
: %empty
| assignment_stat
| if_stat
| do_while_stat
| while_stat
| select_stat
| exit_stat
| return_stat
| print_stat
| call_stat
;
assignment_stat
: IDENTIFIER EXACT IDENTIFIER
;
if_stat
: IF '(' condition')' brack_or_stat elsepart
;
elsepart
: %empty
| ELSE brack_or_stat
;
while_stat
: WHILE '(' condition')' brack_or_stat
;
select_stat
: SELECT'(' IDENTIFIER')'
dec
DEFAULT":" brack_or_stat
;
dec
: DECIMAL_CONSTANT ':' brack_or_stat
| dec ','
;
do_while_stat
: DO brack_or_stat WHILE '(' condition ')'
;
exit_stat
: EXIT
;
return_stat
: RETURN '(' expression ')'
;
print_stat
: PRINT '('expression ')'
;
call_stat
: CALL IDENTIFIER actualpars
;
statement
可以,那么将其设为终端,并从测试中删除该终端及其引用的所有非终端。这给我们留下了一个简单得多的程序:(当我复制并粘贴此摘录并通过野牛运行时,它告诉我
assignment_stat
未定义。因此我将其添加到了
%token
声明中。)
%token PROGRAM
%token IDENTIFIER
%token DECIMAL_CONSTANT
%token DECLARE ENDDECLARE
%token AND CALL DEFAULT
%token FUNCTION PROCEDURE IN INOUT
%token IF ELSE DO WHILE FOR OR NOT SELECT
%token RETURN EXIT PRINT
%token EQ_LT EQ_GT NE EXACT
%token statement assignment_stat
%start program
%%
program
: %empty
| PROGRAM IDENTIFIER block
;
block
: "{" declarations subprograms sequence "}"
;
declarations
: %empty
| DECLARE varlist ENDDECLARE
;
varlist
: %empty
| assignment_stat identifier2
;
identifier2 : ',' assignment_stat
| ',' assignment_stat
;
subprograms
: func
| subprograms ','
;
func
: PROCEDURE IDENTIFIER funcbody
| FUNCTION IDENTIFIER funcbody
;
funcbody
: formalpars block
;
formalpars
: '('')'
| '(' formalparlist ')'
;
formalparlist
: formalparitem
| formalparlist ','
;
formalparitem
: IN IDENTIFIER
| INOUT IDENTIFIER
;
sequence
: statement statement_sequence
;
statement_sequence
: ";"statement
| ';' statement statement_sequence
;
brackets_seq
: '{' sequence '}'
;
brack_or_stat
: brackets_seq
| statement
;
subprograms
: func
| subprograms ','
func : PROCEDURE IDENTIFIER funcbody
| FUNCTION IDENTIFIER funcbody
funcbody: formalpars block
block: "{" declarations subprograms sequence "}"
subprograms
有两个结果。第二个显然是递归的。但是只需花很少的工作就可以看到另一个也是递归的:
func
有两个产生式,但是都使用
funcbody
;
funcbody
的唯一生产使用
block
,而
block
使用
subprograms
。
subprograms
没有非递归的产生,因此它永远不会脱离递归。而且
func
,
funcbody
或
block
都不可以。
block
无法生成任何语句,则
program
(
PROGRAM IDENTIFIER block
)的第二个产生形式也不会生成任何语句,而
program: %empty
作为起始符号的唯一有效产生形式。这使空字符串成为唯一有效的
program
,因此,野牛将所有其他非终端标记为无用。
subprograms
(正如我一开始所说的,这是当前的问题)。定义是:
subprograms
: func
| subprograms ','
subprograms
是
func
或
subprograms
,后跟逗号。因此它将产生:
func
func ,
func , ,
func , , ,
func , , , ,
func
,后跟零个或多个逗号。它必须具有一个func,而不能具有更多。
block
必须包含
subprograms
,并且
subprograms
必须包含单个
func
。但是
func
必须包含
block
。从那个旋转木马也无法逃脱。
subprograms
不能为空,并且也不能包含多个
func
。您可能正在寻找的是:
function_list: func
| function_list ',' func
subprograms : %empty
| function_list
function_list
使用左递归。那是故意的。野牛产生LR解析器,它喜欢左递归。
关于c - 建立 Bison 语法时,终端上显示了太多无用的规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43712500/
我正在尝试使用 Excel 中的间接函数来构建公式以在另一张纸上返回值。 在工作表 A 单元格 D3 的值为 B 我想使用值 B 从名为 App Summary 的工作表中的单元格 B6 返回一个值。
我目前正在使用 LumiSoft 的 SIP 堆栈,并且能够在我的 FreePBX 盒子上成功注册分机并调用另一个软电话。我现在需要做的就是通过调用流式传输 WAV 文件(或 RAW,或任何可行的文件
这个问题已经有答案了: How can I fix 'android.os.NetworkOnMainThreadException'? (65 个回答) 已关闭 8 年前。 我有一个安卓 Activ
我正在使用 ws npm 在服务器端,websocket 在客户端。 从 node-js 运行此代码时它工作正常,但从浏览器运行它会出现以下错误: failed: Error in connectio
当我将鼠标悬停在想要淡入和淡出的内容上多次时,它就会不断重复。即使我停止悬停它。我怎样才能阻止这个? $(".featured").hover(function(){ $(this).find
我需要建立一个 mysql 连接并取回一些数据。我可以使用此代码在 Java 中执行此操作 try{ String username;
不能制造愚蠢。具有下一个文件夹结构: /flint/double-conversion/src /燧石/愚蠢/愚蠢/ 其中/flint/folly 包含自述文件和许可证。作为in the readme
我想在编译主单元之前在程序集中嵌入本地引用。但书面目标不起作用。 WithMetadataValue( 'CopyLocal', 'true' )->Met
我不是软件专家,但我确实需要一些建议。 我正在编写一个 C 程序(在下面剪切/粘贴)以通过 LAN(以太网)建立从我的 Mac Pro 到位于它旁边的基于 Windows XP 的测试仪器的 TCP
我正在构建一个应用程序,我的手机经常将数据发送到我的服务器。由于我将使用我的移动数据,我想知道建立(和拆除?)到我的服务器的 TCP 连接需要多少数据。 最佳答案 TCP 三向握手 Device 1
我有一个带有登录表单的网站。当加载登录表单页面时,我创建一个新的 PDO 对象以查看连接是否正常工作。如果成功打开连接,查看者将看到一个登录表单。如果不成功,他们会收到一条消息,说明服务器已关闭。 然
构建我的Electron应用程序后,它将显示产品名称undefined。如何设置其他名称呢? 当前是这样的: 最佳答案 请尝试此操作。引用此链接 https://www.electronjs.org/
我有一个项目在哪里使用这个 jar 。 据我所知...发生 war 之后,文件夹WEB-INF/lib必须具有: mail-1.4.1.jar activation-1.1.jar mysql-con
代码: %{ #include #include #include #include "gener.h" #include "sym_tab.h" #include "scope.h" #inc
我需要将侧边栏小部件集成到我的高流量页面(称为SiteA)中。该小部件应包含我的其他页面之一(称为 SiteB)的最新文章。 在我看来,我有两种可能的解决方案。 SiteA 上的 cUrl 调用从 S
我正在尝试建立 Cortana 技能,以便能够使用 Surface 相机拍照。怎么做?目前我的技能是能够使用bot框架和使用nodejs来回答问题。代码看起来像 bot.dialog('ScanCar
这个问题在这里已经有了答案: Resolving javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorExce
当我与网络服务器建立 https 连接时出现 SSLProtocolException。我只在 Android 2.3 Gingebread 中有这个异常(exception);相同的代码在所有其他
我想做的是指定几个端口,然后检查它们是否已建立连接。我找到了以下脚本并运行了,但它只列出了 3 个端口,我不明白为什么。我验证了相关端口的事件规则(以及下面输出中未列出的许多其他端口)。 Set ob
使用 MySQL 我试图使用已经上传到数据库中的数据建立一对多关系。举个例子,假设我在一个表中有一个名字列表,我想将它们连接到一个他们去过的地方的列表。显然 1 个人可以去很多不同的地方,但我在设置时
我是一名优秀的程序员,十分优秀!