Descripción Eyapp del Lenguaje SimpleC

En este capítulo usaremos Parse::Eyapp para desarrollar un compilador para el siguiente lenguaje, al que denominaremos Simple C :

program: definition+

definition: funcDef | basictype funcDef | declaration

basictype: INT | CHAR

funcDef: ID '('  params  ')' block

params: ( basictype ID arraySpec)<* ','>

block: '{' declaration* statement* '}'

declaration: basictype declList ';'

declList: (ID arraySpec) <+ ','>

arraySpec: ( '[' INUM ']')*

statement:
    expression ';'
  | ';'
  | BREAK ';'
  | CONTINUE ';'
  | RETURN ';'
  | RETURN expression ';'
  | block
  | ifPrefix statement %prec '+'
  | ifPrefix statement 'ELSE' statement
  | loopPrefix statement

ifPrefix: IF '(' expression ')'

loopPrefix: WHILE '(' expression ')'

expression: binary <+ ','>

Variable: ID ('[' binary ']') *

Primary:
    INUM
  | CHARCONSTANT
  | Variable
  | '(' expression ')'
  | function_call

function_call:  ID  '(' binary <* ','> ')'

Unary: '++' Variable | '--' Variable | Primary

binary:
    Unary
  | binary '+' binary
  | binary '-' binary
  | binary '*' binary
  | binary '/' binary
  | binary '%' binary
  | binary '<' binary
  | binary '>' binary
  | binary '>=' binary
  | binary '<=' binary
  | binary '==' binary
  | binary '!=' binary
  | binary '&' binary
  | binary '**' binary
  | binary '|' binary
  | Variable '=' binary
  | Variable '+=' binary
  | Variable '-=' binary
  | Variable '*=' binary
  | Variable '/=' binary
  | Variable '%=' binary
  | etc. etc.

Casiano Rodríguez León
2013-04-23