0% found this document useful (0 votes)
66 views23 pages

Superior University Lahore: Compiler Construction

This document describes a project to develop a syntax analyzer for PHP using Flex tools. A team of 3 students from Superior University Lahore are working on the project under the guidance of Miss Maryam. The project will build a syntax analyzer that can identify errors in PHP code such as missing tags or syntax mistakes. It will include developing regular expressions, DFAs, and lexical code in Flex to analyze the input code and generate an output identifying the lexical components and any errors.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views23 pages

Superior University Lahore: Compiler Construction

This document describes a project to develop a syntax analyzer for PHP using Flex tools. A team of 3 students from Superior University Lahore are working on the project under the guidance of Miss Maryam. The project will build a syntax analyzer that can identify errors in PHP code such as missing tags or syntax mistakes. It will include developing regular expressions, DFAs, and lexical code in Flex to analyze the input code and generate an output identifying the lexical components and any errors.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

SUPERIOR UNIVERSITY LAHORE

Faculty of Computer Science & IT


Compiler Construction

syntax analyzer for PHP

Project Team
Student Name Program Rool number Email Address
M. Wasal BSCS BCSM-F16-324 Bcsm-f16-324@superior.edu.pk
M. Ihsan BSCS BCSM-F16-352 Bcsm-f16-352@superior.edu.pk
Bilal Rasool BSCS BCSM-F16-314 Bcsm-f16-314@superior.edu.pk

Miss Maryam
Syntax analyzer for PHP
Syntax analyzer for PHP

Project Scope:
The purpose of this project to develop a compiler that is find any type(missing tag, syntax mistake)
of error in PHP . We are using different tools to build this project. We will build a Syntax analyzer
for PHP using flex code in this project.

Introduction:
PHP syntax analyzer analyze the code for language and then show what does it really means and
find out if there is any type of syntax error(missing tag, function error) in code that the user
provide at run time. So for all these purpose we use lex tools. That will helpful for new and
inexperienced users.
Lexical Analyzer
Regular Expression:
DFA:
Lexical Code:

%{

int total =0 ;

%}

%option noyywrap

%%

[''|,|;(|)|{|}|.|_] { fprintf(yyout,"This is Delimiter: %s\n\n",yytext);}

[[]] { fprintf(yyout,"This is Delimiter: %s\n\n",yytext);}

"#"|"?"|"@"|"$"|"^"|"%"|"^"|"&" { fprintf(yyout,"This is Special Characters: %s\n\n",yytext);}

"["|"]" { fprintf(yyout,"This is Delimiter: %s\n\n",yytext);}

"=" { fprintf(yyout,"This is Assignment Operator: %s\n\n",yytext);}

"+"|"- "|"*"|"/" { fprintf(yyout,"This is Arithmatic Operator: %s\n\n",yytext);}

"and"|"or"|"not"|"nand"|"xor"|"nor"|"xnor" { fprintf(yyout,"This is Logical Operators:


%s\n\n",yytext);}

"<="|">="|"++"|"!="|"=="|"<"|">" { fprintf(yyout,"This is Relational Operator: %s\n\n",yytext);}

("echo")|("function")|("if")|("else")|("while")|("do")|("break")|("continue")|("double")|("float")|("re
turn") { fprintf(yyout,"This is Keyword: %s\n\n",yytext);}

("php")|("case")|("sizeof")|("typedef")|("switch")|("goto") {fprintf(yyout,"This is
Keyword:%s\n",yytext);}

[a-zA-Z_][a-zA-Z0-9_]* { fprintf(yyout,"This is Identifier: %s\n\n",yytext);}


[0-9]*"."[0-9]+ { fprintf(yyout,"This is Fraction : %s\n\n", yytext);}

[-][0-9]*"."[0-9]+ { fprintf(yyout,"This is Negative Fraction : %s\n\n", yytext);}

[0-9]+ { fprintf(yyout,"This is Integer: %s\n\n",yytext);}

"-"[0-9]+ { fprintf(yyout,"This is Negative Integer: %s\n\n",yytext);}

["]([^"\\\n]|\\.|\\\n)*["] { fprintf(yyout,"this is String:%s\n\n",yytext);}

. {fprintf(yyout,"",yytext);}

[\t\n]+

%%

main()
{
extern FILE *yyin, *yyout;

yyin = fopen("input.txt", "r");

yyout = fopen("Output.txt", "w");

yylex();

return 0;
}
Input File:

Output File:
Syntax Analysis
CFG(un-ambiguous and Right Recursive):
CFG(Deterministic):
First() & Follow():
Algorithm:
LL(1)
Parsing Table:
Stack Implementation:
Semantic Analysis(S attributes):

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy