Files
School/Anul 3/Semestrul 1/Formal Languages and Compiler Design/g2.txt
T
2025-02-06 20:33:26 +02:00

40 lines
1.4 KiB
Plaintext

G = ({program, statement_list, statement, assignment_stmt, input_stmt, output_stmt, if_stmt, for_stmt, array_decl_stmt, condition, increment_stmt, expression, term, factor, relational_operator, binary_operator, concatenation},{=, (, ), [, ], if, else, for, ARRAY, echo, readline, +, -, *, /, <, <=, ==, >=, !=, ++, --, :, ;, IDENTIFIER, INTEGER_CONST, FLOAT_CONST, STRING_CONST},P, program)
P :
program -> statement_list
statement_list -> statement | statement statement_list
statement -> assignment_stmt | input_stmt | output_stmt | if_stmt | for_stmt | array_decl_stmt
assignment_stmt -> IDENTIFIER = expression
input_stmt -> IDENTIFIER = readline_function ( STRING_CONST )
output_stmt -> echo_function ( STRING_CONST concatenation IDENTIFIER )
if_stmt -> if ( condition ) : statement | if ( condition ) : statement else : statement
for_stmt -> for ( assignment_stmt ; condition ; increment_stmt ) : statement
array_decl_stmt -> IDENTIFIER = ARRAY [ INTEGER_CONST ]
condition -> expression relational_operator expression
increment_stmt -> IDENTIFIER ++ | IDENTIFIER --
expression -> term | term binary_operator expression
term -> factor | factor binary_operator term
factor -> IDENTIFIER | INTEGER_CONST | FLOAT_CONST | STRING_CONST
relational_operator -> < | <= | == | >= | !=
binary_operator -> + | - | * | /
concatenation -> +
echo_function -> echo
readline_function -> readline