README-D.txt 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. Some usage notes for the D Parser:
  2. - it is a port of the Java parser, so interface is very similar.
  3. - the lexer class needs to implement the interface 'Lexer' (similar to
  4. java). It typically (depending on options) looks like this:
  5. public interface Lexer
  6. {
  7. /**
  8. * Method to retrieve the beginning position of the last scanned token.
  9. * @return the position at which the last scanned token starts. */
  10. @property YYPosition startPos ();
  11. /**
  12. * Method to retrieve the ending position of the last scanned token.
  13. * @return the first position beyond the last scanned token. */
  14. @property YYPosition endPos ();
  15. /**
  16. * Method to retrieve the semantic value of the last scanned token.
  17. * @return the semantic value of the last scanned token. */
  18. @property YYSemanticType semanticVal ();
  19. /**
  20. * Entry point for the scanner. Returns the token identifier corresponding
  21. * to the next token and prepares to return the semantic value
  22. * and beginning/ending positions of the token.
  23. * @return the token identifier corresponding to the next token. */
  24. TokenKind yylex ();
  25. /**
  26. * Entry point for error reporting. Emits an error
  27. * referring to the given location in a user-defined way.
  28. *
  29. * @param loc The location of the element to which the
  30. * error message is related
  31. * @param s The string for the error message. */
  32. void yyerror (YYLocation loc, string s);
  33. }
  34. - semantic types are handled by D unions (same as for C/C++ parsers)
  35. - the following (non-standard) %defines are supported:
  36. %define package "<package_name>"
  37. %define api.parser.class "my_class_name>"
  38. %define position_type "my_position_type"
  39. %define location_type "my_location_type"
  40. - the following declarations basically work like in C/C++:
  41. %locations
  42. %error-verbose
  43. %parse-param
  44. %initial-action
  45. %code
  46. %union
  47. - %destructor is not yet supported