Sei sulla pagina 1di 6

Guidelines for Making a Predictive Parser

Coding:
1. Define a syntax in term of token sequence for each statement type in your program i.e.
declaration statement, assignment statements, loops etc

2. Use the optimized transition diagram for parsing each statement and making a Predictive
Parser. You will be dealing with a procedural approach.

3. Generate meaningful errors where the syntax is not followed.

Documentation
1. You will make a separate chapter for each phase of compiler.

2. In the chapter regarding syntax analyzer, discuss

a. Grammar of each type of statement

b. Transition Diagram for each statement with optimization

c. Sample Source Code in your programming language

d. Snapshot of Output ( with and without errors)

e. Pseudo- code OR flowchart of your syntax analyzer

Presentation
5. Each group member should speak in the
presentation turn by turn

5. Be prepared to defend your project.

5. Remember how you implemented your lexical


analyzer as related questions may be asked.

5. Demonstrate your code and know how the parser


works.
EVALUATION SHEET FOR SYNTAX ANALYZER
(PREDICTIVE PARSER)
PROGRAMMING

# Checks Done(Y/N) Comments


1 Does the parser generate meaningful error if    
the declaration stmt is incomplete?
2 Does the parser generate meaningful error if    
the data type in a declaration is omitted?
3 Does the parser generate meaningful error if    
terminator is missed after a stmt?
4 Does the parser generate meaningful error if    
the condition is missed from an IF stmt?
5 Does the parser generate meaningful error if    
the IF stmt does not contain a THEN part?
6 Does the parser generate meaningful error if    
the ELSE part comes before the THEN part?
7 Does the parser generate meaningful error if    
any other lexeme comes out of sequence in
between the IF stmt?
8 Does the parser generate meaningful error if    
the WHILE condition is given incorrectly e.g x =
4 instead of x<4?
9 Does the parser generate meaningful error if    
there is nothing after the WHILE condition?
10 Does the parser generate meaningful error if    
the three statements in the FOR loops are
written in wrong order?
11 Does the parser generate meaningful error if    
the FOR loop is empty?
12 Does the parser generate meaningful error if    
the assignment statement doesn’t contain the
assignment operator?
13 Does the parser generate meaningful error if    
the arithmetic statements are written
incorrectly e.g. a b + written instead of a + b?
14 Does the parser generate meaningful error if    
the relational operators are used incorrectly ?
15 Does the parser generate meaningful error if    
the FUNCTION declaration misses a return
type?
16 Does the parser generate meaningful error if    
the FUNCTION contains no parameter?
17 Does the parser generate meaningful error if    
the parameters are not declared in a function ?
18 Does the parser generate meaningful error if    
the program has a start token but no end token
?
19 Does the parser generate meaningful error if    
something is written before the START token of
a program?
20 Does the parser generate meaningful error if    
something is written after the END token of a
program?
21      
DOCUMENTATION

Document Grammar Transition Pseudocode/Algo/Flowchar Snapshot


Content Diagram t
         
VIVA-VOCE AND PRESENTATION

Group Members Viva Presentation


     
     
     
     
     
     

EVALUATION SHEET FOR LEXICAL ANALYZER 2


PROGRAMMING

# Checks Done(Y/N) Comments


1 Does the error msg convey that case    
sensitivity has to be observed?
2 Error msg conveying that an identifier is    
invalid because of invalid chars in it.
3 Error msg conveying that an identifier is    
invalid because of Invalid length
4 Error msg conveying that a number is invalid    
because of Chars within a number
5 Error msg conveying that a number is invalid    
because of Symbols within a number
6 Error msg conveying that a number is invalid    
because of Two dots within a real number
7 Error msg conveying that a string is invalid    
because of Multiple starting symbol for string
literals e.g instead of ‘a’ what happens if ‘’a’ is
written
8 Error msg conveying that there is an invalid    
char within an operator e.g <a= instead of <=
9 Error msg conveying that there is an invalid    
number within an operator e.g <1= instead of
<=
10 Error msg conveying that there is an invalid    
symbol within an operator e.g <&= instead of
<=
11 Error msg conveying that Multi line comments    
started but not ended
12 Error msg conveying that Multi line comments    
ended but not started
13 Unbalanced multiline comment /* /* */     
OR /* */*/
14 Total Number of Errors    
15 Total Number of Lines    
16 Total Number of Words/ Lexemes    
17 Display of Line Number with every error    
DOCUMENTATION

Document Pseudocode/Algo/Flowchart Snapshot


Content
     
PRESENTATION

Group Members Presentation


   
   
   
   
Available from: Tuesday, 8 March 2011, 12:10 PM
Due date: Tuesday, 15 March 2011, 12:10 PM

 Guidelines for Lexical Analyzer Part II

Modify the code to make the lexical analyzer more friendly and informative

1. Allow nested levels in the code and store accordingly in the symbol table

2. Mention the total number of words and lines in the source code

3. Generate informative errors in the code along with the line numbers.

How can a lexical analyzer specify and recognize the following patterns?

1. Identifiers over {a,…,z} that are exactly four characters long

2. Identifiers over {a , b} containing atleast one occurrence of the substring aba

3. Identifiers over {$, c, ., 0, … ,9} that are legal descriptions of monetary quantities. e.g $43 ,
$5.22, 54c, and so on

4. Identifiers over {a , b} containing exactly one occurrence of the substring aba

5. Identifiers over {/, 0, … ,9} that contain date values in the format dd/mm/yyyy

· Store the <lexeme ,token> pairs in your symbol table

1. For ( int x= 0; x<=5; x++)

2. B= (( c + a) * d ) / f

3. While ( a < 5 )
a= a+1

4. Char MyCourse[5];

5. if ( a< b)
a=a*a;
else
b=b*b;

· Show how the following code will be stored in symbol Table

proc sum (int x17) {

int kk = 0;

proc doFoo {

real x17 = 0.0;

proc sum (int kk) {

return kk * x17;

Potrebbero piacerti anche