Nepedia
Back to Discover
Independent Reader
💻

Syntax (programming languages)

technology Maturity 11-13 Next article →

Computers use special rules to read code. We call these rules syntax. Syntax tells a computer how to read words and symbols.

Python add5 syntax
Python add5 syntax

Without these rules, the computer would not understand.

There are three main levels of syntax. First is the lexical level. This is the level of words. A tool called a lexer looks at characters. It turns them into tokens. Tokens are like the building blocks of a language.

Next is the grammar level. This level looks at phrases. A tool called a parser checks the tokens. It makes sure they follow the rules. It often builds an abstract syntax tree. This is a simple map of the code.

Python add5 parse
Python add5 parse

The last level is context. This step checks if names and types are right.

Syntax is not the same as meaning. Syntax is about the form of the code. Meaning is called semantics. A sentence can follow all the rules but still make no sense. For example, a sentence might be grammatically correct but tell a lie. In coding, a program can have perfect syntax but still have errors in meaning.

181 words

Where will your curiosity go next?

Keep exploring at your chosen reading level.

🖼️ Images & Media (2)
File:Python add5 syntax.svg
Python add5 syntax.svg
File:Python add5 parse.svg
Python add5 parse.svg
More to explore

What is Nepedia?

A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.