{"content":{"id":722,"title":"'Build Your Own Lisp' Solutions: 5.3","body":"\u003cp\u003e\u003cb\u003eQ:\u003c/b\u003e Why are there back slashes \u003ci\u003e\\\u003c/i\u003e at the end of the line in the grammar?\u003c/p\u003e\r\n\u003cbr\u003e\r\n\u003cp\u003e\u003cb\u003eA:\u003c/b\u003e C will ignore a combination of a newline followed by \u003ci\u003e\\\u003c/i\u003e, which lets you format long strings more nicely. An example:\r\n\u003cpre\u003e\u003ccode class=\"cpp\"\u003e#include \u0026ltstdio.h\u0026gt\r\n\r\nint main(void)\r\n{\r\n /* If you count the spaces here and in the resulting output, there are\r\n * 11. The \\ and the newline are dropped. */\r\n printf(\"this is line one \\\r\n and this is line two\\n\");\r\n\r\n return 0;\r\n}\r\n\u003c/code\u003e\u003c/pre\u003e\r\n\u003cpre\u003e\u003ccode class=\"lisp\"\u003ethis is line one and this is line two\r\n\u003c/code\u003e\u003c/pre\u003e\r\n\u003c/p\u003e\r\n\u003c!--\r\n\u003cstyle\u003e\r\ni { background: white; font-style: normal; margin-left: 3px; margin-right: 3px }\r\n\u003c/style\u003e\r\n--\u003e","publication_date":"2019-06-20T00:00:00.000Z","created_at":"2019-05-19T18:52:47.000Z","updated_at":"2019-06-22T02:53:03.000Z","user_id":1,"rating":null},"tags":"\u003ca class=\"changeable-title\" href=\"/q?tag=c\"\u003ec\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=lisp\"\u003elisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=build_your_own_lisp\"\u003ebuild_your_own_lisp\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=answers\"\u003eanswers\u003c/a\u003e \u003ca class=\"changeable-title\" href=\"/q?tag=programming\"\u003eprogramming\u003c/a\u003e"}

'Build Your Own Lisp' Solutions: 5.3

Q: Why are there back slashes \ at the end of the line in the grammar?


A: C will ignore a combination of a newline followed by \, which lets you format long strings more nicely. An example:

#include <stdio.h>

int main(void)
{
  /* If you count the spaces here and in the resulting output, there are
   * 11. The \ and the newline are dropped. */
  printf("this is line one \
          and this is line two\n");

  return 0;
}
this is line one           and this is line two