Lecture 14 – Recap Eran Yahav Thanks to Ohad Shacham (TAU) for some of the slides in this lecture 1 www.cs.technion.ac.il/~yahave/tocs2011/compilers-lec14.pptx.

Slides:



Advertisements
Similar presentations
Compiler construction in4020 – lecture 4 Koen Langendoen Delft University of Technology The Netherlands.
Advertisements

Compilation (Semester A, 2013/14) Lecture 6a: Syntax (Bottom–up parsing) Noam Rinetzky 1 Slides credit: Roman Manevich, Mooly Sagiv, Eran Yahav.
1 Mooly Sagiv and Greta Yorsh School of Computer Science Tel-Aviv University Modern Compiler Design.
Lecture 08a – Backpatching & Recap Eran Yahav 1 Reference: Dragon 6.2,6.3,6.4,6.6.
Winter Compiler Construction T7 – semantic analysis part II type-checking Mooly Sagiv and Roman Manevich School of Computer Science Tel-Aviv.
Mooly Sagiv and Roman Manevich School of Computer Science
Lecture 01 - Introduction Eran Yahav 1. 2 Who? Eran Yahav Taub 734 Tel: Monday 13:30-14:30
6/12/2015Prof. Hilfinger CS164 Lecture 111 Bottom-Up Parsing Lecture (From slides by G. Necula & R. Bodik)
Recap Mooly Sagiv. Outline Subjects Studied Questions & Answers.
1 Semantic Processing. 2 Contents Introduction Introduction A Simple Compiler A Simple Compiler Scanning – Theory and Practice Scanning – Theory and Practice.
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
Compiler Summary Mooly Sagiv html://
1 LR parsing techniques SLR (not in the book) –Simple LR parsing –Easy to implement, not strong enough –Uses LR(0) items Canonical LR –Larger parser but.
Compiler Construction Recap Ran Shaham and Ohad Shacham School of Computer Science Tel-Aviv University.
Table-driven parsing Parsing performed by a finite state machine. Parsing algorithm is language-independent. FSM driven by table (s) generated automatically.
BİL744 Derleyici Gerçekleştirimi (Compiler Design)1.
Compiler Construction Recap Rina Zviel-Girshin and Ohad Shacham School of Computer Science Tel-Aviv University.
Cs164 Prof. Bodik, Fall Symbol Tables and Static Checks Lecture 14.
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
COP4020 Programming Languages
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
1 Chapter 5 LL (1) Grammars and Parsers. 2 Naming of parsing techniques The way to parse token sequence L: Leftmost R: Righmost Top-down  LL Bottom-up.
Java Programming Introduction & Concepts. Introduction to Java Developed at Sun Microsystems by James Gosling in 1991 Object Oriented Free Compiled and.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style COMPILER DESIGN Review Joey Paquet,
Joey Paquet, Lecture 12 Review. Joey Paquet, Course Review Compiler architecture –Lexical analysis, syntactic analysis, semantic.
CS412/413 Introduction to Compilers and Translators Spring ’99 Lecture 8: Semantic Analysis and Symbol Tables.
Review 1.Lexical Analysis 2.Syntax Analysis 3.Semantic Analysis 4.Code Generation 5.Code Optimization.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
CS536 Semantic Analysis Introduction with Emphasis on Name Analysis 1.
Introduction to Compiling
Compiler Design Introduction 1. 2 Course Outline Introduction to Compiling Lexical Analysis Syntax Analysis –Context Free Grammars –Top-Down Parsing –Bottom-Up.
Compiler Introduction 1 Kavita Patel. Outlines 2  1.1 What Do Compilers Do?  1.2 The Structure of a Compiler  1.3 Compilation Process  1.4 Phases.
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
Top-Down Parsing CS 671 January 29, CS 671 – Spring Where Are We? Source code: if (b==0) a = “Hi”; Token Stream: if (b == 0) a = “Hi”; Abstract.
Semantic Analysis II. Messages Please check lecturer notices in the Moodle Appeals  Legitimate: “I don’t have the bug you mentioned…”  Illegitimate:
1 A Simple Syntax-Directed Translator CS308 Compiler Theory.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
LECTURE 3 Compiler Phases. COMPILER PHASES Compilation of a program proceeds through a fixed series of phases.  Each phase uses an (intermediate) form.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
Compiler Construction Recap. 2 Announcements PA4: extension until end of exam period – Not a single day more, for any reason! PA5: bonus exercise – Will.
Compilers: Bottom-up/6 1 Compiler Structures Objective – –describe bottom-up (LR) parsing using shift- reduce and parse tables – –explain how LR.
CS416 Compiler Design1. 2 Course Information Instructor : Dr. Ilyas Cicekli –Office: EA504, –Phone: , – Course Web.
CMSC 330: Organization of Programming Languages Pushdown Automata Parsing.
CS510 Compiler Lecture 1. Sources Lecture Notes Book 1 : “Compiler construction principles and practice”, Kenneth C. Louden. Book 2 : “Compilers Principles,
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 12–Compilers.
2016/7/9Page 1 Lecture 11: Semester Review COMP3100 Dept. Computer Science and Technology United International College.
LECTURE 10 Semantic Analysis. REVIEW So far, we’ve covered the following: Compilation methods: compilation vs. interpretation. The overall compilation.
Lecture 9 Symbol Table and Attributed Grammars
Intro to compilers Based on end of Ch. 1 and start of Ch. 2 of textbook, plus a few additional references.
Compiler Design (40-414) Main Text Book:
Chapter 1 Introduction.
Winter Compiler Construction T11 – Recap
Constructing Precedence Table
Table-driven parsing Parsing performed by a finite state machine.
Chapter 1 Introduction.
Compiler Lecture 1 CS510.
CS 536 / Fall 2017 Introduction to programming languages and compilers
CS416 Compiler Design lec00-outline September 19, 2018
Introduction CI612 Compiler Design CI612 Compiler Design.
CPSC 388 – Compiler Design and Construction
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
CSE401 Introduction to Compiler Construction
Subject: Language Processor
Exam Topics Hal Perkins Autumn 2009
CS416 Compiler Design lec00-outline February 23, 2019
Fall Compiler Principles Lecture 4: Parsing part 3
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
COMPILER CONSTRUCTION
Exam Topics Hal Perkins Winter 2008
Compiler design Review COMP 442/6421 – Compiler Design
Presentation transcript:

Lecture 14 – Recap Eran Yahav Thanks to Ohad Shacham (TAU) for some of the slides in this lecture 1

2 Generic compiler structure Executable code exe Source text txt Semantic Representation Backend (synthesis) Compiler Frontend (analysis)

3 Lexical Analysis  Input  program text (file)  Output  sequence of tokens  Read input file  Identify language keywords  Count line numbers  Remove whitespaces  Report illegal symbols

Lexical Analysis 4 CLASS,CLASS_ID(Hello),LB,BOOLEAN,ID(state),SEMI … Issues in lexical analysis Language changes New keywords New operators New meta-language features, e.g., annotations class Hello { boolean state; static void main(string[] args) { Hello h = new Hello(); boolean s = h.rise(); Library.printb(s); h.setState(false); } boolean rise() { boolean oldState = state; state = true; return oldState; } void setState(boolean newState) { state = newState; } }

5 Parsing  Input  A context free grammar  A stream of tokens  Output  An abstract syntax tree or error

6 Parsing and AST CLASS,CLASS_ID(Hello),LB,BOOLEAN,ID(state),SEMI … prog class_list class field_method_list fieldfield_method_list type ID(state) BOOLEAN method field_method_list … … parser uses stream of tokens and generate derivation tree Grammars: LL(1), LR(0), SLR(1), LALR(1), LR(1) Building parsers Transition diagram Parse table Running automaton Conflict resolution Write LR grammar for a language Ambiguity

Parsing and AST prog class_list class field_method_list fieldfield_method_list type ID(state) BOOLEAN method field_method_list … … Syntax tree built during parsing parser uses stream of token and generate derivation tree CLASS,CLASS_ID(Hello),LB,BOOLEAN,ID(state),SEMI … ProgAST ClassAST classList FieldAST[0] type:BoolType name:state MethodAST[0] MethodAST[1] MethodAST[2] … … methodList fieldList Should know difference between derivation tree and AST Know how to build AST from input

FieldsOrMethods ::= Field:field FieldsOrMethods:next {: RESULT = next; RESULT. addField(field); :} | Method:method FieldsOrMethods:next {: RESULT = next; RESULT.addMethod(method); :} | /* empty */ {: RESULT = new FieldsMethods(); :};

Typical Questions  Build an LR grammar for the language  Is the following grammar in LR(0), SLR(1), LALR(1), LR(1)  Build a parser for the grammar  Run an input string using your parser

Q1: Parsing  Is the following grammar in LR(0)? E  E + T E  T T  F F  id F  (E)

11 Answer  Add a production S  E$  Construct a finite automaton  States are set of items A  

12 S   E$ E   T E   E + T T   F F   i F   (E) E  T  T F  i  i S  E  $ E  E  + T E F  (  E) E   T E   E + T T   F F   i F   (E) ( ( F  (E)  ) F  (E  ) E  E  + T E E  E +  T T   F F   i F   (E) + + E  E + T  T S  E $  $ i i T  F  F F ( T F LR(0)

Q2: Parsing  Is the following grammar in LR(0)? E  E + T T  T * F E  T T  F F  id F  (E)

14 S   E$ E   T E   E + T T   T * F T   F F   i F   (E) E  T  T  T  * F T F  i  i S  E  $ E  E  + T E F  (  E) E   T E   E + T T   T * F T   F F   i F   (E) ( ( F  (E)  ) F  (E  ) E  E  + T E E  E +  T T   T * F T   F F   i F   (E) + + E  E + T  T  T  * F T S  E $  $ i i T  F  F F ( T F T  T *  F F   i F   (E) i ( T  T * F  F * *

Q3: Parsing  Is the following grammar in SLR(1)? E  E + T T  T * F E  T T  F F  id F  (E) ( We already know that its not LR(0) )

16 E  T  T  T  * F E  E + T  T  T  * F T  T *  F F   i F   (E) * * compute FOLLOW sets for each non terminal Use the FOLLOW set to break conflicts SLR(1) FIRST(E) = ? E  E + T E  T FIRST(T) = ? T  T * F T  F FIRST(F) = { id,( } S  E$ FOLLOW(E) = FOLLOW(E) U { $ } E  E + T FOLLOW(E) = FOLLOW(E) U { + } F  (E) FOLLOW(E) = FOLLOW(E) U { ) } FOLLOW(E) = {),+,$} S  E$ E  E + T T  T * F E  T T  F F  id F  (E)

17 Q4: Parsing 2.31 Can you create a top-down parser for the following grammars? (a) S  ‘(‘ S ‘)’ | ‘)’ (b) S  ‘(‘ S ‘)’ |  (c) S  ‘(‘ S ‘)’ | ‘)’ | 

18 Answer 2.31 Can you create a top-down parser for the following grammars? (a) S  ‘(‘ S ‘)’ | ‘)’ Yes – FIRST sets differ (b) S  ‘(‘ S ‘)’ |  Yes – FIRST and FOLLOW set differ (c) S  ‘(‘ S ‘)’ | ‘)’ |  No – FIRST and FOLLOW set overlap

19 Transition diagram Z   E $ E   E ‘+’ T E   T T   i T   ‘(’ E ‘)’ S0 Z  E  $ E  E  ‘+’ T S3 Z  E $  S6 T i E  E + T  S5 E  E ‘+’  T T   i T   ‘(’ E ‘)’ S4 E  T  S2 T  i  S1 T i ‘+’ E $ Q5: Complete the diagram for the LR(0) automaton…

20 Answer Q5 (fig 2.89) Z   E $ E   E ‘+’ T E   T T   i T   ‘(’ E ‘)’ S0 Z  E  $ E  E  ‘+’ T S3 Z  E $  S6 T i E  E + T  S5 E  E ‘+’  T T   i T   ‘(’ E ‘)’ S4 E  T  S2 T  i  S1 T i ‘+’ E $ T  ‘(’  E ‘)’ E   E ‘+’ T E   T T   i T   ‘(’ E ‘)’ S7 ‘(’ T i T  ‘(‘ E  ‘)’ E  E  ‘+’T S8 T  ‘(‘ E ‘)’  S9 ‘)’ E ‘(’ ‘+’

21 Q6: Parsing Can you find an input the exercises all states of the automaton?

22 Answer Q6 The following expression exercises all states ( i ) + i

23 Q7  derive the LR(1) ACTION/GOTO table for the following grammar: S  A | x b A  a A b | x

24 A  a  A b {b} A   a A b {b} A   x {b} S9 A  a A b  {b} S10 A b S8 A x A  a A  b {b} Answer Q7 - LR(1) automaton S   A {$} S   x b {$} A   a A b {$} A   x {$} S0 A  a  A b {$} A   a A b {b} A   x {b} S  x  b {$} A  x  {$} S1 S  x b  {$} S2 x b S6 A  a A b  {$} S7 A b A  a A  b {$} a S  A  {$} S3 S4 A A  x  {b} S5 x a

25 Q Is the following grammar LR(0), LALR(1), or LR(1) ? (a) S  x S x | y (b) S  x S x | x

26 Answer Q Is the following grammar LR(0), LALR(1), or LR(1) ? (a) S  x S x | y LR(0) (b) S  x S x | x None! A shift-reduce conflict remains

27 Q9 (a) Is this grammar LL(1) ? (b) Is this language LL(1) ? (c) Is this grammar LR(0) ? (d) Is this grammar LR(1) ? (e) Is this language regular ? S   | a | ‘(‘ S ‘)’ | ‘(‘ S ‘;’ S ‘)’

28 Answer Q9 (a) Is this grammar LL(1) ? No, last two rules have a common prefix (b) Is this language LL(1) ? Yes, can apply factoring to get S   | a | ‘(‘ S T T  ‘)’ | ‘;’ S ‘)’ S   | a | ‘(‘ S ‘)’ | ‘(‘ S ‘;’ S ‘)’

29 Answer Q9 (c) Is this grammar LR(0) ? No, there is a shift reduce conflict between the epsilon rule and the others (d) Is this grammar LR(1) ? Yes, the grammar is LR(1). FOLLOW(S) = { $, ;, ) }. Any LR(1) lookahead set for an S rule must be a subset of FOLLOW(s), and a and ( are not in FOLLOW(S). Thus, the LR(0) shift-reduce conflict is eliminated. (e) Is this language regular ? No, it requires bracketing (matching), and requires an unbounded number of states and so cannot be recognized by a finite automaton. S   | a | ‘(‘ S ‘)’ | ‘(‘ S ‘;’ S ‘)’

30 Q10 Prove that the following grammar is LL(1): declaration  ID declaration_tail declaration_tail , declaration declaration_tail  : ID ;

31 Answer Q10 Prove that the following grammar is LL(1): declaration  ID declaration_tail declaration_tail , declaration declaration_tail  : ID ; By definition, a grammar is LL(1) if it can be parsed by an LL(1) parser. It can be parsed by an LL(1) parser if no conflicts arise in the creation of the parse table. In this grammar, no symbols generate , so the table can be built entirely from FIRST sets; FOLLOW sets do not matter. There is only one symbol, declaration_tail, with more than one production, and the FIRST sets for the right-hand sides of those productions are distinct ({,} and {;}). Therefore no conflicts arise.

32 Semantic analysis  Context analysis  Does break and continue appear only inside while statement?  Scope analysis  Every variable is predefined  No double definitions  Bound variable use to its definition  Type checking  Every expression is well typed  Every statement is well typed

33 Semantic analysis Syntax analysis is not enough int a; a = “hello”; int a; b = 1; Assigning wrong type Assigning undeclared variable int a; int a; a = 1; Variable double declaration

34 Semantic analysis ProgAST ClassAST classList FieldAST[0] type:BoolType MethodAST[0] MethodAST[1] MethodAST[2] … … methodList fieldList  Representing scopes  Type-checking  Semantic checks SymbolKindType HelloclassHello SymbolKindTypeProperties statefieldbooleaninstance mainmethodstring[]->voidstatic risemethodvoid->booleaninstance setStatemethodboolean->voidinstance SymbolKindType newStateparamint (Program) (Hello) (setState) …

35 Examples of type errors int a; a = true; void foo(int x) { int x; foo(5,7); } 1 < true class A {…} class B extends A { void foo() { A a; B b; b = a; } } argument list doesn’t match formal parameters a is not a subtype of b assigned type doesn’t match declared type relational operator applied to non-int type

36 Type rules E  true : bool E  e1 : intE  e2 : int E  e1 op e2 : int E  false : bool E  int-literal : int E  string-literal : string op  { +, -, /, *, %} E  e1 : intE  e2 : int E  e1 rop e2 : bool rop  {, >=} E  e1 : TE  e2 : T E  e1 rop e2 : bool rop  { ==,!=}

Q11: Semantic conditions  What is checked in compile-time and what is checked in runtime? EventC/R Program execution halts Break/continue inside a while statement Array index within bound In Java the cast statement (A)f is legal In Java method o.m(…) is illegal since m is private

Semantic conditions  What is checked in compile-time and what is checked in runtime? EventC/R Program execution haltsR (undecidable in general) Break/continue inside a while statement C Array index within boundR (undecidable in general) In Java the cast statement (A)f is legal Depends: if A is sub-type of f then checked during runtime (raising exception), otherwise flagged as an error during compilation In Java method o.m(…) is illegal since m is private C

39 Q12: language features  Support Java override annotation inside comments   Annotation is written above method to indicate it overrides a method in superclass  Describe the phases in the compiler affected by the change and the changes themselves class A { void rise() {…} } class B extends A { void rise() {…} } class A { void rise() {…} } class B extends A { void ris() {…} } Legal program Illegal program

40 Answer  The change affects the lexical analysis, syntax analysis and semantic analysis  Does not affect later phases  User semantic condition

41 Changes to scanner  Add pattern inside comment state patterns  Change action for comments  instead of not returning any tokens, we now return a token for the annotation boolean override=false; % // { override=false; yybegin(comment); { override=true; } \n { if (override) return new Token(…,override,…) }

42 Changes to parser and AST PARSER method  static type name params ‘{‘ mbody ‘}’ | type name params ‘{‘ mbody ‘}’ | OVERRIDE type name params ‘{‘ mbody ‘}’ AST Add a Boolean flag to the method AST node to indicate that the method is annotated

43 Changes to semantic analysis  Suppose we have an override annotation for a method m in class A  We check the following semantic conditions 1. class A extends a superclass (otherwise it does not make sense to override a method) 2. Traverse the superclasses of A by going up the class hierarchy until we find the first method m and check that it has the same signature as A.m If we fail to find such a method we report an error

44 Intermediate representation  Allows language-independent, machine independent optimizations and transformations  Easy to translate from AST  Easy to translate to assembly ASTIR Pentium Java bytecode Sparc optimize

Translation to IR  Accept AST and translate functions into lists of instructions  Compute offsets for fields and virtual functions  Dispatch vectors  Register allocation 45

46 Q13: Translation to IR Question: write the method tables for Rectangle and Square class Shape { boolean isShape() {return true;} boolean isRectangle() {return false;} boolean isSquare() {return false;} double surfaceArea() {…} } class Rectangle extends Shape { double surfaceArea() {…} boolean isRectangle() {return true;} } class Square extends Rectangle { boolean isSquare() {return true;} }

Answer Shape_isShape Rectangle_isRectangle Shape_isSqaure Rectangle_surfaceArea Shape_isShape Rectangle_isRectangle Sqaure_isSqaure Rectangle_surfaceArea Method table for rectangleMethod table for square

48 Q14: Semantic Analysis 6.3 The following declarations are given for a language that uses name equivalence. A, B: array [1..10] of int; C : array [1..10] of int; D : array [1..10] of int; Which of these four variables have the same type?

49 Answer Q The following declarations are given for a language that uses name equivalence. A, B: array [1..10] of int; C : array [1..10] of int; D : array [1..10] of int; A and B

50 Q15 class A {...}; class B extends A {...}; B[] bArray = new B[10]; A[] aArray = bArray; A x =new A(); if (...)x =new B(); aArray[5]=x; (a) Explain why line 4 of the Java code, A[] aArray =bArray; is considered well-typed in Java. (b) Under what conditions could the assignment aArray[5]=x; lead to a run-time type error? Explain. (c) What does Java do to manage this problem with the assignment aArray[5]=x?

51 Q16  Add support of access qualifiers to a Java-like langauge  Allow methods to be defined as public or private  Public --- method accessible to all classes  Private --- method accessible only to its own class  Assume that subclasses cannot modify the accessibility defined by a superclass (e.g., a method defined private by a superclass cannot be made private by an overriding implementation)  Why is it helpful to have the assumption that access qualifiers are not modified by subclasses?

52 Disclaimer Questions provided here are just a sample of reasonable questions and do not cover all course material. In particular, emphasis in this collection was on parsing, neglecting other topics.

EXTRAS 53

54 Q17 Calculate nullable, FIRST and FOLLOW sets for the following grammar S  uBDz B  Bv B  w D  EF E  y E   F  x F  

Answer Q17 nullableFIRSTFOLLOW Bnowv,x,y,z Dyesx,yz Eyesyx,z Fyesxz Snou

56 Q18 Problem 3.8 from [Appel] A simple left-recursive grammar: S  S + a S  a A simple right-recursive grammar that accepts the same language: S  a + S S  a Which has better behavior for shift-reduce parsing?

57 Answer Q18 Consider the input string: a+a+a+a+a For the left-recursive case, the stack looks like: a (reduce) S S + S + a (reduce) S S + S + a (reduce) S S + S + a (reduce) S S + S + a (reduce) S The stack never has more than three items on it. In general, with LR-parsing of left-recursive grammars, an input string of length O(n) requires only O(1) space on the stack.

58 Answer Q18 For the right-recursive case, the stack looks like: a a + a + a a + a + a + a + a a + a + a + a a + a + a + a + a + a + a + a + a (reduce) a + a + a + a + S (reduce) a + a + a + S (reduce) a + a + S (reduce) a + S (reduce) S The stack grows as large as the input string. In general, with LR-parsing of right-recursive grammars, an input string of length O(n) requires O(n) space on the stack. (taken from

59 Q19  derive the LALR(1) automaton (and ACTION/GOTO table) for the following grammar: S  A | x b A  a A b | x

60 A  a A b  A  a A b  {b,$} Answer Q19 - LALR(1) automaton S   A {$} S   x b {$} A   a A b {b,$} A   x {b,$} S0 A  a  A b {b,$} A   a A b {b,$} A   x {b,$} S  x  b {$} A  x  {b,$} S1 S  x b  {$} S2 x b S6 S7 A b A  a A  b a S  A  {$} S3 S4 A S5 x S   A {$} S   x b {$} A   a A b {$} A   x {$} A  a  A b {b,$} A   a A b {b,$} A   x {b,$} S  x  b {$} A  x  {b,$} A a A  a A  b {b,$} A  x  {b}

61 LALR(1) ACTION/GOTO table state stack symbol / look-ahead token abx$A 0s4s1s3 1s2r4 2r2 3r1 4s4s5s6 5r4 6s7 7r3 1: S  A 2: S  x b 3: A  a A b 4: A  x

62 Q20  derive the SLR(1) ACTION/GOTO table (with shift-reduce conflict) for the following grammar: S  A | x b A  a A b | x

63 Answer Q20 state stack symbol / look-ahead token abx$A 0s4s1s3 1s2/r4r4 2r2 3r1 4s4s5s6 5r4 6s7 7r3 1: S  A 2: S  x b 3: A  a A b 4: A  x FOLLOW(S) = {$} FOLLOW(A) = {$,b}

64 Q21 P  E E  int E  E + E E  E / E E  E - E E  E * E E  E % E (a)Is this grammar ambiguous ? Why? [Yes]

65 Q21 (a) Draw an AST for the expression below. Label each AST node clearly with the meaning of the node (for example, "addition," "identifier," etc). Invent new types of AST nodes as necessary. x x (a) It is interesting to observe that while x x is a legal Java expression, the same expression without white spaces, namely x+++++x is not a legal Java expression. That is, the latter expression will cause a compile- time error. Identify the phase of the compiler in which the error occurred. Depending on the compiler, the error can be flagged in different stages, and so there is more than one correct answer.