CS152 – Programming Language Paradigms
- Prof. Tom Austin, Fall 2015
Syntax & Semantics, and Language Design Criteria Lab 1 solution - - PowerPoint PPT Presentation
CS152 Programming Language Paradigms Prof. Tom Austin, Fall 2015 Syntax & Semantics, and Language Design Criteria Lab 1 solution (in class) Formally defining a language When we define a language, we need to keep two concepts in mind:
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's job is to combine the tokens together into 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