Syntax and Semantics

  1. Program semantics
    • The meaning of:
    • - Expressions
    • - Statements
    • - Program units
  2. Program Syntax
    Forms and structures of constructs
  3. How is a programming language defined?
    • Language syntax
    • Language semantics
  4. Lexeme
    • Lowest syntactic unit of a language
    • Described and checked by lexical analyzer
    • E.g +, *, =, etc...
    • Lexemes are converted to tokens when the code is tokenized
  5. Tokens
    • Categorize lexemes from a program
    • E.g new, int, <identifiers>, etc...
  6. Meta language
    Language used to describe another language
  7. Standard form for describing programming language syntax
    Backus-Naur form
  8. Describe an assignment statement in BNF
    <Assignment_Statement> → <var> = <expression>
  9. Examples of terminals in BNF
    • Tokens
    • Lexemes
  10. Nonterminal symbols (BNF)
    • Symbols that can be replaced
    • In the expression,
    • <assignment>→<var>=<expr>
    • The LHS <assignment> is nonterminal
  11. Put the following processes in order:
    Lexical analyzer
    Syntax analyzer
    Tokenizer
    Parse tree
    Code Generator
    Assembler
    Linker
    • Tokenizer
    • Syntax analyzer
    • Parse tree
  12. What is a keyword
    • Keywords have a special (contextual) meaning
    • They can be used as idenfitiers
  13. What is a reserved word
    • Reserved words are reserved
    • They cannot be used as identifiers
  14. BNF for IF statement
    <if_statement>→if<expr> then <stmt>
  15. BNF for IF-ELSE statement
    <if_statement> → if <expr> then <statement> else <statement>
  16. BNF for a list
    • <identifier_list>→<identifier>|<identifier_list>→<identifier>,<identifier_list>
    • The | is an OR (choose the appropriate definition)
    • Recursive
  17. When is a grammar ambiguous
    If two parse trees can be generated from it
  18. Types of program semantics
    • Operational - Compare difference between machine states
    • Axiomatic - Define axioms for each statement type
  19. Conditions in axiomic semantics
    • Precondition
    • Postcondition
    • Weakest precondition
  20. Precondition
    • Before a statement
    • Describes relationships and constraints of variables
  21. Postcondition
    • Occurs after a statement
    • True after the statement is executed
  22. Weakest precondition
    The least restrictive precondition that garuntees the post condition
Author
Ant
ID
354789
Card Set
Syntax and Semantics
Description
Syntax
Updated