We have a parser that handles arithmetic expressions. Numbers, operators, parentheses. It works. But we’re not trying to build a calculator - we’re building a compiler for a real programming language.

Time to add the rest. Functions, variables, conditionals. Everything we need to write actual programs.

Same strategy as before: one piece at a time. We’ll start simple and build up.

Adding Identifiers

The first thing we need is identifiers - names for variables and functions. When you write factorial(n), both factorial and n are identifiers.

Lexing Identifiers

An identifier is a sequence of letters, digits, and underscores. But it can’t start with a digit - x1 is valid, 1x is not. That’s a convention most programming languages follow, and we will too.

So …

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help