Syntax Analysis

The code below shows the body of the grammar (file Infix.eyp). Eyapp syntax very much resembles the syntax of old cherished yacc [7]. An Eyapp program has three parts: head, body and tail. Each part is separated from the former by the symbol %%. The head section contains declarations, code support and directives. The grammar rules describing the language - and the semantic actions that indicate how evaluate the attributes associated with the symbols - reside in the body section. The tail section includes Perl code that gives support to the semantic actions. Commonly the lexical analyzer and error diagnostic subroutines go there. In the case of eyapp the lexical analyzer is usually automatically generated from the token definitions or defined through a %lexer directive inside the head section. Also, for most cases, there is no need to overwrite the provided default error diagnostic method.

%right  '='        # Head section
%left   '-' '+'
%left   '*' '/'
%left   NEG
%tree 

%%
line:             # Body section
  sts <%name EXPS + ';'>
;
sts:
    %name PRINT
    PRINT leftvalue
  | exp 
;
exp:
    %name NUM    NUM
  | %name VAR    VAR
  | %name ASSIGN leftvalue '=' exp
  | %name PLUS   exp '+' exp
  | %name MINUS  exp '-' exp
  | %name TIMES  exp '*' exp
  | %name DIV    exp '/' exp
  | %name NEG
                '-' exp              %prec NEG
  |             '(' exp ')'
;
leftvalue : %name VAR VAR
;
%% 



Subsections
Procesadores de Lenguajes 2010-01-31