freeCodeCamp/curriculum/challenges/chinese/08-coding-interview-prep/rosetta-code/s-expressions.chinese.md

2.9 KiB
Raw Blame History

title id challengeType videoUrl localeTitle
S-Expressions 59667989bf71cf555dd5d2ff 5 S-表达式

Description

S-Expressions是一种解析和存储数据的便捷方式。

任务:

为S-Expressions编写一个简单的读取器/解析器,处理引用的和不带引号的字符串,整数和浮点数。

该函数应从字符串中读取单个但嵌套的S-Expression并将其作为嵌套数组返回。

除非包含在带引号的字符串中,否则可以忽略换行符和其他空格。

”内部引用的字符串不会被解释,但会被视为字符串的一部分。

处理字符串中的转义引号是可选的;因此“ foo”bar “可能被视为字符串” foo“bar ”,或作为错误。

为此,读者无需识别“ \ ”以进行转义,但如果语言具有适当的数据类型,则还应识别数字。

请注意,除了“ ()” “(” \ “,如果支持转义)和空格,没有特殊字符。其他任何内容都是允许的,不带引号。

读者应该能够阅读以下输入

 数据“引用数据”123 4.5
    (数据(!@4.5)“(更多”“数据”))))

并将其转换为本机数据结构。 (有关本机数据结构的示例,请参阅Pike PythonRuby实现。)

Instructions

Tests

tests:
  - text: <code>parseSexpr</code>是一个函数。
    testString: 'assert(typeof parseSexpr === "function", "<code>parseSexpr</code> is a function.");'
  - text: '<code>parseSexpr(&quot;(data1 data2 data3)&quot;)</code>应返回[“data1”“data2”“data3”]“)'
    testString: 'assert.deepEqual(parseSexpr(simpleSExpr), simpleSolution, "<code>parseSexpr("(data1 data2 data3)")</code> should return ["data1", "data2", "data3"]");'
  - text: '<code>parseSexpr(&#39;(data1 data2 data3)&#39;)</code>应该返回一个包含3个元素的数组“'
    testString: 'assert.deepEqual(parseSexpr(basicSExpr), basicSolution, "<code>parseSexpr("(data1 data2 data3)")</code> should return an array with 3 elements");'

Challenge Seed

function parseSexpr(str) {
  // Good luck!
  return true;
}

After Test

console.info('after the test');

Solution

// solution required