{"content":{"id":806,"title":"'Build Your Own Lisp' Solutions: 5.4","body":"\u003cp\u003e\u003cb\u003eQ:\u003c/b\u003e Describe textually a grammar for decimal numbers such as \u003ci\u003e0.01\u003c/i\u003e or \u003ci\u003e52.221\u003c/i\u003e.\u003c/p\u003e\r\n\u003cbr\u003e\r\n\u003cp\u003e\u003cb\u003eA:\u003c/b\u003e \r\n\u003cpre\u003e\u003ccode class=\"cpp\"\u003e// Using the same system he's given us to describe decimals:\r\n\" \\\r\n digit : \\\"0\\\" | \\\"1\\\" \\\"2\\\" | \\\"3\\\" \\\"4\\\" \\\r\n | \\\"5\\\" | \\\"6\\\" \\\"7\\\" | \\\"8\\\" \\\"9\\\"; \\\r\n number : \u0026lt;digit\u0026gt;+; \\\r\n decimal : \u0026lt;number\u0026gt;+\\.\u0026lt;number\u0026gt;+; \\\r\n\"\r\n/* The URL example is essentially the same, but with a all the letters \r\n * of the alphabet. The rest of the questions in the chapter are soft\r\n * enough to be left to the interested reader. */\r\n\u003c/code\u003e\u003c/pre\u003e\r\n\u003c/p\u003e","publication_date":"2019-07-26T00:00:00.000Z","created_at":"2019-06-28T18:09:04.000Z","updated_at":"2019-06-29T20:42:50.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.4

Q: Describe textually a grammar for decimal numbers such as 0.01 or 52.221.


A:

// Using the same system he's given us to describe decimals:
"                                             \
 digit   : \"0\" | \"1\" \"2\" | \"3\" \"4\"  \
         | \"5\" | \"6\" \"7\" | \"8\" \"9\"; \
 number  : <digit>+;                          \
 decimal : <number>+\.<number>+;              \
"
/* The URL example is essentially the same, but with a all the letters 
 * of the alphabet. The rest of the  questions in the chapter are soft
 * enough to be left to the interested reader. */