Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. /******** Grammaire : à faire **********/
  2.  
  3. void Sp()
  4. {
  5. S();
  6. consume(SEMICOLON);
  7. }
  8. void S()
  9. {
  10. if (currentToken()->type == VAR)
  11. {
  12. consume(VAR);
  13. consume(ASSIGN);
  14. S();
  15. }
  16. else
  17. {
  18. E();
  19. }
  20. }
  21. void E()
  22. {
  23. T();
  24. Ep();
  25. }
  26. void Ep()
  27. {
  28. if (currentToken()->type == MINUS || currentToken()->type == PLUS)
  29. {
  30. consume(currentToken()->type);
  31. T();
  32. Ep();
  33. }
  34. }
  35. void T()
  36. {
  37. F();
  38. Tp();
  39. }
  40. void Tp()
  41. {
  42. if (currentToken()->type == MULT || currentToken()->type == DIV)
  43. {
  44. consume(currentToken()->type);
  45. F();
  46. Tp();
  47. }
  48. }
  49. void F()
  50. {
  51. if (currentToken()->type == VAR)
  52. {
  53. consume(VAR);
  54. }
  55. else if (currentToken()->type == NUMBER)
  56. {
  57. consume(NUMBER);
  58. }
  59. else if (currentToken()->type == LB)
  60. {
  61. consume(LB);
  62. S();
  63. consume(RB);
  64. }
  65. }
  66.  
  67. /******** Exemple de programme principal (lecture du fichier passé en paramètres ******/
  68. int main(int argc, char *argv[])
  69. {
  70. fprintf(stderr, "Lexing from %s.\n", argv[1]);
  71. initLexer(argv[1]);
  72. // Appeler la racine de la grammaire...
  73. Sp();
  74. // Vérifier que tout le programme a été lu...
  75. if (currentToken() != NULL)
  76. {
  77. fprintf(stderr, "Unexpected input after assignation.\n");
  78. }
  79. // Afficher la table des symboles.
  80. print_symbols();
  81. return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement