Skip to content

ULL-ESIT-PL-1920/r15-t3-langdesign-alu0101121529

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Diseño de Lenguajes (Reto)

Modifica la gramática corrigiendo los errores que veas, de manera que genere frases como estas:

  1. a[4][b+c][5] = c[2][3]
  2. a.b.c = a[x]
  3. a.b[x*y].d = c.d[3][1].e(temp)
  • Procura que exprese bien la precedencia de operadores (vigila la asignación)

  • La variable <value> no se describe (y debería describirse)

Grammar

<program> ::= <block>

<block> ::= '{' <statement>* '}'  // Modified Casiano

<statement> ::=
               <declaration> |
              "if" <parenthesis> <block> ("else" "if" <block>)* ('else' <block>)? |
              "while" <parenthesis> <block> |
              'function' <word> '(' <word> (',' <word>)* ')' <block> |
              <expr> ";"
              
<declaration> ::= 'var' WORD ('=' <expr>)?

<leftValue> ::= WORD (. WORD | '[' <expr> ']')*

<expr> ::= (<leftValue> '=')* <rightValue>

<rightValue> ::= <term> (('==', '!=', '>', '>=', '<', '<=', '=') <term>)*

<term> ::= <sum> (('+', '-') <sum>)*

<sum> ::= <value> (('*', '/') <value>)*

<value> ::= (VALUE | WORD | <array> | <parenthesis>) (. WORD | '[' <expr> ']' | <apply>)*

<apply> ::= '(' <expr> (',' <expr>)* ')'<apply> | '.'<word><apply> | empty

<array> ::= '[' ']' | '[' <expr> (',' <expr> )*] // Added by Casiano

<parenthesis> ::= '(' <expr> ')'

Tokens

WORD = [a-zA-Z_]\w*
VALUE = STRING | NUMBER
STRING = "( [^"\\]   #any character except " and escape
           | \\.     #any character before an escape
           )*"
NUMBER = ([-+]?\d+     #entero
          (\.\d+)?    #flotante
          ([eE][-+]?\d+)?  #con exponente
          )

About

r15-t3-langdesign-alu0101121529 created by GitHub Classroom

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published