Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******** Grammaire : à faire **********/
- void Sp()
- {
- S();
- consume(SEMICOLON);
- }
- void S()
- {
- if (currentToken()->type == VAR)
- {
- consume(VAR);
- consume(ASSIGN);
- S();
- }
- else
- {
- E();
- }
- }
- void E()
- {
- T();
- Ep();
- }
- void Ep()
- {
- if (currentToken()->type == MINUS || currentToken()->type == PLUS)
- {
- consume(currentToken()->type);
- T();
- Ep();
- }
- }
- void T()
- {
- F();
- Tp();
- }
- void Tp()
- {
- if (currentToken()->type == MULT || currentToken()->type == DIV)
- {
- consume(currentToken()->type);
- F();
- Tp();
- }
- }
- void F()
- {
- if (currentToken()->type == VAR)
- {
- consume(VAR);
- }
- else if (currentToken()->type == NUMBER)
- {
- consume(NUMBER);
- }
- else if (currentToken()->type == LB)
- {
- consume(LB);
- S();
- consume(RB);
- }
- }
- /******** Exemple de programme principal (lecture du fichier passé en paramètres ******/
- int main(int argc, char *argv[])
- {
- fprintf(stderr, "Lexing from %s.\n", argv[1]);
- initLexer(argv[1]);
- // Appeler la racine de la grammaire...
- Sp();
- // Vérifier que tout le programme a été lu...
- if (currentToken() != NULL)
- {
- fprintf(stderr, "Unexpected input after assignation.\n");
- }
- // Afficher la table des symboles.
- print_symbols();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement