Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. /******************************************************************************************************************\
  2. * Uma empresa pretende implementar um repositório de informação sobre artigos científicos. Para tal, desenvolveu *
  3. * um processo automático que permite receber das editoras, a informação em ficheiros de texto cujas linhas têm a *
  4. * seguinte estrutura em formato EBNF (em que os campos opcionais são apresentados entre [] e os que se repetem *
  5. * 0 ou mais vezes entre { }): *
  6. * <título> [<ISBN>] <ano_publicação> [<género>] <autor>{,<autor>} {<quantidade>} *
  7. \*******************************************************************************************************************/
  8.  
  9. grammar Lprog;
  10.  
  11. // Monoline comment about a parser rule
  12. inicio : input ;
  13.  
  14. /*
  15. A multi-line Java-like comment
  16. */
  17. input: b NEWLINE
  18. | input b NEWLINE
  19. ;
  20.  
  21. b: titulo isbn ano_pub gen autor autores qtds
  22. ;
  23.  
  24. titulo: STRING ' '
  25. ;
  26.  
  27. isbn:
  28. | ISBN ' '
  29. ;
  30.  
  31. ano_pub: BTWIN_1800_2018 ' '
  32. ;
  33.  
  34. gen:
  35. | GENERO ' '
  36. ;
  37.  
  38.  
  39. autores:
  40. |',' autores autor
  41. ;
  42.  
  43. autor: STRING ' '
  44. ;
  45.  
  46. qtds:
  47. | qtd qtds
  48.  
  49. ;
  50.  
  51. qtd: INT
  52. ;
  53.  
  54. // some lexer rules
  55.  
  56. STRING :'"'([a-zA-Z]|' '|[0-9])+'"'; // String de caracteres alfanuméricos limitada por aspas + espaços
  57. ISBN :([0-9]'-'[0-9][0-9][0-9][0-9]'-'[0-9][0-9][0-9][0-9]'-'([0-9]|'X')|[0-9][0-9][0-9]'-'[0-9]'-'[0-9][0-9][0-9][0-9]'-'[0-9][0-9][0-9][0-9]'-'([0-9]|'X')) ; // N-NNNN-NNNN-R ou NNN-N-NNNN-NNNN-R em que N representa um algarismo e, R um algarismo ou a letra X;
  58. BTWIN_1800_2018 :'1'[8-9][0-9][0-9]|'200'[0-9]|'201'[0-8]; // todos os inteiros em [1800,2018]
  59. GENERO :'SURVEY'|'ENSAIO'|'INOVAÇÃO';
  60. INT :[0-9]+;
  61. NEWLINE :'\r'? '\n' ; // ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement