compiler construction - Does this grammar allow scope nesting? -


I'm only able to work in the global field. Scope nest means being able to work within the job is correct ? I am not able to do this with this grammar, is it possible?

  / * C-Minas BNF grammar * /% token ELSE% token if% token INT% token returns% token void% token WHILE% token id% token NUM% token lte% token gte% Token EQUAL% Token Notices %% Program: Announcement_list; Declaration: Declaration declaration_list | Declaration; Announcement: var_declaration | Fun_declaration; Var_declaration: type_specifier id ';' | Type_specifier ID '[' NUM ']' ';' ; Type_specifier: INT | Zero; Fun_declaration: type_specifier ID '(' params ')' compound_stmt; Params: Ultimate_list | Zero; Param_list: param_list ',' Ultimate | Ultimate; Ultimate: type_specifier id | Type_specifier ID '[']] '; Compound_stmt: '{' local_declarations statement_list '}'; Local_declarations: local_declarations var_declaration | / * Below * /; Statement_list: statement_list statement | / * Below * /; Statement: Expression_Stom | Compound_stmt | Selection_stom | Iteration_stmt | Return_stmt; Expression_stmt: expression ';' | ';' ; Select_stmt: if '(' expression ')' statement | IF '(' Expression ')' Statement Else Statement; Iteration_stmt: WHILE '(' expression ')' statement; Return_stmt: Returns ';' | Return expression ';' ; Expression: var '=' expression | Simple_express; Var: id | ID '[' expression ']'; Simple_preview: additive_expression relop additive_expression | Additive_expression; Relop: LTE | '& Lt;' | '& Gt;' | GTE | Equal | Not equal; Additive_expression: additive_expression addop word | word; Plus: '+' | '-'; Word: word miyilop factor | Factor; Mulop: '*' | '/'; Factor: '(' expression ')' | Var | Call | NUM; Call: ID '(' Args ')'; Args: arg_list | / * Below * /; Arg_list: arg_list ',' expression | Expression; Actually, a grammar does not show a scope. It is just that you can see the signals. How to deal with the materials, which determines the scope. 

It has been said that there may be a global scope in this grammar and the scope presented by a magnitude statement can be. In the global scope, you can declare variables and functions. In the field of compound statements, you can declare variables only.

If you want to support nested functions, then allow grammar to declare a function inside compound statements.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -