📄 parser.y
字号:
| STEP step;if_expr: IF if_expr_body FI { };if_expr_body: expr then_alternative else_alternative;else_alternative: ELSIF if_expr_body { }| ELSE expr { };opt_prefix_clause: PREFIXED opt_name_string| /* empty */;else_clause: ELSIF expr then_clause { }| ELSIF expr then_clause else_clause { }| ELSE opt_actions { };then_clause: THEN opt_actions { };then_alternative: THEN expr;tuple: LEFTTUPLE RIGHTTUPLE| LEFTTUPLE tuple_element_list RIGHTTUPLE;tuple_element_list: tuple_element| tuple_element_list ',' tuple_element;tuple_element: tuple_fieldname_list ':' expr| case_label_list ':' expr| expr ':' expr| expr;tuple_fieldname_list: '.' NAME | tuple_fieldname_list ',' '.' NAME ',';opt_actions: opt_actions action| opt_actions NAME ':' action| opt_actions NAME '(' args ')' end { emit_xref_procedure($2.name, $2.line); }| opt_actions NAME ':' NAME '(' args ')' end { emit_xref_procedure($4.name, $4.line); }| opt_actions variable_list ASSIGN expr end { emit_xref_assignment($2); }| opt_actions NAME ':' variable_list ASSIGN expr end { emit_xref_assignment($4); }| opt_actions variable_list dyadic_operator ASSIGN expr end { emit_xref_assignment($2); }| opt_actions NAME ':' variable_list dyadic_operator ASSIGN expr end { emit_xref_assignment($4); }| /* empty */;body: body definition| body NAME ':' PROC { set_proc_name($2.name); } procedure_definition { emit_procedure(&$2, $6); }| body NAME ':' PROCESS { set_process_name($2.name); } process_definition { emit_process(&$2, $6); }| body { emit = 1; } action { emit = 0; }| body NAME ':' { emit = 1; } action { emit = 0; }| body NAME '(' args ')' end { emit_xref_procedure($2.name, $2.line); }| body NAME ':' NAME '(' args ')' end { emit_xref_procedure($4.name, $4.line); }| body variable_list ASSIGN { emit = 1; } expr { emit = 0; } end { emit_xref_assignment($2); }| body NAME ':' variable_list ASSIGN expr end { emit_xref_assignment($4); }| body variable_list dyadic_operator ASSIGN expr end { emit_xref_assignment($2); }| body NAME ':' variable_list dyadic_operator ASSIGN expr end { emit_xref_assignment($4); }| /* empty */; definition: DCL declaration_stmt ';'| GRANT grant_stmt ';'| NEWMODE mode_definition_stmt ';'| SEIZE seize_stmt ';'| SIGNAL signal_definition_stmt ';'| SYN synonym_definition_stmt ';'| SYNMODE mode_definition_stmt ';';synonym_definition: def_occ_list mode '=' expr { emit_synonyms($1, $2.text); }| def_occ_list '=' expr { emit_synonyms($1, "unknown"); }| def_occ_list '=' NAME expr { emit_synonyms($1, "unknown"); };synonym_definition_stmt: synonym_definition| synonym_definition_stmt ',' synonym_definition;declaration_stmt: declaration| declaration_stmt ',' declaration;declaration: def_occ_list mode opt_based opt_loc opt_init opt_assign opt_handler { /* We have a bunch of names and their mode. */ if (local) { remember_locals($1); } emit_declarations($1, $2.text); }| def_occ_list mode STATIC opt_based opt_loc opt_init opt_assign opt_handler { /* Likewise, but take qualifiers into account. */ if (local) { remember_locals($1); } emit_declarations($1, $2.text); };variable_list: variable { $$ = ckalloc(sizeof(struct identifierlist)); memcpy($$, &$1, sizeof(struct identifier)); $$->next = NULL; }| variable_list ',' variable { $$ = ckalloc(sizeof(struct identifierlist)); memcpy($$, &$3, sizeof(struct identifier)); $$->next = $1; };opt_assign: ASSIGN { emit = 1; } expr { emit = 0; }| /* empty */;opt_based: BASED '(' name_string ')'| /* empty */;opt_loc: LOC { $$ = $1; }| /* empty */ { $$.text = SN_StrDup(""); };opt_init: INIT| /* empty */;on_alternatives: on_alternatives on_exception_list| on_alternatives action| /* empty */;iteration: variable_list ASSIGN expr TO expr { emit_xref_assignment($1); }| variable_list ASSIGN expr BY expr TO expr { emit_xref_assignment($1); }| variable_list ASSIGN expr DOWN TO expr { emit_xref_assignment($1); } | variable_list ASSIGN expr BY expr DOWN TO expr { emit_xref_assignment($1); }| variable_list IN expr { }| variable_list DOWN IN expr { };case_expr: CASE expr_list OF case_way_list ESAC { }| CASE expr_list OF case_way_list ELSE expr ESAC { };case_way_list: case_way { }| case_way_list case_way { };case_way: '(' case_label_specification ':' expr ';';case_label_list: '(' '*' ')'| '(' case_label_list2 ')';case_label_list2: case_label| case_label_list2 ',' case_label;case_label_specification: case_label_list| case_label_specification ',' case_label_list;case_label: ELSE| expr| expr ':' expr;do_action: DO opt_actions OD| DO FOR EVER ';' opt_actions OD| DO FOR iteration_list ';' opt_actions OD| DO FOR iteration_list WHILE expr ';' opt_actions OD| DO WHILE expr ';' opt_actions OD| DO WITH { activate_with(); } expr ';' opt_actions { leave_with(); } OD;variant_alternative: fixed_field| ':' fixed_field| case_label_specification ':' fixed_field;index_mode_list: index_mode { }| index_mode_list ',' index_mode { };index_mode: NAME '(' expr ':' expr ')' { }| mode { $$ = $1; }| expr ':' expr { };iteration_list: iteration { }| iteration_list ',' iteration { };opt_forbid: FORBID /* no names, as per GNU CHIILL */| FORBID ALL| /* empty */;postfix_list: postfix| postfix_list ',' postfix;postfix: opt_name_string opt_forbid { /* forbid for GRANT only, but we'll relax it */ };mode_definition_stmt: mode_definition| mode_definition_stmt ',' mode_definition;mode_definition: def_occ_list '=' mode { emit_type_synonyms($1, $3.text); };procedure_definition: '(' param_list ')' opt_result_spec opt_except opt_procedureattr opt_semicolon proc_body { unsigned length = 0; struct identifierlist * idlist = $2; while (idlist != NULL) { length += strlen(idlist->name); if (idlist->next != NULL) { length += 2; /* ", " */ } idlist = idlist->next; } $$.args = ckalloc((length + 1)*sizeof(char)); memset ($$.args, 0, (length + 1)*sizeof(char)); idlist = $2; while (idlist != NULL) { strcat($$.args, idlist->name); if (idlist->next != NULL) { strcat($$.args, ", "); } idlist = idlist->next; } $$.rettype = $4.text; } | '(' ')' opt_result_spec opt_except opt_procedureattr opt_semicolon proc_body { $$.rettype = $3.text; $$.args = NULL; };opt_except: EXCEPTIONS '(' ')'| EXCEPTIONS '(' name_string_list ')'| /* empty */;name_string_list: name_string { }| name_string_list ',' name_string { };opt_name_string: name_string { }| /* empty */ { $$.name = SN_StrDup(""); };name_string: NAME '!' opt_name_string { $$ = $1; }| NAME { $$ = $1; }| ALL { };pos: '(' expr ')'| '(' expr ',' expr ')'| '(' expr ',' expr ',' expr ')'| '(' expr ',' expr ':' expr ')';step: '(' POS pos ')'| '(' POS pos ',' expr ')';proc_body: { local = 1; } body { local = 0; } END end;process_definition: '(' param_list ')' { local = 1; } opt_semicolon proc_body { $$.rettype = NULL; $$.args = NULL; /* for now */ local = 0; }| '(' ')' { local = 1; } opt_semicolon proc_body { $$.rettype = NULL; $$.args = NULL; /* for now */ local = 0; };param_list: param { $$ = ckalloc(sizeof(struct identifierlist)); $$->name = $1.text; $$->next = NULL; }| param_list ',' param { $$ = ckalloc(sizeof(struct identifierlist)); $$->name = $3.text; $$->next = $1; };param: def_occ_list mode param_attr { struct identifierlist * idlist = $1; $$.text = NULL; /* Emit the actual local variable declarations produced by these formal parameters while we have context. */ emit_declarations($1, $2.text); remember_locals($1); while (idlist != NULL) { unsigned length = strlen(idlist->name) + 1 + strlen($2.text) + 1 + strlen($3.text) + 2 /* ", " */; if ($$.text == NULL) { $$.text = ckalloc(length + 1 /*NUL*/); $$.text[0] = 0; } else { $$.text = ckrealloc($$.text, strlen($$.text) + length); } /* Now populate the string. */ strcat($$.text, idlist->name); strcat($$.text, " "); strcat($$.text, $2.text); if (strcmp($3.text, "") != 0) { strcat($$.text, " "); strcat($$.text, $3.text); } strcat($$.text, ", "); if (idlist->next == NULL) { $$.text[strlen($$.text) - 2] = 0; } idlist = idlist->next; } } ;mode: ACCESS { $$ = $1; }| ACCESS mode DYNAMIC { $$.text = strjoin($1.text, strjoin($2.text, $3.text)); }| ACCESS mode { $$.text = strjoin($1.text, $2.text); }| ACCESS '(' index_mode ')' { $$.text = (char *) ckalloc(strlen($1.text) + strlen($3.text) + 3); /* (,) and a NULL. */ sprintf($$.text, "%s (%s)", $1.text, $3.text); }| ACCESS '(' index_mode ')' mode { $$.text = (char *) ckalloc(strlen($1.text) + strlen($3.text) + strlen($5.text) + 3); sprintf($$.text, "%s (%s) %s", $1.text, $3.text, $5.text); }| ACCESS '(' index_mode ')' mode DYNAMIC { $$.text = (char *) ckalloc(strlen($1.text) + strlen($3.text) + strlen($5.text) + 3); sprintf($$.text, "%s (%s) %s", $1.text, $3.text, $5.text); }| ARRAY '(' index_mode_list ')' opt_varying mode opt_layout { /* $$.text = strjoin($1.text, strjoin(brackets, $5.text)); */ }| BIN '(' expr ')' { $$ = $1; }| BOOLS '(' expr ')' opt_varying { $$.text = strjoin($1.text, brackets); }| BUFFER '(' expr ')' mode { $$.text = strjoin($1.text, $5.text); }| BUFFER mode { $$.text = strjoin($1.text, $2.text); }| CHARS '(' expr ')' opt_varying { $$.text = strjoin($1.text, brackets); }| EVENT { $$ = $1; }| EVENT '(' expr ')' { $$ = $1; }| mode '(' expr ':' expr ')' { $$.text = strjoin($1.text, brackets); }| mode '(' expr ')' opt_varying { $$.text = strjoin($1.text, brackets); }| NAME { $$.text = $1.name; }| POWERSET mode { $$.text = strjoin($1.text, $2.text); }| procedure_mode { $$ = $1; }| RANGE '(' expr ':' expr ')' { $$ = $1; }| READ mode { $$.text = strjoin($1.text, $2.text); }| REF mode { $$.text = strjoin($1.text, $2.text); }| ROW mode { $$.text = strjoin($1.text, $2.text); }| SET '(' set_list ')' { $$ = $1; emit_enumeration(); emit_enumeration_values($3); }| structure_mode { $$ = $1; }| TEXT '(' expr ')' { $$ = $1; }| TEXT '(' expr ')' DYNAMIC { $$.text = strjoin($1.text, $5.text); }| TEXT '(' expr ')' mode { $$.text = strjoin($1.text, $5.text); }| TEXT '(' expr ')' mode DYNAMIC { $$.text = strjoin($1.text, strjoin($5.text, $6.text)); };param_attr: IN { $$ = $1; }| OUT { $$ =$1; }| INOUT { $$ = $1; }| LOC { $$ = $1; }| DYNAMIC { $$ = $1; }| /* empty */ { $$.text = SN_StrDup(""); };opt_semicolon: ';' { }| /* empty */;%%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -