jueves, 14 de enero de 2010

Gramatica



Esta es la foto de la gramatica del porblema de examen, recursividad elimina por izquierda.



program= program_heading block '.' .
identifier_list= NAME { ',' NAME } .
program_heading= PROGRAM NAME '(' identifier_list ')' ';' .

block= declaration_part statement_part .

label= NUMBER .

formal_parameter_list= '(' formal_parameter_section
{ ';' formal_parameter_section } ')' .
formal_parameter_section= [ VAR ]identifier_list ':' parameter_type .
parameter_type= TYPE_NAME .

constant= [ '+' | '-' ] ( CONSTANT_NAME | NUMBER ) | STRING .
case_label_list= constant { ',' constant } .

type= simple_type | structured_type | pointer_type | procedural_type | TYPE_NAME .
simple_type= subrange_type | enumerated_type .
subrange_type= constant '..' constant .
enumerated_type= '(' identifier_list ')' .
structured_type= [ PACKED ] unpacked_structured_type .
unpacked_structured_type= array_type | record_type | set_type
| file_type .
array_type= ARRAY '[' index_type { ',' index_type } ']' OF
element_type .
index_type= simple_type .
element_type= type .
record_type= RECORD field_list END .
field_list= [ ( fixed_part [ ';' variant_part ] | variant_part ) [ ';' ] ] .
fixed_part= record_section { ';' record_section } .
record_section= identifier_list ':' type .
variant_part= CASE tag_field TYPE_NAME OF variant { ';' variant } .
tag_field= [ NAME ':' ] .
variant= case_label_list ':' '(' field_list ')' .
set_type= SET OF base_type .
base_type= type .
file_type= FILE [ OF file_component_type ] .
file_component_type= type .
pointer_type= '^' TYPE_NAME .
procedural_type= procedure_type | function_type .
procedure_type= PROCEDURE [ formal_parameter_list ] .
function_type= FUNCTION [ formal_parameter_list ] ':' TYPE_NAME .

declaration_part= { label_declaration_part | constant_definition_part |
| type_definition_part | variable_declaration_part
| procedure_and_function_declaration_part } .
label_declaration_part= LABEL label { ',' label } ';' .
constant_definition_part= CONST constant_definition ';'
{ constant_definition ';' } .
constant_definition= NAME '=' constant .
type_definition_part= TYPE type_definition ';' { type_definition ';' } .
type_definition= NAME '=' type .
variable_declaration_part= VAR variable_declaration ';'
{ variable_declaration ';' } .
variable_declaration= identifier_list ':' type .
procedure_and_function_declaration_part=
( procedure_declaration | function_declaration ) ';' .
directive= FORWARD .
procedure_declaration= procedure_heading ';' ( block | directive ) .
procedure_heading= PROCEDURE NAME [ formal_parameter_list ] .
function_declaration= function_heading ';' ( block | directive ) .
function_heading= FUNCTION NAME [ formal_parameter_list ] ':' TYPE_NAME .

statement_part= BEGIN statement_sequence END .
statement_sequence= statement { ';' statement } .

expression= F .
expression_list= expression { ',' expression } .
variable_access= ACCESS_NAME { end_access_ } .
end_access_= { array_access_ | record_access_ | '^' | function_parameters_ } .
array_access_= '[' expression_list ']' .
record_access_= '.' variable_access .
function_parameters_= '(' [ expression_list ] ')' .

actual_parameter_list= '(' actual_parameter { ',' actual_parameter } ')' .
actual_parameter= actual_value | actual_variable | actual_procedure
| actual_function .
actual_procedure= PROCEDURE_NAME .
actual_function= FUNCTION_NAME .
actual_value= expression .
actual_variable= variable_access .

expression= simple_expression [ relational_operator simple_expression ] .
relational_operator= '=' | '<>' | '<' | '<=' | '>' | '>=' | IN .
simple_expression= [ '+' | '-' ] term { addition_operator term } .
addition_operator= '+' | '-' | OR .
term= factor { multiplication_operator factor } .
multiplication_operator= '*' | '/' | DIV | MOD | AND .
factor= NUMBER | STRING | NIL | CONSTANT_NAME | set
| variable_access | function_designator
| '(' expression ')' | NOT factor .
function_designator= FUNCTION_NAME [ actual_parameter_list ] .
set= '[' element_list ']' .
element_list= [ expression { ',' expression } ] .

statement= [ LABEL ':' ] ( simple_statement | structured_statement ) .
simple_statement= [ assignment_statement | procedure_statement
| goto_statement ] .
assignment_statement= ( variable_access | FUNCTION_NAME ) ':=' expression .
procedure_statement= PROCEDURE_NAME [ actual_parameter_list ] .
goto_statement= GOTO label .
structured_statement= compound_statement | repetitive_statement
| conditional_statement | with_statement .
compound_statement= BEGIN statement_sequence END .
repetitive_statement= while_statement | repeat_statement
| for_statement .
while_statement= WHILE expression DO statement .
repeat_statement= REPEAT statement_sequence UNTIL expression .
for_statement= FOR VARIABLE_NAME ':=' initial_expression
( TO | DOWNTO ) final_expression DO statement .
initial_expression= expression .
final_expression= expression .
conditional_statement= if_statement | case_statement .
if_statement= IF expression THEN statement [ ELSE statement ] .
case_statement= CASE expression OF case_element { ';' case_element }
[ ';' ] END .
case_element= case_label_list ':' statement .
with_statement= WITH variable_access { ',' variable_access } DO
statement .
.

Esta es la gramatica exacta de pascal, aqui esta la fuente : http://www.felix-colibri.com/papers/compilers/pascal_grammar/pascal_grammar.html

Saludos !!

No hay comentarios:

Publicar un comentario