%{ #include #include /* Declaracoes C diversas */ %} %token PROGRAM DECLARATIONS STATEMENTS INTEGER BOOLEAN SET ARRAY SIZE TRUE FALSE FORWARD BACKWARD RRIGHT RLEFT %token PEN UP DOWN GOTO WHERE SUCC PREDD ISMEMBER ASK SAY IF THEN ELSE WHILE %token SETA OR AND EQ NE LT GT LE GE %token number %token identifier %token string %% Liss : PROGRAM identifier '{' Body '}' ; Body : DECLARATIONS Declarations STATEMENTS Statements ; Declarations : Declaration | Declarations Declaration ; Declaration : Variable_Declaration ; Variable_Declaration : Vars SETA Type ';' ; Vars : Var | Vars ',' Var ; Var : identifier Value_Var ; Value_Var : | '=' Inic_Var ; Type : INTEGER | BOOLEAN | SET | ARRAY SIZE number ; Inic_Var : Constant | Array_Definition | Set_Definition ; Constant : Sign number | string | TRUE | FALSE ; Sign : | '+' | '-' ; Array_Definition : '[' Array_Initialization ']' ; Array_Initialization : Elem | Array_Initialization ',' Elem ; Elem : Sign number ; Set_Definition : '{' Set_Initialization '}' ; Set_Initialization : | identifier '|' Expression ; Statements : Statement | Statements Statement ; Statement : Turtle_Commands | Assignment | Conditional_Statement | Iterative_Statement ; Turtle_Commands : Step | Rotate | Mode | Dialogue | Location ; Step : FORWARD Expression | BACKWARD Expression ; Rotate : RRIGHT | RLEFT ; Mode : PEN UP | PEN DOWN ; Dialogue : Say_Statement | Ask_Statement ; Location : GOTO number ',' number | WHERE '?' ; Assignment : Variable '=' Expression ; Variable : identifier Array_Acess ; Array_Acess : | '[' Expression ']' ; Expression : Single_Expression | Expression Rel_Oper Single_Expression ; Single_Expression : Term | Single_Expression Add_Op Term ; Term : Factor | Term Mul_Op Factor ; Factor : Constant | Variable | Set_Definition | Member | SuccOrPred | '!' Expression | '+' Expression | '-' Expression | '(' Expression ')' ; Add_Op : '+' | '-' | OR ; Mul_Op : '*' | '/' | AND ; Rel_Op : EQ | NE | LT | GT | LE | GE ; SuccOrPred : SuccPred identifier ; SuccPred : SUCC | PRED ; Member : ISMEMBER '(' Expression ',' Variable ')' ; Say_Statement : SAY '(' Expression ')' ; Ask_Statement : ASK '(' string ',' Variable ')' ; Conditional_Statement: IfThenElse_Stat ; Iterative_Statement : While_Stat ; IfThenElse_Stat : IF Expression THEN '{' Statements '}' Else_Expression ; Else_Expression : | ELSE '{' Statements '}' ; While_Stat : WHILE '(' Expression ')' '{' Statements '}' ; %% void yyerror(char *s) { fprintf(stderr, "ERRO: %s \n", s); } int main() { yyparse(); return(0); } %-------------------------------------------------------------------------- \end{document}