|
接上一份的 flex文件,
下面是realw写的st语言的bison文件。
- %code top{
- #include <stdio.h>
- #include <stdlib.h>
- }
- %code requires{
- #define YYLTYPE YYLTYPE
- typedef struct PlcSrcLocation YYLTYPE;
- typedef void* yyscan_t;
- #define YYLTYPE_IS_TRIVIAL 1
- }
- %code provides{
- #define YY_DECL int yylex \
- (YYSTYPE *yylval_param,YYLTYPE *yylloc_param,struct PlcCContext *context,yyscan_t yyscanner)
-
- YY_DECL;
- }
- %code {
- void yyerror(YYLTYPE *loc,yyscan_t yyscanner,const char *msg);
- }
- /* Page 97,4.1,there is an example. */
- %param { yyscan_t yyscanner }
- /* Page 84 for yylex(YYSTYPE*,YYLTYPE*) */
- %locations
- %define api.pure full
- /* enable run-time debug */
- %define parse.trace
- /* generate the parse description file. */
- %verbose
- /* verbose error reporting, 4.7 The Error Reporting Function*/
- %define parse.error verbose
- /* LAC enable, 5.8.3 LAC*/
- %define parse.lac full
- %start pou
- %%
- pou:
- %empty
- {
- }
- | stmt_list
- {
- }
- ;
- stmt_list:
- statement
- {
- }
- | stmt_list statement
- {
- }
- ;
- statement:
- ';'
- {
- }
- | assignment_statement
- {
- }
- | selection_statement
- {
- }
- | function_call_statement
- {
- }
- | jump_statement
- {
- }
- | goto_label_statement
- {
- }
- | error_statement
- {
- }
- ;
- function_call_statement:
- function_call ';'
- {
- };
- error_statement:
- error ';'
- {
- }
- | error ':'
- {
- }
- ;
- jump_statement:
- return_statement
- {
- }
- | goto_statement
- {
- }
- ;
- return_statement:
- RETURN ';'
- {
- }
- | RETURN expression ';'
- {
- }
- ;
- goto_statement:
- GOTO IDENTIFIER ';'
- {
- }
- ;
- goto_label_statement:
- IDENTIFIER ':' statement
- {
- }
- ;
- assignment_statement:
- sym_variable ASSIGN expression ';'
- {
- }
- ;
- selection_statement:
- if_statement
- {
- }
- ;
- if_statement:
- IF expression THEN stmt_list END_IF
- {
- }
- | IF expression THEN stmt_list elseif_stmt_list END_IF
- {
- }
- | IF expression THEN stmt_list ELSE stmt_list END_IF
- {
- }
- | IF error END_IF
- {
- }
- | IF expression THEN error END_IF
- {
- }
- ;
- elseif_stmt_list:
- elseif_statement
- {
- }
- | elseif_stmt_list elseif_statement
- {
- }
- ;
- elseif_statement:
- ELSIF expression THEN stmt_list
- {
- }
- ;
- expression:
- bitwise_or_expression
- {
- }
- ;
- bitwise_or_expression:
- bitwise_xor_expression
- {
- }
- | bitwise_or_expression OR bitwise_xor_expression
- {
- }
- ;
- bitwise_xor_expression:
- bitwise_and_expression
- {
- }
- | bitwise_xor_expression XOR bitwise_and_expression
- {
- }
- ;
- bitwise_and_expression:
- equality_expression
- {
- }
- | bitwise_and_expression '&' equality_expression
- {
- }
- | bitwise_and_expression AND equality_expression
- {
- }
- ;
- equality_expression:
- relation_expression
- {
- }
- | equality_expression '=' relation_expression
- {
- }
- | equality_expression NE_OP relation_expression
- {
- }
- ;
- relation_expression:
- additive_expression
- {
- }
- | relation_expression '<' additive_expression
- {
- }
- | relation_expression '>' additive_expression
- {
- }
- | relation_expression LE_OP additive_expression
- {
- }
- | relation_expression GE_OP additive_expression
- {
- }
- ;
- additive_expression:
- multiplication_expression
- {
- }
- | additive_expression '+' multiplication_expression
- {
- }
- | additive_expression '-' multiplication_expression
- {
- }
- ;
- multiplication_expression:
- exp_expression
- {
- }
- | multiplication_expression '*' exp_expression
- {
- }
- | multiplication_expression '/' exp_expression
- {
- }
- | multiplication_expression MOD exp_expression
- {
- }
- ;
- exp_expression:
- unary_expression
- {
- }
- | exp_expression EXP_OP unary_expression
- {
- }
- ;
- unary_expression:
- primary_expression
- {
- }
- | unary_operator primary_expression
- {
- }
- ;
- unary_operator:
- '-'
- {
- }
- | NOT
- {
- }
- | '+'
- {
- }
- ;
- primary_expression:
- literal
- {
- }
- | paren_expr
- {
- }
- | sym_variable
- {
- }
- | function_call
- {
- }
- ;
- paren_expr:
- '(' expression ')'
- {
- };
- literal:
- TYPE_PREFIX LITERAL_VALUE
- {
- }
- | LITERAL_VALUE
- {
- };
- sym_variable:
- IDENTIFIER
- {
- }
- | sym_variable '.' IDENTIFIER
- {
- }
- | sym_variable '[' expression ']'
- {
- }
- | sym_variable '[' error ']'
- {
- }
- | sym_variable '.' error
- {
- }
- ;
-
- function_call:
- IDENTIFIER '(' parameter_list ')'
- {
- }
- ;
- parameter_list:
- %empty
- {}
- | parameter_init
- {
- }
- | parameter_list ',' parameter_init
- {
- }
- ;
- parameter_init:
- IDENTIFIER ASSIGN expression
- {
- }
- | error
- {
- }
- ;
- %%
- void yyerror(YYLTYPE *loc,yyscan_t yyscanner,const char *msg){
- }
复制代码
已经经过了基本测试。
以上。 realw
|
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|