Linear syntax

From Wikipedia, the free encyclopedia
Jump to: navigation, search

Linear syntax is a computer-programming term for an expression that can be parsed from left to right. Linear syntax implies the ability to write code without the use of line-feed or carriage-return characters. Although the use of such characters is recommended for code readability, they are optional, as compilers do not rely on them to parse and compile the code. HTML, C, and SQL code are examples of languages that employ linear syntax; they all rely on commas, semicolons, and parentheses to separate code blocks.

Example[edit]

C[edit]

Linear example in C:

void main() { printf("Hello world!"); }

Non-linear example in C:

void main() {
    printf("Hello world!");
}

HTML[edit]

Linear example in HTML:

<ul><li>Foo</li><li>Bar</li><li>Baz</li></ul>

Non-linear example in HTML:

<ul>
  <li>Foo</li>
  <li>Bar</li>
  <li>Baz</li>
</ul>

SQL[edit]

Linear example in SQL:

SELECT name FROM users WHERE lvl > 10 ORDER BY firstname

Non-linear example in SQL:

SELECT name
FROM users
WHERE lvl > 10
ORDER BY firstname