5 ms·
Syntax and Semantics of Programming Languages (1995)
- ks2048 11mo agoIt 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-Programming-Languages/dp/0201656973 https://www.amazon.com/-/es/Formal-Syntax-Semantics-Programm...
- froh 11mo agoSlonneger, 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 11mo agoFar 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/ 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 ;-)
- iainctduncan 11mo agoThanks for the tip, I just did! I don't know what it is, but it seems form my slowly blooming collection like the standard of writing in PLT books from that era was just really, really high.
- rramadass 11mo agoYou might also want to checkout the book (surprisingly slim) Implementing Programming Languages: An Introduction to Compilers and Interpreters by Aarne Ranta - https://teach-plt.github.io/www/plt-book/ipl-book/ https://teach-plt.github.io/www/plt-book/ipl-book/
- iainctduncan 11mo agothanks!
- anonymousDan 11mo agoI'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 11mo agoSyntax, 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 11mo 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.
- Razengan 11mo agoI’ve been braining about a hypothetical language made from the ground up to be ideal for coding gameplay logic, and not worrying about hardware. I’m designing from the syntax first but have no idea/energy to actually implement the language/runtime or have it be usable with Godot etc. If I make the syntax and someone likes it, how to get someone to help me make it? :)
- levzettelin 11mo agoI'm probably not gonna do it, but just out of interest: What is the syntax?
- Razengan 11mo agoI'll start a brainstorming/drafting repo once I'm confident in deciding what I want. Stating my sources of inspiration will win some people and turn off some people: In terms of syntax, Godot's GDScript comes closest to my ideal. In terms of features, Swift. One thing I really want to try: instead of "functions" I want it to be "event handlers", so instead of func doSomething() you'd say on doSomething() A class instance could "contain" or "own" another class instance at runtime, similar to Godot's node-based hierarchy, and sending the `update()` event/signal to an instance could propagate it down the tree, making it easy to implement an entity+components architecture. and you could overload handlers based on which type raised the event or emitted the signal: on doSomething() by PlayerClass `caller` would be a keyword/object just like `self` is, in every handler scope so you could see `if caller is Player` or Monster for example. Most relevant in terms of gameplay, I want `Stat` to be a core type: a number that has a maximum and minimum, and conditional buffs/debuffs affecting the final value, and so on.
- levzettelin 11mo agoHmm, interesting! Sounds a bit like a DSL for ECS with tight integration of event handling.
- Razengan 11mo ago