frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Syntax and Semantics of Programming Languages (1995)

https://homepage.cs.uiowa.edu/~slonnegr/plf/Book/
14•nill0•2h ago

Comments

ks2048•10h ago
It looks like this is the following book, if you want to read a two paragraph description (also a google search you lead you to a full-book PDF):

https://www.amazon.com/-/es/Formal-Syntax-Semantics-Programm...

froh•10h ago
Slonneger, Kenneth, and Kurtz, Barry L.. Formal syntax and semantics of programming languages : a laboratory based approach. United Kingdom, Addison-Wesley Publishing Company, 1995.

as the Amazon app wants to switch country and closes if I don't. (party pooper).

from the Preface:

Laboratory Activities

Chapter 2: Scanning and parsing Wren

Chapter 3: Context checking Wren using an attribute grammar

Chapter 4: Context checking Hollerith literals using a two-level grammar

Chapter 5: Evaluating the lambda calculus using its reduction rules

Chapter 6: Self-definition of Scheme (Lisp) Self-definition of Prolog

Chapter 7: Translating (compiling) Wren programs following an attribute grammar

Chapter 8: Interpreting the lambda calculus using the SECD machine Interpreting Wren according to a definition using structural operational semantics

Chapter 9: Interpreting Wren following a denotational specification

Chapter 10: Evaluating a lambda calculus that includes recursive defini- tions

Chapter 12: Interpreting Wren according to an algebraic specification of the language

Chapter 13: Translating Pelican programs into action notation following a specification in action semantics.

rramadass•4h ago
Far more details can be found at author's old-school webpage (see Preface and Table of Contents without pdf) - https://homepage.cs.uiowa.edu/~slonnegr/

I had recommended this book earlier on HN and elsewhere. It uses Prolog as the meta language for language design. With Prolog finding new domains of usage with LLMs this makes it a good approach to learn both Prolog and language design.

Since it is out of print, snap up any and all used copies available ;-)

anonymousDan•3h ago
I've always really struggled to understand the purpose of defining the 'semantics' of a programming language and how it differs from syntax. Explanations that involve 'giving a precise mathematical meaning' just seem almost circular to me. As I understand it now it's about saying what the value of a particular language construct should be (e.g. when evaluated), as opposed to whether the construct is allowed/part of the language (syntax). Is that intuition wrong?
FloorEgg•3h ago
Syntax, semantics, and pragmatics all define meaning at different scopes/scales.

Syntax is the smallest scale (words, punctuation, grammar), semantics is sentence or small function level, and pragmatics is paragraph-essay and program level.

For example when training early smaller scale LLMs they noticed that syntax was the first property for the LLM to reproduce reliably. They got proper grammar and punctuation but the sentences made no sense. When they scaled up they got semantics but not pragmatics. The sentences made sense but paragraphs didn't. Eventually the systems could output whole essays that made sense.

Even though you're asking about programming specifically, these concepts are universal to language, and are maybe a bit more intuitively applied to English (or your native language).

I suspect that a computer scientist could give a different mathematical explanation about how these concepts compile into binary or machine code in different ways, and I can't explain that. Generally I think of syntax as being very language specific but semantics and pragmatics can be translated across languages with similar capabilities.

jez•2h ago
> as opposed to whether the construct is allowed/part of the language

Arguably this is also semantics. Type checking and reporting type errors decides whether a construct is allowed or not, yet belongs squarely in the semantic analysis phase of a language (as opposed to the syntactic analysis phase).

> how it differs from syntax

Consider a language like C, which allows code like this:

    if (condition) {
        doWhenTrue();
    }
And consider a language like Python, which allows code like this:

    if condition:
        doWhenTrue()
The syntax and the semantics are both different here.

The syntax is different: C requires parens around the condition, allows curly braces around the body, and requires `;` at the end of statements. Python allows but does not require parens around the condition, requires a `:`, requires indenting the body, and does not allow a `;` at the end of statements.

Also, the semantics are different: in C, `doWhenTrue()` only executes if `condition` either is a non-zero integer, or can be implicitly coerced to a non-zero integer.

In Python, `doWhenTrue` executes if `condition` is "truthy," which is defined as whether calling `condition.__bool__()` returns `True`. Values like `True`, non-zero numbers, non-empty containers, etc. are all truthy, which is far more values than in C.

But you could imagine a dialect of Python that used the exact same syntax from C, but the semantics from Python. e.g., a language where

    if (condition) {
        doWhenTrue();
    }
has the exact same meaning as the Python snippet above: that `doWhenTrue()` executes when `condition` is truthy, according to some internal `__bool__()` method.
rramadass•2h ago
> As I understand it now it's about saying what the value of a particular language construct should be (e.g. when evaluated), as opposed to whether the construct is allowed/part of the language (syntax). Is that intuition wrong?

Your intuition is right. It falls under what is called "Operational Semantics" (https://en.wikipedia.org/wiki/Operational_semantics) There are other aspects of looking at it i.e. "Denotational Semantics", "Axiomatic Semantics", "Algebraic Semantics" etc. which are more mathematical. The submitted book talks about all of them.

For more background, you might want to look at Alan Parkes book Introduction to Languages, Machines, and Logic.

The basic idea is that Symbolic Logic allows you to express Strings (sentences containing words) constructed from an Alphabet (set of symbols for that language) as "Programs" (which are valid i.e. meaningful strings in that language) which can then be interpreted by a Abstract Machine we call a Computer.

bananaflag•2h ago
I think the problem is that you don't get "syntax". What you think "syntax" is is actually semantics.

"Syntax" just means what strings are valid programs. For example, x=3 should be valid in C, while =+x shouldn't. Note that this doesn't say anything about what x=3 actually means in practice. The fact that there is a variable called x, and that it has a value at some point in time, and that after the execution of x=3 that value becomes 3 are all semantics.

lifthrasiir•2h ago
There does exist a subtle middle ground between proper syntax and proper semantics, namely well-formedness. Well-formedness is technically a part of syntax rules (i.e. syntactic correctness) but not a part of formal grammars and other similar stuffs, making it harder to classify. For example, XML's opening tag and closing tag should be matched like <foo></foo>, but this syntactic rule is not described in the formal context-free grammar. It is possible to make a formal context-sensitive grammar that only accepts a well-formed syntax, but that would make the specification unnecessarily complex, hence the introduction of informal rules. Some still may argue that it is actually kind of semantics, however.
antonvs•1h ago
Your intuition is on the right track. The distinction may become clearer if you consider a classic language implementation design:

1. There's a lexer which breaks source text up into a stream of tokens.

2. A parser which converts a stream of tokens into an abstract syntax tree (AST).

3. An interpreter or compiler that traverses the AST in order to either execute it (interpreter) or transform it into some other form (compiler).

Points 1 & 2 are syntax - the mapping between the textual form of a program and its meaning.

Point 3 is semantics - how a program actually behaves, or as you say, what its terms evaluate to.

Looking at it like this can give a sharp line between syntax and semantics. But when you get deeper into it, it turns out that with some languages at least, you can get from source syntax to something that actually executes - has behavior, i.e. semantics - with nothing but a series of syntactic transformations. From that perspective, you can say that semantics can be defined as a sequence of syntactic transformations.

This doesn't erase the distinction between syntax and semantics, though. The syntax of the source language is the first stage in a chain of transformations, with each stage involving a different (albeit closely related) language with its own syntactic structure.

> Explanations that involve 'giving a precise mathematical meaning' just seem almost circular to me.

Formal semantics covers this, but the syntax/semantics distinction isn't necessary just formal - it's a useful distinction even in an informal sense.

As for circularity, it's absolutely the case that formal semantics is nothing more than defining one language in terms of another. But the idea is that the target language is supposed to be one with well-defined semantics of its own, which is why "mathematical" comes up so often in this context. Mathematical abstractions such as set theory, lattice theory, lambda calculus and so on can provide a rigorous foundation that's more tractable when it comes to proofs.

That kind of circularity pervades our knowledge in general. Words in the dictionary are given meaning in terms of other words. You can't explain something without explaining it in terms of something else.

adamddev1•59m ago
Great explanation. Also, if I understand things correctly, type-checking is where things get really interesting. Runtime errors occur in #3. Type checkers identify these errors (to varying degrees) and they show the errors in the compile phase. If we think of parsing and type-checking as a unit together, then type-checking sort of pushes the line of syntax further into semantic territory. The stronger the type-checker, the more you can make semantic errors look like syntax errors.

This is similar to what Chomsky did in "Aspects of the Theory of Syntax" when he tried to show how we can build more thorough systems to evaluate semantics of (human) language, like what kinds of nouns can go with what kinds of verbs. He pushes the line of syntax further into the semantic territory and tries to create more comprehensive sets of rules that better guarantee the generation of syntactically and semantically correct sentences. I think this is perfectly analogous to the type-checking enterprise.

tmoertel•55m ago
In short: Syntax defines the textual forms that the language allows. Semantics define how each form is interpreted.

Consider a simple calculator language that lets you add positive integers.

The syntax might give grammar rules like:

    expr ::= digits (EOF | ' + ' expr)
    digits ::= ('0' | '1' | ... | '9')+
This grammar admits expressions like 33 and 2 + 88 + 344. That's syntax.

But how the language interprets those expressions is semantics. Continuing our calculator example:

1. Every expr evaluates to an integer value.

2. An expr of the form `<digits> EOF` evaluates to the integer given by interpreting the digits in <digits> as an integer in base 10.

3. If <expr> evaluates to the value x, then an expr of the form `<digits> + <expr>` evaluates to the value y + x, where y is the integer given by interpreting the digits in <digits> as an integer in base 10.

Of course, specifying semantics in human language is tedious and hard to make precise. For this reason, most programming languages give their semantics in a more formalized language. See, for a classic example, the R5RS specs for Scheme:

https://conservatory.scheme.org/schemers/Documents/Standards...

Razengan•21m ago
I’ve been braining about a hypothetical ideal language made for coding gameplay logic, and not worrying about hardware.

I’m designing from the syntax first but have no idea how to actually implement the language/rubtime or have it be usable with Godot etc.

If I design the syntax can someone help me make it? ^^

Tabloid: The Clickbait Headline Programming Language

https://tabloid.vercel.app/
73•sadeshmukh•2h ago•12 comments

Ironclad – formally verified, real-time capable, Unix-like OS kernel

https://ironclad-os.org/
176•vitalnodo•6h ago•37 comments

Boring Company fined nearly $500K after it dumped drilling fluids into manholes

https://www.yahoo.com/news/articles/elon-musk-boring-company-fined-150000426.html
95•eloisius•1h ago•22 comments

Marko – A declarative, HTML‑based language

https://markojs.com/
243•ulrischa•10h ago•117 comments

Largest cargo sailboat completes first Atlantic crossing

https://www.marineinsight.com/shipping-news/worlds-largest-cargo-sailboat-completes-historic-firs...
169•defrost•9h ago•108 comments

Study identifies weaknesses in how AI systems are evaluated

https://www.oii.ox.ac.uk/news-events/study-identifies-weaknesses-in-how-ai-systems-are-evaluated/
328•pseudolus•15h ago•166 comments

Reverse engineering Codex CLI to get GPT-5-Codex-Mini to draw me a pelican

https://simonwillison.net/2025/Nov/9/gpt-5-codex-mini/
5•simonw•1h ago•0 comments

Open-source communications by bouncing signals off the Moon

https://open.space/
92•fortran77•6d ago•21 comments

Control structures in programming languages: from goto to algebraic effects

http://xavierleroy.org/control-structures/
117•SchwKatze•5d ago•9 comments

Syntax and Semantics of Programming Languages (1995)

https://homepage.cs.uiowa.edu/~slonnegr/plf/Book/
14•nill0•2h ago•13 comments

WriterdeckOS

https://writerdeckos.com
150•surprisetalk•10h ago•83 comments

Debugging BeagleBoard USB boot with a sniffer: fixing omap_loader on modern PCs

https://www.downtowndougbrown.com/2025/11/debugging-beagleboard-usb-boot-with-a-sniffer-fixing-om...
55•todsacerdoti•6h ago•0 comments

Avería: The Average Font (2011)

http://iotic.com/averia/
144•JoshTriplett•9h ago•29 comments

How to build your own VPN, or: the history of WARP

https://blog.cloudflare.com/how-to-build-your-own-vpn-or-the-history-of-warp/
19•yla92•5d ago•1 comments

Show HN: Geofenced chat communities anyone can create

https://vicinity.social/
8•clarencehoward•2h ago•3 comments

Judge denies request to exempt Flock footage from Public Records Act

https://www.goskagit.com/news/local_news/court-denies-request-that-it-find-flock-safety-camera-da...
84•p_ing•4h ago•25 comments

How Airbus Took Off

https://worksinprogress.co/issue/how-airbus-took-off/
11•JumpCrisscross•4h ago•2 comments

Cloudflare scrubs Aisuru botnet from top domains list

https://krebsonsecurity.com/2025/11/cloudflare-scrubs-aisuru-botnet-from-top-domains-list/
124•jtbayly•13h ago•27 comments

IP blocking the UK is not enough to comply with the Online Safety Act

https://prestonbyrne.com/2025/11/06/the-ofcom-files-part-2-ip-blocking-the-uk-is-not-enough-to-co...
225•pinkahd•6h ago•271 comments

My first fifteen compilers (2019)

https://blog.sigplan.org/2019/07/09/my-first-fifteen-compilers/
51•azhenley•1w ago•3 comments

He Chunhui's Tiny386 Turns an ESP32-S3 into a Fully-Functional 386-Powered PC

https://www.hackster.io/news/he-chunhui-s-tiny386-turns-the-humble-esp32-s3-into-a-fully-function...
60•HardwareLust•4h ago•7 comments

Valdi – A cross-platform UI framework that delivers native performance

https://github.com/Snapchat/Valdi
473•yehiaabdelm•1d ago•198 comments

Why is Zig so cool?

https://nilostolte.github.io/tech/articles/ZigCool.html
500•vitalnodo•1d ago•441 comments

Show HN: Hephaestus – Autonomous Multi-Agent Orchestration Framework

https://github.com/Ido-Levi/Hephaestus
7•idolevi•5d ago•0 comments

An Algebraic Language for the Manipulation of Symbolic Expressions (1958) [pdf]

https://softwarepreservation.computerhistory.org/LISP/MIT/AIM-001.pdf
86•swatson741•14h ago•10 comments

Opencloud – An alternative to Nextcloud written in Go

https://github.com/opencloud-eu/opencloud
66•todsacerdoti•12h ago•10 comments

Ticker: Don't die of heart disease

https://myticker.com/
448•colelyman•14h ago•373 comments

GPT-5-Codex-Mini – A more compact and cost-efficient version of GPT-5-Codex

https://github.com/openai/codex/releases/tag/rust-v0.56.0
43•wahnfrieden•5h ago•28 comments

Humanity's Endgame

https://www.noemamag.com/humanitys-endgame/
22•marojejian•5h ago•15 comments

How did I get here?

https://how-did-i-get-here.net/
362•zachlatta•1d ago•61 comments