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 [9]. 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.

%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
;
%% 
...               # tail section



Subsections

Procesadores de Lenguaje 2007-03-01