The Gateway to Computer Science Excellence
+4 votes
368 views

A simple Pascal like language has only three statements.

  1. assignment statement e.g. x:=expression
  2. loop construct e.g. for i:=expression to expression do statement
  3. sequencing e.g. begin statement ;…; statement end
  1. Write a context-free grammar (CFG) for statements in the above language. Assume that expression has already been defined. Do not use optional parenthesis and * operator in CFG.
  2. Show the parse tree for the following statements:
    for j:=2 to 10 do
    begin 
        x:=expr1;
        y:=expr2;
    end
in Compiler Design by Veteran (52.2k points) | 368 views

1 Answer

+1 vote
  • $P \to A \mid L \mid A \mid S\mid \epsilon$
  • $A \to V := E $
  • $L \to for \; V := E \;to\; E\; do\; P$
  • $S \to begin\; P\;P\; end\mid \epsilon$
  • $V \to id$
by Veteran (425k points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,644 questions
56,500 answers
195,544 comments
100,995 users