SlideServe
Menu
Préférences
© SlideServe · v2026

Assignment 3 Solution Background

elom avatar
11 diapositives · 258 Views · Aug 24, 2014

This document details the process of converting infix expressions to postfix notation, specifically focusing on expressions such as `2 + 3 * 4` and `2 + (3 * 4)`. It explores evaluating postfix expressions using a stack, compiling constant expressions for stack machines, and generating byte code for static functions considering numeric types and variable coercion. Additionally, it discusses grammar rules for mapping to control structures with practical examples, including alternatives and loops in parsing specifications.

Assignment 3 Solution Background - slide 1
01 / 11Assignment 3 Solution Background
1 / 17

Télécharger la présentation

Assignment 3 Solution Background
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Assignment 3 Solution Background

  2. Constant Expression : Infix to postfix 2 + 3 * 4 ( 2 + (3 * 4 ) ) 2 3 4 * + • Evaluating postfix expression using stack | 2 | | 2 | 3 | 4 | | 2 | 12 | |14|

  3. Evaluating postfix expression using stack | 2 | | 2 | 3 | 4 | | 2 | 12 | |14| • Compiling constant expression for a stack machine Push 2 Push 3 Push 4 Mul Add

  4. Generalizing to expressions with variables i + j * k Push i Push j Push k Mul Add • Conversion to abstract syntax tree + i * j k

  5. Generalizing to expressions with variables i + j * k Push i Push j Push k Mul Add • Byte code generation for static f(int i,j,k) iload_0 iload_1 iload_2 imul iadd

  6. Right associative “+” iload_0 iload_1 iload_2 iadd iadd Left associative “+” iload_0 iload_1 iadd iload_2 iadd Byte code for i + j + k for static f(int i,j,k)

  7. Introducing numeric types with real variables a + b Push a Push b Add • Byte code generation for static f(double a,b) dload_0 dload_2 dadd

  8. Mixing int and double variables (requiring coercion code) for static f(double a,int i, j) i + j * a iload_2 i2d iload_3 i2d dload_0 dmul dadd

  9. Translation algorithm essence trans (e1 * e2) = trans(e1) [type coercion code?] trans(e2) [type coercion code?] trans(*) • Map grammar rules to control structures • E.g., alternatives, while-loop, etc

  10. Scanner Spec (define the-lexical-spec '((whitespace (whitespace) skip) (identifier ((or "i" "j" "k")) symbol) (number (digit (arbno digit)) number)) )

  11. Parser Spec (define the-grammar '((expression (term (arbno "+" term)) add-exps) … (factor ("(" expression ")") paren-exp) ) )