Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
BELGAUM
PROJECT WORK
Of
5TH SEMESTER COMPUTER SCIENCE & ENGINEERING
NAME ROLL.NO USN
ARJUN M.R 10 4JC07CS014
ESHWARA .C 19 4JC07CS032
HARIPRASAD K.B 21 4JC07CS038
Submitted by
Page | 1
Acknowledgement
The successful completion of a project involves the efforts of many people. We have
been lucky to have received a lot of help and support from all quarters during the
course of this project, so with gratitude we take this opportunity to acknowledge all
progress. It’s our privilege and honor to express our sincere gratitude to our guide,
our regards to our HOD, Dr. C.N.Ravikumar, Dept. of CS&E, SJCE, Mysore.
We are also grateful to all other teaching and nonteaching faculty of our department
Contents Page no
1. Introduction. 4-5
ii) Output
v) Functional requirements.
3. Results
5. Conclusion. 13-14
6. Reference. 15-16
1. Introduction
The syntax analyzer is a module that reads the token stream delivered by the lexer
module and builds a memory data structure containing the syntactically analyzed and
built program.
Page | 3
For the syntax analyzer the program is a series of commands. A command is a series
another command. Therefore the syntax definition is quite simple and yet still
parameters and the “global variables” for the syntactical analyzer. This structure
contains the pointer to the array containing the syntax definition. Each element of the
array defines command syntax. Command syntax is the list of the symbols that
construct the command. When the syntactical analyzer tries to analyze a line it tries
When checking a line against a syntax definition the syntactical analyzer takes the
lexical elements on the line and checks that they match the next symbol in the syntax
definition. A symbol can be as simple as a reserved word, like if else, endif. Such a
syntax element is matched by the specific keyword. On the other hand a symbol on
whole expression.
The Syntax analyzer is the section of the compiler which verifies the structure of the
Page | 4
Syntax Analysis or Hierarchical Analysis, in which characters or tokens are
analysis also termed as Parsing, involves grouping the tokens of the source program
into grammatical phrases that are used by the compiler to synthesize output. Usually,
the grammatical phrases of the source program are represented by a Parse tree.
2. REQUIREMENTS:
2.1 INPUT:
Page | 5
The input to the program should be given through a file. The input is a written ‘C’
2.2 OUTPUT:
The output of the Syntax analyzer is to verify the overall syntax of the input C
program and say ‘VALID’ if it is, or display the line number of the syntax error
saying the program is ‘INVALID’ if the program does not satisfy the grammar.
1. The program should accept a C file and validate its correctness of the syntax.
3. It should accept all the valid identifiers, numbers and arithmetic operations.
2. Efficiency in analyzing.
Page | 6
1.5.1 Hardware resources
➢ Intel processor
➢ Linux OS
➢ Editor
Page | 7
Lex Specifications
Features of lex:
1. Identifies the keywords, variables and identifiers and returns the token as the
value as yylex( ).
2. Increments the value of the line counter for the reference of the line number in
case of error.
3. Effectively ignores the comment lines and white spaces without returning to
yacc.
%{ (definition section)
Headerfiles inclusion
Page | 8
%}
(Identifiers)
%%
(Rules section)
%%
Yacc Specifications
Features of Yacc:
1. Verifies the complete structure of the C program using the tokens returned by the
lex specification.
rules structure.
parser.
4. It stores the action and goto table in the form of compressed array.
Structure of Yacc:
%{ (Definition Section)
Headerfile
%}
Page | 9
% token: token codes obtained as the value of yylex( ) from Lex scanner.
%%
(Production Section)
%%
main ( )
yyerror ( ) condition.
1. System Testing.
Page | 10
The final syntax analyzer is got through the a.out file
For Syntax analysis of any if else statement, the name of the file is specified in the
TEST CASES
NO FEATURE EXPECTED ACTUAL REMARKS
RESULT RESULT
Page | 11
1 ACCEPT YES YES PASS
INPUT FROM
FILE
2 ACCEPT THE YES YES PASS
IF ELSE
STATEMENT
OF LEVEL 1
3 ACCEPT THE YES YES PASS
IF ELSE
STATEMENT
OF LEVEL n
4 ERROR YES YES PASS
HANDLER
FOR IF(A>B)
5 ERROR YES YES PASS
HANDLER
FOR IF(A>B);
6 ERROR YES YES PASS
HANDLER
FOR OPEN
PARANTHESIS
7 ERROR YES YES PASS
HANDLER
FOR CLOSE
PARANTHESIS
RESULTS
Page | 12
In the Terminal:
Page | 13
Possible error in if else statements
In terminal
Page | 14
APPLICATIONS:
➢ The designed syntax analyzer can be effectively used to verify the syntax of
LIMITATIONS:
➢ The program returns line number of the first error occurred and proceeds
➢ The comment lines if any should be given only at the beginning or ending of
➢ The parse tree construction for the scanf and printf statements are not
CONCLUSION:
Syntax analyzer is the major module used in any compiler. By repeated testing, we
easily understandable interface for the user to interact with SAC. The Syntax errors
are successfully found along with the line number. The expected results have been
Page | 15
obtained and hence the implementation of the Syntax analyzer for C programming
REFERENCES:
4. http://en.wikipedia.org/wiki/Syntax analysis.
Page | 16