CS 152: Programming Language Paradigms
- Prof. Tom Austin
Syntax, Semantics, and Language Design Criteria Prof. Tom Austin - - PowerPoint PPT Presentation
CS 152: Programming Language Paradigms Syntax, Semantics, and Language Design Criteria Prof. Tom Austin San Jos State University Lab 1 solution (in class) Formally defining a language Two aspects of a language: Syntax structure of
source code tokens …
source code tokens if (x < 42) { y++; } else { y = 42; } "if" "(" "x" "<" "42" ")" "{" "y" "++" ";" "}" "else" "{" "y" "=" "42" ";" "}"
source code tokens if (x < 42) { y++; } else { y = 42; } "if" "(" "x" "<" "42" ")" "{" "y" "++" ";" "}" "else" "{" "y" "=" "42" ";" "}"
source code tokens
The parser reads tokens to form an abstract syntax tree.
"if" "(" "x" "<" "42" ")" "{" "y" "++" ";" "}" "else" "{" "y" "=" "42" ";" "}" 42 if < X 42 = y + y 1 = y
source code tokens
Machine code
Commands
Return value is true