lexer.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef AVDL_LEXER_H
  2. #define AVDL_LEXER_H
  3. /*
  4. * Lexer
  5. * responsible for reading source code
  6. * and tokenizing it
  7. *
  8. * it also supports push new (included) files
  9. */
  10. /*
  11. * all available tokens the lexer understands
  12. */
  13. enum lexer_tokens {
  14. LEXER_TOKEN_UNKNOWN,
  15. LEXER_TOKEN_DONE,
  16. LEXER_TOKEN_COMMANDSTART,
  17. LEXER_TOKEN_COMMANDEND,
  18. LEXER_TOKEN_ARRAYSTART,
  19. LEXER_TOKEN_ARRAYEND,
  20. LEXER_TOKEN_PERIOD,
  21. LEXER_TOKEN_STRING,
  22. LEXER_TOKEN_IDENTIFIER,
  23. LEXER_TOKEN_INT,
  24. LEXER_TOKEN_FLOAT,
  25. };
  26. /*
  27. * `prepare` initialises the lexer towards the given filename.
  28. * at some point `clean` should be called when the process is done.
  29. */
  30. void lexer_prepare(const char *filename);
  31. void lexer_clean();
  32. /*
  33. * After initialisation, `getNextToken` will return the next
  34. * token.
  35. * In case it's not needed, `rewind` will go back one step, so
  36. * `getNextToken` will return the same token when called again.
  37. * `getLexToken` is to get the string that the token represents.
  38. *
  39. * peek is used to take a look at the next token, without
  40. * updating parsing position.
  41. */
  42. int lexer_getNextToken();
  43. int lexer_peek();
  44. const char *lexer_getLexToken();
  45. const char *lexer_getCurrentFilename();
  46. int lexer_getCurrentLinenumber();
  47. void lexer_printCurrentLine();
  48. void lexer_addIncludedFile(const char *includeFilename);
  49. #endif // lexer