Vous êtes sur la page 1sur 106

LEXICAL ANALYSIS AND PARSER

WRITTEN IN C LANGUAGE
A SYNOPSIS
Minor Project Submitted in partial fulfillment of the requirement for Degree of
BACHELOR OF ENGINEERING
IN
COMPUTER SCIENCE &ENGINEERING
RA1IV GANDHI PRODYOGIKI VISHWAVIDYALAYA, BHOPAL (M.P.)]
Submitted By: Guided By:
Swati Kiyawat (0101CS011!"# Prof$%aji& pandey
%i'hi Pari(h (0101CS010!# Prof$Shi(ha )garwal
)lo( Sharma (0101*+0100,#
DEPARTMENT OF COMPUTER SCIENCE
UNIVERSITY INSTITUTE OF TECHNOLOGY
RA1IV GANDHI PRODYOGIKI VISHWAVIDYALYA, BHOPAL
April 2012
Rajiv Gandhi Prodyogiki Vishwavidyalaya, Bhopal
(M.P.)
Department of Computer Science & Engineering
CERTIFICATE
+hi' i' to certify that the wor( embodied in thi' 'ynop'i' entitled
~Lexical Analysis and Parser Written in C Language being
'ubmitted by ~Swati kiyawat (Roll No.: 0101CS091123) , ~Rishi
Parikh (Roll No.: 0101CS091092) & ~Alok Sharma (Roll No.:
0101IT091004) for partial fulfillment of the requirement for the degree of
~Bachelor of Engineering in Computer Science & Engineering
di'cipline to -%aji& .andhi Praudyogi(i /i'hwa&idyalaya0
1hopal(M$P$#2 during the academic year !01! i' a record of bona fide
piece of wor(0 carried out by him under my 'uper&i'ion and guidance in
the ~Department of Computer Science & Engineering, University
Institute of Technology, Bhopal (M.P.).
APPROVED & GUIDED BY:
Prof. Rajiv Pandey
Prof.Shikha Agarwal
(Profe''or0 Department 3f Computer Science 4 5ngineering#
ii
University Institute of Technology, Bhopal (M.P.)
Department Of Computer Science & Engineering
DECLARATION
6e Swati Kiyawat, Rishi Parikh and Alok Sharma0 'tudent' of
Bachelor of Engineering in Computer Science di'cipline0
session: 2012, University Institute of Technology-Bhopal
(M.P.), here by declare that the wor( pre'ented in thi' 'ynop'i'
entitled ~Lexical Analysis and Parser Written in C Language
i' the outcome of our own wor(0 i' bona fide and correct to the be't
of our (nowledge and thi' wor( ha' been carried out ta(ing care of
5ngineering 5thic'$ +he wor( pre'ented doe' not infringe any
patented wor( and ha' not been 'ubmitted to any other uni&er'ity
or anywhere el'e for the award of any degree or any profe''ional
diploma$
Swati Kiyawat
Date7 5nrollment 8o$7 0101CS011!"

%i'hi Pari(h
5nrollment 8o$7 0101CS010!

)lo( Sharma
5nrollment 8o$7 0101*+0100,

iii

CONTENTS
TOPIC NAME PAGE NO.
Certificate i
Declaration ii
)b'tract 1
1$0 *8+%3D9C+*38 2
1.1.0 Introduction to Lexical Grammar 3
1.2.0 Introduction to Token 4
1.3.0 How scanner and tokenizer works ? 4
1.4.0 Platorm used 7
!$0 P%3P3S5D M5+:3D3;3.< 9
2.1.0 !lock "ia#ram 9
2.2.0 "ata $low "ia#ram 9
2.3.0 $low %&art 11
"$0 )PP%3)C:5D %5S9;+ )8D C38C;9S*38 13
,$0 )PP;*C)+*38S )8D =9+9%5 63%K 14
%5=5%58C5S 15
i&
ABSTRACT
+he le>ical analy?er i' re'pon'ible for 'canning the 'ource input file and tran'lating
le>eme' ('tring'# into 'mall object' that the compiler for a high le&el language can
ea'ily proce''$ +he'e 'mall &alue' are often called -to(en'2$ +he le>ical analy?er i'
al'o re'pon'ible for con&erting 'equence' of digit' in to their numeric form a' well a'
proce''ing other literal con'tant'0 for remo&ing comment' and white 'pace' from the
'ource file0 and for ta(ing care of many other mechanical detail'$ ;e>ical analy?er
con&ert' 'tream of input character' into a 'tream of to(en'$ =or to(eni?ing into
identifier' and (eyword' we incorporate a 'ymbol table which initially con'i't' of
predefined (eyword'$ +he to(en' are read from an input file$ +he output file will
con'i't of all the to(en' pre'ent in our input file along with their re'pecti&e to(en
&alue'$
KEYWORDS: ;e>eme0 ;e>ical )naly'i'0 Compiler0 Par'er0 +o(en
1
1.0 INTRODUCTION
Compiler and its phases:
) compiler i' a program ta(e' a program written in a 'ource language and tran'late' it
into an equi&alent program in a target language.*t i' a program that tran'late' a high@
le&el language into a functionally equi&alent low@le&el language program$ So0a
compiler i' ba'ically a tran'lator who'e 'ource language i' high le&el language0and
target language i' low@le&el language0 that i'0 a compiler i' u'ed to implement a high
le&el language on a computer$
*n computer 'cience0 lexical analysis i' the proce'' of con&erting a 'equence of
character' into a 'equence of to(en'$ ) program or function which perform' le>ical
analy'i' i' called a lexical analyzer0 lexer or scanner$ ) le>er often e>i't' a' a 'ingle
function which i' called by a par'er or another function and wor(' along'ide other
component' for ma(ing compilation of a high le&el language po''ible$ +hi' complete
'etup i' what we call a compiler$
+o define what a compiler i' one mu't fir't define what a tran'lator i'$ ) tran'lator
i' a program that ta(e' another program written in one language0 al'o (nown a' the
'ource language0 and output' a program written in another language0 (nown a' the
target language$
8ow that the tran'lator i' defined0 a compiler can be defined a' a tran'lator$ +he
'ource language i' a high@le&el language 'uch a' Aa&a or Pa'cal and the target
language i' a low@le&el language 'uch a' machine or a''embly$
+here are fi&e part' of compilation (or pha'e' of the compiler#
1$# ;e>ical )naly'i'
!$# Synta> )naly'i'
"$# Semantic )naly'i'
,$# Code 3ptimi?ation
B$# Code .eneration
;e>ical )naly'i' i' the act of ta(ing an input 'ource program and outputting a
'tream of to(en'$ +hi' i' done with the Scanner$ +he Scanner can al'o place
identifier' into 'omething called the 'ymbol table or place 'tring' into the 'tring table$
+he Scanner can report tri&ial error' 'uch a' in&alid character' in the input file$
!
Synta> )naly'i' i' the act of ta(ing the to(en 'tream from the 'canner and
comparing them again't the rule' and pattern' of the 'pecified language$ Synta>
)naly'i' i' done with the Par'er$ +he Par'er produce' a tree0 which can come in many
format'0 but i' referred to a' the par'e tree$ *t report' error' when the to(en' do not
follow the s'ntax of the 'pecified language$ 5rror' that the Par'er can report are
'yntactical error' 'uch a' mi''ing parenthe'i'0 'emicolon'0 and (eyword'$
Semantic )naly'i' i' the act of determining whether or not the par'e tree i'
rele&ant and meaningful$ +he output i' intermediate code0 al'o (nown a' an
intermediate repre'entation (or *%#$ Mo't of the time0 thi' *% i' clo'ely related to
a''embly language but it i' machine independent$ *ntermediate code allow' different
code generator' for different machine' and promote' ab'traction and portability from
'pecific machine time' and language'$ (* dare to 'ay that the mo't famou' e>ample i'
ja&aC' byte@code and A/M#$ Semantic )naly'i' find' more meaningful error' 'uch a'
undeclared &ariable'0 type compatibility0 and 'cope re'olution$
Code 3ptimi?ation ma(e' the *% more efficient$ Code optimi?ation i' u'ually
done in a 'equence of 'tep'$ Some optimi?ation' include code ho'ting0 or mo&ing
con'tant &alue' to better place' within the code0 redundant code di'co&ery0 and
remo&al of u'ele'' code$
Code .eneration i' the final 'tep in the compilation proce''$ +he input to the
Code .enerator i' the *% and the output i' machine language code$
1.1.0 Introduction to Lexical Grammar
+he 'pecification of a programming language will often include a 'et of rule'
which define' the le>er$ +he'e rule' are u'ually called regular e>pre''ion' and they
define the 'et of po''ible character 'equence' that are u'ed to form to(en'
or le>eme'$ white'pace0 (i$e$ character' that are ignored#0 are al'o defined in
the regular e>pre''ion'$
"
1.2.0 Introduction to token
) token i' a 'tring of character'0 categori?ed according to the rule' a' a 'ymbol
(e$g$ *D58+*=*5%0 89M15%0 C3MM)0 etc$#$ +he proce'' of forming to(en' from
an input 'tream of character' i' called (tokenization# and the le>er categori?e' them
according to a 'ymbol type$ ) to(en can loo( li(e anything that i' u'eful for
proce''ing an input te>t 'tream or te>t file$
) le>ical analy?er generally doe' nothing with combination' of to(en'0 a ta'( left
for a par'er$ =or e>ample0 a typical le>ical analy?er recogni?e' parenthe'i' a' to(en'0
but doe' nothing to en'ure that each D(D i' matched with a D#D$
Con'ider thi' e>pre''ion in the C programming language7
'umE"F!G
+o(eni?ed in the following table7
+o(en' are frequently defined by regular e>pre''ion'0 which are under'tood by a
le>ical analy?er generator 'uch a' le>$ +he le>ical analy?er (either generated
automatically by a tool li(e le>0 or hand@crafted# read' in a 'tream of character'0
identifie' the le>eme' in the 'tream0 and categori?e' them into to(en'$ +hi' i' called
Hto(eni?ing$H *f the le>er find' an in&alid to(en0 it will report an error$
=ollowing to(eni?ing i' par'ing$ =rom there0 the interpreted data may be loaded
into data 'tructure' for general u'e0 interpretation0 or compiling$
lex
eme
token
type
Su
m
*dentifier
E
)''ignme
nt operator
" 8umber
F
)ddition
operator
! 8umber
G
5nd of
'tatement
,
1.3.0 How scanner and tokenizer work?
+he fir't 'tage0 the scanner0 i' u'ually ba'ed on a finite 'tate machine$ *t ha'
encoded within it information on the po''ible 'equence' of character' that can be
contained within any of the to(en' it handle' (indi&idual in'tance' of the'e character
'equence' are (nown a' le>eme'#$ =or in'tance0 an inte#er to(en may contain any
'equence of numerical digit character'$ *n many ca'e'0 the fir't non@white 'pace
character can be u'ed to deduce the (ind of to(en that follow' and 'ub'equent input
character' are then proce''ed one at a time until reaching a character that i' not in the
'et of character' acceptable for that to(en (thi' i' (nown a' the ma>imal munch rule0
or longe't match rule#$ *n 'ome language' the le>eme creation rule' are more
complicated and may in&ol&e bac(trac(ing o&er pre&iou'ly read character'$
Tokenization i' the proce'' of demarcating and po''ibly cla''ifying 'ection' of a
'tring of input character'$ +he re'ulting to(en' are then pa''ed on to 'ome other form
of proce''ing$ +he proce'' can be con'idered a 'ub@ta'( of par'ing input$
+a(e0 for e>ample0 the following 'tring$
+he quic( brown fo> jump' o&er the la?y dog
9nli(e human'0 a computer cannot intuiti&ely D'eeD that there are word'$ +o a
computer thi' i' only a 'erie' of ," character'$
A process of tokenization could be used to split the sentence into word
tokens. Although the following exaple is gi!en as "#$ there are an%
wa%s to represent tokenized input&
I'entenceJ
IwordJ+heIKwordJ
IwordJquic(IKwordJ
IwordJbrownIKwordJ
IwordJfo>IKwordJ
IwordJjump'IKwordJ
IwordJo&erIKwordJ
IwordJtheIKwordJ
IwordJla?yIKwordJ
IwordJdogIKwordJ
IK'entenceJ
B
) le>eme0 howe&er0 i' only a 'tring of character' (nown to be of a certain (ind
(eg0 a 'tring literal0 a 'equence of letter'#$ *n order to con'truct a to(en0 the le>ical
analy?er need' a 'econd 'tage0 the evaluator0 which goe' o&er the character' of the
le>eme to produce a (alue$ +he le>emeD' type combined with it' &alue i' what
properly con'titute' a to(en0 which can be gi&en to a par'er$ (Some to(en' 'uch a'
parenthe'e' do not really ha&e &alue'0 and 'o the e&aluator function for the'e can
return nothing$ +he e&aluator' for integer'0 identifier'0 and 'tring' can be con'iderably
more comple>$ Sometime' e&aluator' can 'uppre'' a le>eme entirely0 concealing it
from the par'er0 which i' u'eful for white'pace and comment'$#
=or e>ample0 in the 'ource code of a computer program the 'tring
netLworthLfuture E (a''et' @ liabilitie'#G
might be con&erted (with white'pace 'uppre''ed# into the le>ical to(en 'tream7
+hough it i' po''ible and 'ometime' nece''ary to write a le>er by hand0 le>er' are
often generated by automated tool'$ +he'e tool' generally accept regular e>pre''ion'
that de'cribe the to(en' allowed in the input 'tream$ 5ach regular e>pre''ion i'
a''ociated with a production in the le>ical grammar of the programming language that
e&aluate' the le>eme' matching the regular e>pre''ion$ +he'e tool' may generate
'ource code that can be compiled and e>ecuted or con'truct a 'tate table for a finite
'tate machine (which i' plugged into template code for compilation and e>ecution#$
%egular e>pre''ion' compactly repre'ent pattern' that the character' in le>eme'
might follow$ =or e>ample0 for an 5ngli'h@ba'ed language0 a 8)M5 to(en might be
any 5ngli'h alphabetical character or an under'core0 followed by any number of
NAME "net_worth_future"
EQUALS
OPEN_PARENTHESIS
NAME "assets"
MINUS
NAME "liabilities"
LOSE_PARENTHESIS
SEMIOLON
M
in'tance' of any )SC** alphanumeric character or an under'core$ +hi' could be
repre'ented compactly by the 'tring Na@?)@OLPNa@?)@OL0@PQ$ +hi' mean' Hany
character a@?0 )@O or L0 followed by 0 or more of a@?0 )@O0 L or 0@H$
%egular e>pre''ion' and the finite 'tate machine' they generate are not powerful
enough to handle recur'i&e pattern'0 'uch a' Hn opening parenthe'e'0 followed by a
'tatement0 followed by n clo'ing parenthe'e'$H +hey are not capable of (eeping count0
and &erifying that n i' the 'ame on both 'ide' R unle'' you ha&e a finite 'et of
permi''ible &alue' for n$ *t ta(e' a full@fledged par'er to recogni?e 'uch pattern' in
their full generality$ ) par'er can pu'h parenthe'e' on a 'tac( and then try to pop
them off and 'ee if the 'tac( i' empty at the end$
+he ;e> programming tool and it' compiler i' de'igned to generate code for fa't
le>ical analy'er' ba'ed on a formal de'cription of the le>ical 'ynta>$ *t i' not generally
con'idered 'ufficient for application' with a complicated 'et of le>ical rule' and
'e&ere performance requirement'G for in'tance0 the .89 Compiler Collection u'e'
hand@written le>er'$
1.4.0 Platform used
*n computing0 C i' a general@purpo'e computer programming language originally
de&eloped in 1S! by Denni' %itchie at the 1ell +elephone ;aboratorie' to implement
the 9ni> operating 'y'tem$
)lthough C wa' de'igned for writing architecturally independent 'y'tem 'oftware0
it i' al'o widely u'ed for de&eloping application 'oftware$
6orldwide0 C i' the fir't or 'econd mo't popular language in term' of number of
de&eloper po'ition' or publicly a&ailable code$ *t i' widely u'ed on many different
'oftware platform'0 and there are few computer architecture' for which a C compiler
doe' not e>i't$ C ha' greatly influenced many other popular programming language'0
mo't notably CFF0 which originally began a' an e>ten'ion to C0 and Aa&a and CT
which borrow C le>ical con&ention' and operator'$
i. %&aracteristics
S
;i(e mo't imperati&e language' in the );.3; tradition0 C ha' facilitie' for
'tructured programming and allow' le>ical &ariable 'cope and recur'ion0 while a 'tatic
type 'y'tem pre&ent' many unintended operation'$ *n C0 all e>ecutable code i'
contained within function'$ =unction parameter' are alway' pa''ed by &alue$ Pa''@by@
reference i' achie&ed in C by e>plicitly pa''ing pointer &alue'$ :eterogeneou'
aggregate data type' ('truct# allow related data element' to be combined and
manipulated a' a unit$ C program 'ource te>t i' free@format0 u'ing the 'emicolon a' a
'tatement terminator (not a delimiter#$
C al'o e>hibit' the following more 'pecific characteri'tic'7
non@ne't able function definition'
&ariable' may be hidden in ne'ted bloc('
partially wea( typingG for in'tance0 character' can be u'ed a' integer'
low@le&el acce'' to computer memory by con&erting machine addre''e' to
typed pointer'
function and data pointer' 'upporting ad &oc run@time polymorphi'm
array inde>ing a' a 'econdary notion0 defined in term' of pointer arithmetic
a preproce''or for macro definition0 'ource code file inclu'ion0 and conditional
compilation
comple> functionality 'uch a' *K30 'tring manipulation0 and mathematical
function' con'i'tently delegated to library routine'
) relati&ely 'mall 'et of re'er&ed (eyword' (originally "!0 now "S in C#
) large number of compound operator'0 'uch a' !"0 !!
ii. $eatures
+he relati&ely low@le&el nature of the language afford' the programmer clo'e
control o&er what the computer doe'0 while allowing 'pecial tailoring and aggre''i&e
optimi?ation for a particular platform$ +hi' allow' the code to run efficiently on &ery
limited hardware0 'uch a' embedded 'y'tem'$
iii. Tur)o %**
+urbo CFF i' a CFF compiler and integrated de&elopment en&ironment (*D5#
from 1orland$ +he original +urbo CFF product line wa' put on hold after 1,0 and
wa' re&i&ed in !00M a' an introductory@le&el *D50 e''entially a 'tripped@down &er'ion
of their flag'hip CFF 1uilder$ +urbo CFF !00M wa' relea'ed on September B0 !00M
and i' a&ailable in D5>plorerD and DProfe''ionalD edition'$ +he 5>plorer edition i' free to
U
download and di'tribute while the Profe''ional edition i' a commercial product$ +he
profe''ional edition i' no longer a&ailable for purcha'e from 1orland$
+urbo CFF "$0 wa' relea'ed in 11 ('hipping on 8o&ember !0#0 and came in
amid't e>pectation' of the coming relea'e of +urbo CFF for Micro'oft 6indow'$
*nitially relea'ed a' an MS@D3S compiler0 "$0 'upported CFF template'0 1orlandD'
inline a''embler0 and generation of MS@D3S mode e>ecutable' for both U0UM real@
mode 4 !UM@protected (a' well a' the *ntel U01UM$# "$0D' implemented )+4+ CFF
!$10 the mo't recent at the time$ +he 'eparate +urbo )''embler product wa' no longer
included0 but the inline@a''embler could 'tand in a' a reduced functionality &er'ion$
2.0 PROPOSED METHODOLOGY
)im of the project i' to de&elop a ;e>ical )naly?er that can generate to(en' for the
further proce''ing of compiler$ +he job of the le>ical analy?er i' to read the 'ource
program one character at a time and produce a' output a 'tream of to(en'$ +he to(en'
produced by the le>ical analy?er 'er&e a' input to the ne>t pha'e0 the par'er$ +hu'0 the
le>ical analy?erC' job i' to tran'late the 'ource program in to a form more conducti&e
to recognition by the par'er$
+he goal of thi' program i' to create to(en' from the gi&en input 'tream$
2.1.0 Block diagram
INPUT
SOURCE
IN C
TOKENIZED
OUTPUT
FILE
LEXICAL
ANALYSER
CODE

N=ig@ 17 1loc( Diagram for ;e>ical )naly?erP


2.2.0 Data Flow Diagram
) data flow diagram (DFD# i' a graphical repre'entation of the HflowH of data
through an information 'y'tem$ *t differ' from the flowchart a' it 'how' the data flow
in'tead of the control flow of the program$ ) data flow diagram can al'o be u'ed for
the &i'uali?ation of data proce''ing ('tructured de'ign#$
N=ig$@!7 Oero ;e&el Data =low Diagram for ;e>ical )naly?erP
N=ig$@"7 =ir't ;e&el Data =low Diagram for ;e>ical )naly?erP
SYMBOL
TABLE
10
N=ig$ @ ,7 Second ;e&el Data =low Diagram for ;e>ical )naly?erP
2.3.0 Flow Chart
) flowchart i' a common type of chart0 that repre'ent' an algorithm or a proce''0
'howing the 'tep' a' bo>e' of &ariou' (ind'0 and their order by connecting the'e with
arrow'$ =lowchart' are u'ed in analy?ing0 de'igning0 documenting or managing a
proce'' or program in &ariou' field'$
=lowchart' are u'ed in de'igning and documenting comple> proce''e'$ ;i(e other
type' of diagram0 they help &i'uali?e what i' going on and thereby help the &iewer to
under'tand a proce''0 and perhap' al'o find flaw'0 bottlenec('0 and other le''@ob&iou'
feature' within it$ +here are many different type' of flowchart'0 and each type ha' it'
own repertoire of bo>e' and notational con&ention'$ +he two mo't common type' of
bo>e' in a flowchart are7
) proce''ing 'tep0 u'ually called acti(it'0 and denoted a' a rectangular bo>
) deci'ion u'ually denoted a' a diamond$
11
Key: -
: START / END
: DECESSION
: PROCESS
: DISPLAY / OUTPUT
: MANUAL INPUT
1!
N=ig$@ B7 =low Chart for ;e>ical )naly?erP
Lex Intoduction:
;e> i' one of the compiler writing tool'0 that i' u'ed to generate a le>ical
analy?er or 'canner from de'cription of to(en' of programming language
to be implemented$
;e> ta(e' a 'pecially@formatted 'pecification file containing the detail' of
a le>ical analy?er$ +hi' tool then create' a C 'ource file for the a''ociated
table@dri&en le>er$
1"
Lex Specification:
*nput to the ;e> i' a te>t file containing regular e>pre''ion along with the
action' to be ta(en by the generated 'canner when each regular
e>pre''ion i' matched$
+he output i' a file that contain' C 'ource code defining procedure
yyle>(#0which implement' D=) corre'ponding to regular e>pre''ion
gi&en in input file$
+he output file i' u'ually called le>$yy$c or le>yy$c0 which when compiled
lin(ed to the main program act' a' a 'canner or le>ical analy?er
recogni?ing to(en' 'pecified by regular e>pre''ion of the input file$
) ;e> input file i' con'i't' of three part'0 a collection of definition'0 a
collection of rule'0 and a collection of u'er 'ubroutine'$ +he'e three
'ection' are 'eparated by double@percent directi&e' (VVWWDD#$
) proper ;e> 'pecification ha' the following format
definition]

rules]

user subroutines]
6here the definition 4 the u'er 'ubroutine' are often omitted$ +he
'econd WW i' optional0 but the fir't i' required to mar( the beginning of
rule'$
1,
CODING:
Lex Program:
WX
TincludeI'tdio$hJ
int (eyE00opE00idE0G
WY
;5++5% Na@?)@OP
D*.*+ N0@P
WW
begin X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
if X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
auto X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
brea( X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
ca'e X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
char X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
1B
con't X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
continue X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
default X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
do X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
double X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
el'e X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
enum X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
e>tern X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
float X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
1M
(eyFFG
Y
for X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
goto X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
int X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
long X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
regi'ter X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
return X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
'hort X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
'igned X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
1S
'i?eof X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
'tatic X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
'truct X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
'witch X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
typedef X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
union X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
un'igned X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
&oid X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
&olatile X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
1U
(eyFFG
Y
while X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
(then[near# X
(eyFFG
Y
N@FQKIJEP X
opFFG
Y
(IE[JE[\E# X
opFFG
Y
N0GZ$P G
X;5++5%Y(X;5++5%Y[XD*.*+Y#Q XidFFG
printf(H%ecogni?ed *D7W'ZnH0yyte>t#G
Y
WW
main(#
X
yyle>(#G
printf(Hnumber of *DD'EWdZt0K5<63%DSEWdZt03P5%)+3%SEWdZtH0id0(ey0op#G
Y
1
Lex.y.c file:
Tline " Hle>$yy$cH
Tdefine <<L*8+L);*.85D 'hort int
KQ ) le>ical 'canner generated by fle> QK
Tdefine =;5]LSC)885%
Tdefine <<L=;5]LM)A3%L/5%S*38 !
Tdefine <<L=;5]LM*83%L/5%S*38 B
Tdefine <<L=;5]LS91M*83%L/5%S*38 "B
Tif <<L=;5]LS91M*83%L/5%S*38 J 0
Tdefine =;5]L15+)
Tendif
KQ =ir't0 we deal with platform@'pecific or compiler@'pecific i''ue'$ QK
KQ begin 'tandard C header'$ QK
Tinclude I'tdio$hJ
Tinclude I'tring$hJ
Tinclude Ierrno$hJ
Tinclude I'tdlib$hJ
KQ end 'tandard C header'$ QK
KQ fle> integer type definition' QK
Tifndef =;5]*8+L:
Tdefine =;5]*8+L:
KQ C 'y'tem' ha&e Iinttype'$hJ$ 8on@C 'y'tem' may or may not$ QK
!0
Tif defined (LLS+DCL/5%S*38LL# 44 LLS+DCL/5%S*38LL JE 101;
KQ C 'ay' to define LLS+DCL;*M*+LM)C%3S before including 'tdint$h0
Q if you want the limit (ma>Kmin# macro' for int type'$
QK
Tifndef LLS+DCL;*M*+LM)C%3S
Tdefine LLS+DCL;*M*+LM)C%3S 1
Tendif
Tinclude Iinttype'$hJ
typedef intULt fle>LintULtG
typedef uintULt fle>LuintULtG
typedef int1MLt fle>Lint1MLtG
typedef uint1MLt fle>Luint1MLtG
typedef int"!Lt fle>Lint"!LtG
typedef uint"!Lt fle>Luint"!LtG
Tel'e
typedef 'igned char fle>LintULtG
typedef 'hort int fle>Lint1MLtG
typedef int fle>Lint"!LtG
typedef un'igned char fle>LuintULtG
typedef un'igned 'hort int fle>Luint1MLtG
typedef un'igned int fle>Luint"!LtG
Tendif KQ \ C QK
KQ ;imit' of integral type'$ QK
Tifndef *8+ULM*8
Tdefine *8+ULM*8 (@1!U#
Tendif
Tifndef *8+1MLM*8
Tdefine *8+1MLM*8 (@"!SMS@1#
Tendif
Tifndef *8+"!LM*8
Tdefine *8+"!LM*8 (@!1,S,U"M,S@1#
!1
Tendif
Tifndef *8+ULM)]
Tdefine *8+ULM)] (1!S#
Tendif
Tifndef *8+1MLM)]
Tdefine *8+1MLM)] ("!SMS#
Tendif
Tifndef *8+"!LM)]
Tdefine *8+"!LM)] (!1,S,U"M,S#
Tendif
Tifndef 9*8+ULM)]
Tdefine 9*8+ULM)] (!BB9#
Tendif
Tifndef 9*8+1MLM)]
Tdefine 9*8+1MLM)] (MBB"B9#
Tendif
Tifndef 9*8+"!LM)]
Tdefine 9*8+"!LM)] (,!,MS!B9#
Tendif
Tendif KQ \ =;5]*8+L: QK
Tifdef LLcplu'plu'
KQ +he Hcon'tH 'torage@cla''@modifier i' &alid$ QK
Tdefine <<L9S5LC38S+
Tel'e KQ \ LLcplu'plu' QK
KQ C require' LLS+DCLL to be defined a' 1$ QK
Tif defined (LLS+DCLL#
Tdefine <<L9S5LC38S+
!!
Tendif KQ defined (LLS+DCLL# QK
Tendif KQ \ LLcplu'plu' QK
Tifdef <<L9S5LC38S+
Tdefine yycon't con't
Tel'e
Tdefine yycon't
Tendif
KQ %eturned upon end@of@file$ QK
Tdefine <<L89;; 0
KQ Promote' a po''ibly negati&e0 po''ibly 'igned char to an un'igned
Q integer for u'e a' an array inde>$ *f the 'igned char i' negati&e0
Q we want to in'tead treat it a' an U@bit un'igned char0 hence the
Q double ca't$
QK
Tdefine <<LSCL+3L9*(c# ((un'igned int# (un'igned char# c#
KQ 5nter a 'tart condition$ +hi' macro really ought to ta(e a parameter0
Q but we do it the di'gu'ting crufty way forced on u' by the (#@le''
Q definition of 15.*8$
QK
Tdefine 15.*8 (yyL'tart# E 1 F ! Q
KQ +ran'late the current 'tart 'tate into a &alue that can be later handed
Q to 15.*8 to return to the 'tate$ +he <<S+)+5 alia' i' for le>
Q compatibility$
QK
Tdefine <<LS+)%+ (((yyL'tart# @ 1# K !#
Tdefine <<S+)+5 <<LS+)%+
KQ )ction number for 53= rule of a gi&en 'tart 'tate$ QK
Tdefine <<LS+)+5L53=('tate# (<<L58DL3=L19==5% F 'tate F 1#
!"
KQ Special action meaning H'tart proce''ing a new fileH$ QK
Tdefine <<L856L=*;5 yyre'tart(yyin #
Tdefine <<L58DL3=L19==5%LC:)% 0
KQ Si?e of default input buffer$ QK
Tifndef <<L19=LS*O5
Tdefine <<L19=LS*O5 1M"U,
Tendif
KQ +he 'tate buf mu't be large enough to hold one 'tate per character in the main
buffer$
QK
Tdefine <<LS+)+5L19=LS*O5 ((<<L19=LS*O5 F !# Q 'i?eof(yyL'tateLtype##
Tifndef <<L+<P5D5=L<<L19==5%LS+)+5
Tdefine <<L+<P5D5=L<<L19==5%LS+)+5
typedef 'truct yyLbufferL'tate Q<<L19==5%LS+)+5G
Tendif
e>tern int yylengG
e>tern =*;5 Qyyin0 QyyoutG
Tdefine 531L)C+LC38+*895LSC)8 0
Tdefine 531L)C+L58DL3=L=*;5 1
Tdefine 531L)C+L;)S+LM)+C: !
Tdefine <<L;5SSL;*8583(n#

KQ %eturn all but the fir't HnH matched character' bac( to the input 'tream$ QK
Tdefine yyle''(n# Z
do Z
!,
X Z
KQ 9ndo effect' of 'etting up yyte>t$ QK Z
int yyle''LmacroLarg E (n#G Z
<<L;5SSL;*8583(yyle''LmacroLarg#GZ
QyyLcp E (yyLholdLchar#G Z
<<L%5S+3%5L<<LM3%5L3==S5+ Z
(yyLcLbufLp# E yyLcp E yyLbp F yyle''LmacroLarg @
<<LM3%5L)DAG Z
<<LD3L15=3%5L)C+*38G KQ 'et up yyte>t again QK Z
Y Z
while ( 0 #
Tdefine unput(c# yyunput( c0 (yyte>tLptr# #
Tifndef <<L+<P5D5=L<<LS*O5L+
Tdefine <<L+<P5D5=L<<LS*O5L+
typedef 'i?eLt yyL'i?eLtG
Tendif
Tifndef <<LS+%9C+L<<L19==5%LS+)+5
Tdefine <<LS+%9C+L<<L19==5%LS+)+5
'truct yyLbufferL'tate
X
=*;5 QyyLinputLfileG
char QyyLchLbufG KQ input buffer QK
char QyyLbufLpo'G KQ current po'ition in input buffer QK
KQ Si?e of input buffer in byte'0 not including room for 531
Q character'$
QK
yyL'i?eLt yyLbufL'i?eG
KQ 8umber of character' read into yyLchLbuf0 not including 531
!B
Q character'$
QK
int yyLnLchar'G
KQ 6hether we HownH the buffer @ i$e$0 we (now we created it0
Q and can realloc(# it to grow it0 and 'hould free(# it to
Q delete it$
QK
int yyLi'LourLbufferG
KQ 6hether thi' i' an Hinteracti&eH input 'ourceG if 'o0 and
Q if weDre u'ing 'tdio for input0 then we want to u'e getc(#
Q in'tead of fread(#0 to ma(e 'ure we 'top fetching input after
Q each newline$
QK
int yyLi'Linteracti&eG
KQ 6hether weDre con'idered to be at the beginning of a line$
Q *f 'o0 D^D rule' will be acti&e on the ne>t match0 otherwi'e
Q not$
QK
int yyLatLbolG
int yyLb'LlinenoG KQQI +he line count$ QK
int yyLb'LcolumnG KQQI +he column count$ QK

KQ 6hether to try to fill the input buffer when we reach the
Q end of it$
QK
int yyLfillLbufferG
int yyLbufferL'tatu'G
Tdefine <<L19==5%L856 0
!M
Tdefine <<L19==5%L83%M); 1
KQ 6hen an 53=D' been 'een but thereD' 'till 'ome te>t to proce''
Q then we mar( the buffer a' <<L53=LP58D*8.0 to indicate that we
Q 'houldnDt try reading from the input 'ource any more$ 6e might
Q 'till ha&e a bunch of to(en' to match0 though0 becau'e of
Q po''ible bac(ing@up$
Q
Q 6hen we actually 'ee the 53=0 we change the 'tatu' to HnewH
Q (&ia yyre'tart(##0 'o that the u'er can continue 'canning by
Q ju't pointing yyin at a new input file$
QK
Tdefine <<L19==5%L53=LP58D*8. !
YG
Tendif KQ \<<LS+%9C+L<<L19==5%LS+)+5 QK
KQ Stac( of input buffer'$ QK
'tatic 'i?eLt yyLbufferL'tac(Ltop E 0G KQQI inde> of top of 'tac($ QK
'tatic 'i?eLt yyLbufferL'tac(Lma> E 0G KQQI capacity of 'tac($ QK
'tatic <<L19==5%LS+)+5 Q yyLbufferL'tac( E 0G KQQI Stac( a' an array$ QK
KQ 6e pro&ide macro' for acce''ing buffer 'tate' in ca'e in the
Q future we want to put the buffer 'tate' in a more general
Q H'canner 'tateH$
Q
Q %eturn' the top of the 'tac(0 or 89;;$
QK
Tdefine <<LC9%%58+L19==5% ( (yyLbufferL'tac(# Z
_ (yyLbufferL'tac(#N(yyLbufferL'tac(Ltop#P Z
7 89;;#
KQ Same a' pre&iou' macro0 but u'eful when we (now that the buffer 'tac( i' not
Q 89;; or when we need an l&alue$ =or internal u'e only$
QK
!S
Tdefine <<LC9%%58+L19==5%L;/);95 (yyLbufferL'tac(#
N(yyLbufferL'tac(Ltop#P
KQ yyLholdLchar hold' the character lo't when yyte>t i' formed$ QK
'tatic char yyLholdLcharG
'tatic int yyLnLchar'G KQ number of character' read into yyLchLbuf QK
int yylengG
KQ Point' to current character in buffer$ QK
'tatic char QyyLcLbufLp E (char Q# 0G
'tatic int yyLinit E 0G KQ whether we need to initiali?e QK
'tatic int yyL'tart E 0G KQ 'tart 'tate number QK
KQ =lag which i' u'ed to allow yywrap(#D' to do buffer 'witche'
Q in'tead of 'etting up a fre'h yyin$ ) bit of a hac( $$$
QK
'tatic int yyLdidLbufferL'witchLonLeofG
&oid yyre'tart (=*;5 QinputLfile #G
&oid yyL'witchLtoLbuffer (<<L19==5%LS+)+5 newLbuffer #G
<<L19==5%LS+)+5 yyLcreateLbuffer (=*;5 Qfile0int 'i?e #G
&oid yyLdeleteLbuffer (<<L19==5%LS+)+5 b #G
&oid yyLflu'hLbuffer (<<L19==5%LS+)+5 b #G
&oid yypu'hLbufferL'tate (<<L19==5%LS+)+5 newLbuffer #G
&oid yypopLbufferL'tate (&oid #G
'tatic &oid yyen'ureLbufferL'tac( (&oid #G
'tatic &oid yyLloadLbufferL'tate (&oid #G
'tatic &oid yyLinitLbuffer (<<L19==5%LS+)+5 b0=*;5 Qfile #G
Tdefine <<L=;9S:L19==5% yyLflu'hLbuffer(<<LC9%%58+L19==5% #
<<L19==5%LS+)+5 yyL'canLbuffer (char Qba'e0yyL'i?eLt 'i?e #G
<<L19==5%LS+)+5 yyL'canL'tring (yycon't char QyyL'tr #G
!U
<<L19==5%LS+)+5 yyL'canLbyte' (yycon't char Qbyte'0int len #G
&oid Qyyalloc (yyL'i?eLt #G
&oid Qyyrealloc (&oid Q0yyL'i?eLt #G
&oid yyfree (&oid Q #G
Tdefine yyLnewLbuffer yyLcreateLbuffer
Tdefine yyL'etLinteracti&e(i'Linteracti&e# Z
X Z
if ( \ <<LC9%%58+L19==5% #X Z
yyen'ureLbufferL'tac( (#G Z
<<LC9%%58+L19==5%L;/);95 E Z
yyLcreateLbuffer(yyin0<<L19=LS*O5 #G Z
Y Z
<<LC9%%58+L19==5%L;/);95@JyyLi'Linteracti&e E i'Linteracti&eG Z
Y
Tdefine yyL'etLbol(atLbol# Z
X Z
if ( \ <<LC9%%58+L19==5% #XZ
yyen'ureLbufferL'tac( (#G Z
<<LC9%%58+L19==5%L;/);95 E Z
yyLcreateLbuffer(yyin0<<L19=LS*O5 #G Z
Y Z
<<LC9%%58+L19==5%L;/);95@JyyLatLbol E atLbolG Z
Y
Tdefine <<L)+L13;(# (<<LC9%%58+L19==5%L;/);95@JyyLatLbol#
KQ 1egin u'er 'ect" QK
typedef un'igned char <<LC:)%G
!
=*;5 Qyyin E (=*;5 Q# 00 Qyyout E (=*;5 Q# 0G
typedef int yyL'tateLtypeG
e>tern int yylinenoG
int yylineno E 1G
e>tern char Qyyte>tG
Tdefine yyte>tLptr yyte>t
'tatic yyL'tateLtype yyLgetLpre&iou'L'tate (&oid #G
'tatic yyL'tateLtype yyLtryL89;Ltran' (yyL'tateLtype currentL'tate #G
'tatic int yyLgetLne>tLbuffer (&oid #G
'tatic &oid yyLfatalLerror (yycon't char m'gNP #G
KQ Done after the current pattern ha' been matched and before the
Q corre'ponding action @ 'et' up yyte>t$
QK
Tdefine <<LD3L15=3%5L)C+*38 Z
(yyte>tLptr# E yyLbpG Z
yyleng E ('i?eLt# (yyLcp @ yyLbp#G Z
(yyLholdLchar# E QyyLcpG Z
QyyLcp E DZ0DG Z
(yyLcLbufLp# E yyLcpG
Tdefine <<L89ML%9;5S "
Tdefine <<L58DL3=L19==5% ,0
KQ +hi' 'truct i' not u'ed in thi' 'canner0
but it' pre'ence i' nece''ary$ QK
'truct yyLtran'Linfo
X
fle>Lint"!Lt yyL&erifyG
fle>Lint"!Lt yyLn>tG
"0
YG
'tatic yycon't fle>Lint1MLt yyLacceptN1MBP E
X 00
00 00 ,00 "0 "0 "B0 "S0 "B0 "B0 "U0
"U0 "U0 "U0 "U0 "U0 "U0 "U0 "U0 "U0 "U0
"U0 "U0 "U0 "U0 "U0 "U0 "M0 "U0 "U0 "U0
"U0 "U0 "U0 "U0 "U0 100 "U0 "U0 "U0 "U0
"U0 "U0 !0 "U0 "U0 "U0 "U0 "U0 "U0 "U0
"U0 "U0 "U0 "U0 "U0 "U0 "U0 "U0 "U0 "U0
"U0 "U0 "U0 "U0 "U0 "U0 "U0 "U0 1M0 "U0
1U0 "U0 "U0 "U0 "U0 "U0 "U0 "U0 "U0 "U0
"U0 "U0 "U0 "U0 "U0 "U0 "U0 "U0 "0 "U0
"U0 B0 M0 "U0 "U0 "U0 "U0 1!0 1"0 "U0
"U0 1S0 10 ",0 "U0 "U0 "U0 "U0 "U0 "U0
"U0 "U0 "U0 "U0 "U0 "10 "U0 "U0 10 ,0
S0 "U0 "U0 "U0 "U0 1B0 "U0 "U0 !!0 "U0
"U0 "U0 "U0 "U0 "U0 !0 "U0 "U0 ""0 "U0
"U0 110 1,0 "U0 !10 !"0 !,0 !B0 !M0 !S0
"U0 "U0 "U0 "U0 0 "U0 !U0 "U0 "U0 U0
!00 "00 "!0 0
Y G
'tatic yycon't fle>Lint"!Lt yyLecN!BMP E
X 00
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 !0 10 10 10 10 10 10 10
10 "0 "0 ,0 "0 ,0 "0 B0 B0 B0
B0 B0 B0 B0 B0 B0 B0 10 ,0 M0
S0 U0 10 10 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
"1
10 10 10 10 10 10 100 110 1!0 1"0
1,0 1B0 1M0 1S0 1U0 0 10 !00 !10 !!0
!"0 !,0 0 !B0 !M0 !S0 !U0 !0 "00 "10
"!0 ""0 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 1
Y G
'tatic yycon't fle>Lint"!Lt yyLmetaN",P E
X 00
10 10 10 10 !0 10 10 10 !0 !0
!0 !0 !0 !0 !0 !0 !0 !0 !0 !0
!0 !0 !0 !0 !0 !0 !0 !0 !0 !0
!0 !0 !
Y G
'tatic yycon't fle>Lint1MLt yyLba'eN1MMP E
X 00
00 00 1S,0 1SB0 1MM0 1SB0 1SB0 1MB0 1M,0 00
1,!0 !00 !B0 !"0 1M0 !00 1,M0 !0 1,B0 1B"0
1B!0 "!0 !!0 1,"0 1,10 1,M0 1SB0 00 1"B0 1,B0
"!
1,M0 1""0 1,U0 1"B0 1,10 1!S0 1!U0 1!B0 1!B0 1!U0
1!B0 1!!0 00 1!10 1!B0 1"M0 !B0 1!!0 "S0 ,M0
1!M0 1!0 11U0 "S0 ,00 1!"0 11S0 1!10 1!U0 1!"0
1110 "U0 1!B0 1!"0 110 1110 11S0 1!00 00 10M0
00 11!0 10!0 10U0 S0 0 1010 10U0 ,0 !0
!0 M0 10"0 "0 S0 1010 10"0 !0 00 U0
10 00 00 U!0 00 S0 UM0 00 00 U00
SS0 00 00 00 SS0 SS0 S,0 UM0 SM0 U00
UB0 U,0 U!0 S!0 SS0 00 MB0 SS0 00 00
00 MU0 M0 S,0 MB0 00 B0 M"0 00 S10
MU0 S00 B,0 M"0 MB0 00 BM0 B0 00 ,U0
,U0 00 00 M00 00 00 00 00 00 00
BU0 BU0 ,0 B,0 00 ,!0 00 B"0 ,S0 00
00 00 00 1SB0 BB
Y G
'tatic yycon't fle>Lint1MLt yyLdefN1MMP E
X 00
1M,0 10 1M,0 1M,0 1M,0 1M,0 1M,0 1M,0 1M,0 1MB0
1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0
1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1M,0 1MB0 1MB0 1MB0
1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0
1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0
1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0
1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0
1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0
1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0
1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0
1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0
1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0
1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0
1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0
""
1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0
1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0 1MB0
1MB0 1MB0 1MB0 00 1M,
Y G
'tatic yycon't fle>Lint1MLt yyLn>tN!0P E
X 00
,0 B0 M0 S0 ,0 U0 M0 0 100 110
1!0 1"0 1,0 1B0 1M0 1S0 100 1U0 100 10
100 !00 100 100 !10 !!0 !"0 !,0 !B0 !M0
100 100 100 "00 "!0 "S0 "B0 "U0 B!0 ,00
S,0 ""0 ,10 ,"0 "10 "M0 "0 ",0 ,U0 ,0
,,0 SB0 SS0 B"0 U,0 S0 !U0 UM0 B00 US0
1M"0 B10 UB0 ,0 B0 1M!0 1M10 1M00 1B0 SU0
U00 1BU0 1BS0 1BM0 1BB0 1B,0 1B"0 1B!0 1B10 1B00
1,0 1,U0 1,S0 1,M0 1,B0 1,,0 1,"0 1,!0 1,10 1,00
1"0 1"U0 1"S0 1"M0 1"B0 1",0 1""0 1"!0 1"10 1"00
1!0 1!U0 1!S0 1!M0 1!B0 1!,0 1!"0 1!!0 1!10 1!00
110 11U0 11S0 11M0 11B0 11,0 11"0 10,0 11!0 1110
1100 100 10U0 10S0 10M0 10B0 10,0 10"0 10!0 1010
1000 0 U0 S0 M0 "0 !0 10 00 U0
UU0 U"0 U!0 U10 SM0 S"0 S!0 S10 S00 M0
MU0 MS0 MM0 MB0 M,0 M"0 M!0 M10 M00 B0
BU0 BS0 BM0 BB0 B,0 ,S0 ,M0 ,B0 ,!0 !0
!S0 !S0 !S0 1M,0 "0 1M,0 1M,0 1M,0 1M,0 1M,0
1M,0 1M,0 1M,0 1M,0 1M,0 1M,0 1M,0 1M,0 1M,0 1M,0
1M,0 1M,0 1M,0 1M,0 1M,0 1M,0 1M,0 1M,0 1M,0 1M,0
1M,0 1M,0 1M,0 1M,0 1M,0 1M,0 1M,0 1M,
Y G
'tatic yycon't fle>Lint1MLt yyLch(N!0P E
X 00
",
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 1!0 1"0 1B0 1,0 1B0 !"0 1M0
,S0 1"0 1M0 1U0 1!0 1,0 1B0 1"0 !!0 !!0
1U0 ,S0 ,0 !"0 B,0 B00 1MB0 BB0 !!0 BB0
1B0 !!0 B,0 M!0 M!0 1BU0 1BM0 1B,0 1B"0 ,0
B00 1B!0 1B10 1,,0 1,10 1,00 1"U0 1"S0 1"B0 1",0
1""0 1"!0 1"10 1"00 1!U0 1!S0 1!B0 1!,0 1!"0 1!!0
11U0 11S0 11B0 11,0 11"0 11!0 1110 1100 100 10U0
10S0 10M0 10B0 1010 1000 S0 M0 B0 ,0 10
00 UU0 US0 UM0 UB0 U,0 U"0 U!0 U10 U00
S0 SU0 SS0 SM0 SB0 S,0 S"0 S!0 S00 MU0
MS0 MM0 MB0 M,0 M"0 M10 M00 B0 BU0 BS0
BM0 B"0 B!0 B10 ,U0 ,M0 ,B0 ,,0 ,!0 ,10
,00 "0 "U0 "S0 "M0 "B0 ",0 ""0 "!0 "10
"00 !0 !M0 !B0 !,0 !10 !00 10 1S0 110
0 U0 B0 "0 1M,0 1M,0 1M,0 1M,0 1M,0 1M,0
1M,0 1M,0 1M,0 1M,0 1M,0 1M,0 1M,0 1M,0 1M,0 1M,0
1M,0 1M,0 1M,0 1M,0 1M,0 1M,0 1M,0 1M,0 1M,0 1M,0
1M,0 1M,0 1M,0 1M,0 1M,0 1M,0 1M,0 1M,
Y G
'tatic yyL'tateLtype yyLla'tLacceptingL'tateG
'tatic char QyyLla'tLacceptingLcpo'G
e>tern int yyLfle>LdebugG
int yyLfle>Ldebug E 0G
KQ +he intent behind thi' definition i' that itDll catch
Q any u'e' of %5A5C+ which fle> mi''ed$
QK
"B
Tdefine %5A5C+ rejectLu'edLbutLnotLdetected
Tdefine yymore(# yymoreLu'edLbutLnotLdetected
Tdefine <<LM3%5L)DA 0
Tdefine <<L%5S+3%5L<<LM3%5L3==S5+
char Qyyte>tG
Tline 1 Heuo$lH
Tline ! Heuo$lH
TincludeI'tdio$hJ
int (eyE00opE00idE0G
Tline BB0 Hle>$yy$cH
Tdefine *8*+*); 0
Tifndef <<L83L98*S+DL:
KQ Special ca'e for Huni'td$hH0 'ince it i' non@)8S*$ 6e include it way
Q down here becau'e we want the u'erD' 'ection 1 to ha&e been 'canned fir't$
Q +he u'er ha' a chance to o&erride it with an option$
QK
Tinclude Iuni'td$hJ
Tendif
Tifndef <<L5]+%)L+<P5
Tdefine <<L5]+%)L+<P5 &oid Q
Tendif
'tatic int yyLinitLglobal' (&oid #G
KQ )cce''or method' to global'$
+he'e are made &i'ible to non@reentrant 'canner' for con&enience$ QK
int yyle>Lde'troy (&oid #G
int yygetLdebug (&oid #G
"M
&oid yy'etLdebug (int debugLflag #G
<<L5]+%)L+<P5 yygetLe>tra (&oid #G
&oid yy'etLe>tra (<<L5]+%)L+<P5 u'erLdefined #G
=*;5 QyygetLin (&oid #G
&oid yy'etLin (=*;5 Q inL'tr #G
=*;5 QyygetLout (&oid #G
&oid yy'etLout (=*;5 Q outL'tr #G
int yygetLleng (&oid #G
char QyygetLte>t (&oid #G
int yygetLlineno (&oid #G
&oid yy'etLlineno (int lineLnumber #G
KQ Macro' after thi' point can all be o&erridden by u'er definition' in
Q 'ection 1$
QK
Tifndef <<LSK*PL<<6%)P
Tifdef LLcplu'plu'
e>tern HCH int yywrap (&oid #G
Tel'e
e>tern int yywrap (&oid #G
Tendif
Tendif
"S
'tatic &oid yyunput (int c0char QbufLptr #G

Tifndef yyte>tLptr
'tatic &oid yyLfle>L'trncpy (char Q0yycon't char Q0int #G
Tendif
Tifdef <<L855DLS+%;58
'tatic int yyLfle>L'trlen (yycon't char Q #G
Tendif
Tifndef <<L83L*8P9+
Tifdef LLcplu'plu'
'tatic int yyinput (&oid #G
Tel'e
'tatic int input (&oid #G
Tendif
Tendif
KQ )mount of 'tuff to 'lurp up with each read$ QK
Tifndef <<L%5)DL19=LS*O5
Tdefine <<L%5)DL19=LS*O5 U1!
Tendif
KQ Copy whate&er the la't rule matched to the 'tandard output$ QK
Tifndef 5C:3
KQ +hi' u'ed to be an fput'(#0 but 'ince the 'tring might contain 89;D'0
Q we now u'e fwrite(#$
QK
Tdefine 5C:3 do X if (fwrite( yyte>t0 yyleng0 10 yyout ## XY Y while (0#
Tendif
KQ .et' input and 'tuff' it into HbufH$ number of character' read0 or <<L89;;0
"U
Q i' returned in Hre'ultH$
QK
Tifndef <<L*8P9+
Tdefine <<L*8P9+(buf0re'ult0ma>L'i?e# Z
if ( <<LC9%%58+L19==5%L;/);95@JyyLi'Linteracti&e # Z
X Z
int c E DQDG Z
un'igned nG Z
for ( n E 0G n I ma>L'i?e 44 Z
(c E getc( yyin ## \E 53= 44 c \E DZnDG FFn # Z
bufNnP E (char# cG Z
if ( c EE DZnD # Z
bufNnFFP E (char# cG Z
if ( c EE 53= 44 ferror( yyin # # Z
<<L=)+);L5%%3%( Hinput in fle> 'canner failedH #G Z
re'ult E nG Z
Y Z
el'e Z
X Z
errnoE0G Z
while ( (re'ult E fread(buf0 10 ma>L'i?e0 yyin##EE0 44 ferror(yyin## Z
X Z
if( errno \E 5*8+%# Z
X Z
<<L=)+);L5%%3%( Hinput in fle> 'canner failedH #G Z
brea(G Z
Y Z
errnoE0G Z
clearerr(yyin#G Z
Y Z
YZ
Z
Tendif
"
KQ 8o 'emi@colon after returnG correct u'age i' to write Hyyterminate(#GH @
Q we donDt want an e>tra DGD after the HreturnH becau'e that will cau'e
Q 'ome compiler' to complain about unreachable 'tatement'$
QK
Tifndef yyterminate
Tdefine yyterminate(# return <<L89;;
Tendif
KQ 8umber of entrie' by which 'tart@condition 'tac( grow'$ QK
Tifndef <<LS+)%+LS+)CKL*8C%
Tdefine <<LS+)%+LS+)CKL*8C% !B
Tendif
KQ %eport a fatal error$ QK
Tifndef <<L=)+);L5%%3%
Tdefine <<L=)+);L5%%3%(m'g# yyLfatalLerror( m'g #
Tendif
KQ end table' 'eriali?ation 'tructure' and prototype' QK
KQ Default declaration of generated 'canner @ a define 'o the u'er can
Q ea'ily add parameter'$
QK
Tifndef <<LD5C;
Tdefine <<LD5C;L*SL39%S 1
e>tern int yyle> (&oid#G
Tdefine <<LD5C; int yyle> (&oid#
Tendif KQ \<<LD5C; QK
KQ Code e>ecuted at the beginning of each rule0 after yyte>t and yyleng
Q ha&e been 'et up$
,0
QK
Tifndef <<L9S5%L)C+*38
Tdefine <<L9S5%L)C+*38
Tendif
KQ Code e>ecuted at the end of each rule$ QK
Tifndef <<L1%5)K
Tdefine <<L1%5)K brea(G
Tendif
Tdefine <<L%9;5LS5+9P Z
<<L9S5%L)C+*38
KQQ +he main 'canner function which doe' all the wor($
QK
<<LD5C;
X
regi'ter yyL'tateLtype yyLcurrentL'tateG
regi'ter char QyyLcp0 QyyLbpG
regi'ter int yyLactG

Tline S Heuo$lH
Tline S", Hle>$yy$cH
if ( \(yyLinit# #
X
(yyLinit# E 1G
Tifdef <<L9S5%L*8*+
<<L9S5%L*8*+G
Tendif
if ( \ (yyL'tart# #
,1
(yyL'tart# E 1G KQ fir't 'tart 'tate QK
if ( \ yyin #
yyin E 'tdinG
if ( \ yyout #
yyout E 'tdoutG
if ( \ <<LC9%%58+L19==5% # X
yyen'ureLbufferL'tac( (#G
<<LC9%%58+L19==5%L;/);95 E
yyLcreateLbuffer(yyin0<<L19=LS*O5 #G
Y
yyLloadLbufferL'tate( #G
Y
while ( 1 # KQ loop' until end@of@file i' reached QK
X
yyLcp E (yyLcLbufLp#G
KQ Support of yyte>t$ QK
QyyLcp E (yyLholdLchar#G
KQ yyLbp point' to the po'ition in yyLchLbuf of the 'tart of
Q the current run$
QK
yyLbp E yyLcpG
yyLcurrentL'tate E (yyL'tart#G
yyLmatch7
do
X
regi'ter <<LC:)% yyLc E yyLecN<<LSCL+3L9*(QyyLcp#PG
,!
if ( yyLacceptNyyLcurrentL'tateP #
X
(yyLla'tLacceptingL'tate# E yyLcurrentL'tateG
(yyLla'tLacceptingLcpo'# E yyLcpG
Y
while ( yyLch(NyyLba'eNyyLcurrentL'tateP F yyLcP \E
yyLcurrentL'tate #
X
yyLcurrentL'tate E (int# yyLdefNyyLcurrentL'tatePG
if ( yyLcurrentL'tate JE 1MB #
yyLc E yyLmetaN(un'igned int# yyLcPG
Y
yyLcurrentL'tate E yyLn>tNyyLba'eNyyLcurrentL'tateP F
(un'igned int# yyLcPG
FFyyLcpG
Y
while ( yyLba'eNyyLcurrentL'tateP \E 1SB #G
yyLfindLaction7
yyLact E yyLacceptNyyLcurrentL'tatePG
if ( yyLact EE 0 #
X KQ ha&e to bac( up QK
yyLcp E (yyLla'tLacceptingLcpo'#G
yyLcurrentL'tate E (yyLla'tLacceptingL'tate#G
yyLact E yyLacceptNyyLcurrentL'tatePG
Y
<<LD3L15=3%5L)C+*38G
doLaction7 KQ +hi' label i' u'ed only to acce'' 53= action'$ QK
'witch ( yyLact #
X KQ beginning of action 'witch QK
ca'e 07 KQ mu't bac( up QK
,"
KQ undo the effect' of <<LD3L15=3%5L)C+*38 QK
QyyLcp E (yyLholdLchar#G
yyLcp E (yyLla'tLacceptingLcpo'#G
yyLcurrentL'tate E (yyLla'tLacceptingL'tate#G
goto yyLfindLactionG
ca'e 17
<<L%9;5LS5+9P
Tline U Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e !7
<<L%9;5LS5+9P
Tline 1! Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e "7
<<L%9;5LS5+9P
Tline 1M Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e ,7
<<L%9;5LS5+9P
Tline !0 Heuo$lH
X
,,
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e B7
<<L%9;5LS5+9P
Tline !, Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e M7
<<L%9;5LS5+9P
Tline !U Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e S7
<<L%9;5LS5+9P
Tline "! Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e U7
<<L%9;5LS5+9P
Tline "M Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
,B
Y
<<L1%5)K
ca'e 7
<<L%9;5LS5+9P
Tline ,0 Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e 107
<<L%9;5LS5+9P
Tline ,, Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e 117
<<L%9;5LS5+9P
Tline ,U Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e 1!7
<<L%9;5LS5+9P
Tline B! Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
,M
ca'e 1"7
<<L%9;5LS5+9P
Tline BM Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e 1,7
<<L%9;5LS5+9P
Tline M0 Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e 1B7
<<L%9;5LS5+9P
Tline M, Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e 1M7
<<L%9;5LS5+9P
Tline MU Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e 1S7
<<L%9;5LS5+9P
,S
Tline S! Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e 1U7
<<L%9;5LS5+9P
Tline SM Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e 17
<<L%9;5LS5+9P
Tline U0 Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e !07
<<L%9;5LS5+9P
Tline U, Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e !17
<<L%9;5LS5+9P
Tline UU Heuo$lH
X
,U
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e !!7
<<L%9;5LS5+9P
Tline ! Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e !"7
<<L%9;5LS5+9P
Tline M Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e !,7
<<L%9;5LS5+9P
Tline 100 Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e !B7
<<L%9;5LS5+9P
Tline 10, Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
,
Y
<<L1%5)K
ca'e !M7
<<L%9;5LS5+9P
Tline 10U Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e !S7
<<L%9;5LS5+9P
Tline 11! Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e !U7
<<L%9;5LS5+9P
Tline 11M Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e !7
<<L%9;5LS5+9P
Tline 1!0 Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
B0
ca'e "07
<<L%9;5LS5+9P
Tline 1!, Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e "17
<<L%9;5LS5+9P
Tline 1!U Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e "!7
<<L%9;5LS5+9P
Tline 1"! Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e ""7
<<L%9;5LS5+9P
Tline 1"M Heuo$lH
X
printf(H%ecogni?ed K5<63%D7W'ZnH0yyte>t#G
(eyFFG
Y
<<L1%5)K
ca'e ",7
<<L%9;5LS5+9P
B1
Tline 1,0 Heuo$lH
X
(eyFFG
Y
<<L1%5)K
ca'e "B7
<<L%9;5LS5+9P
Tline 1," Heuo$lH
X
opFFG
Y
<<L1%5)K
ca'e "M7
<<L%9;5LS5+9P
Tline 1,M Heuo$lH
X
opFFG
Y
<<L1%5)K
ca'e "S7
<<L%9;5LS5+9P
Tline 1, Heuo$lH
G
<<L1%5)K
ca'e "U7
<<L%9;5LS5+9P
Tline 1B0 Heuo$lH
XidFFG
printf(H%ecogni?ed *D7W'ZnH0yyte>t#G
Y
<<L1%5)K
ca'e "7
<<L%9;5LS5+9P
Tline 1B, Heuo$lH
B!
5C:3G
<<L1%5)K
Tline 111 Hle>$yy$cH
ca'e <<LS+)+5L53=(*8*+*);#7
yyterminate(#G
ca'e <<L58DL3=L19==5%7
X
KQ )mount of te>t matched not including the 531 char$ QK
int yyLamountLofLmatchedLte>t E (int# (yyLcp @ (yyte>tLptr## @ 1G
KQ 9ndo the effect' of <<LD3L15=3%5L)C+*38$ QK
QyyLcp E (yyLholdLchar#G
<<L%5S+3%5L<<LM3%5L3==S5+
if ( <<LC9%%58+L19==5%L;/);95@JyyLbufferL'tatu' EE
<<L19==5%L856 #
X
KQ 6eDre 'canning a new file or input 'ource$ *tD'
Q po''ible that thi' happened becau'e the u'er
Q ju't pointed yyin at a new 'ource and called
Q yyle>(#$ *f 'o0 then we ha&e to a''ure
Q con'i'tency between <<LC9%%58+L19==5% and our
Q global'$ :ere i' the right place to do 'o0 becau'e
Q thi' i' the fir't action (other than po''ibly a
Q bac(@up# that will match for the new input 'ource$
QK
(yyLnLchar'# E <<LC9%%58+L19==5%L;/);95@
JyyLnLchar'G
<<LC9%%58+L19==5%L;/);95@JyyLinputLfile E yyinG
<<LC9%%58+L19==5%L;/);95@JyyLbufferL'tatu' E
<<L19==5%L83%M);G
Y
B"
KQ 8ote that here we te't for yyLcLbufLp HIEH to the po'ition
Q of the fir't 531 in the buffer0 'ince yyLcLbufLp will
Q already ha&e been incremented pa't the 89; character
Q ('ince all 'tate' ma(e tran'ition' on 531 to the
Q end@of@buffer 'tate#$ Contra't thi' with the te't
Q in input(#$
QK
if ( (yyLcLbufLp# IE 4<<LC9%%58+L19==5%L;/);95@
JyyLchLbufN(yyLnLchar'#P #
X KQ +hi' wa' really a 89;$ QK
yyL'tateLtype yyLne>tL'tateG
(yyLcLbufLp# E (yyte>tLptr# F yyLamountLofLmatchedLte>tG
yyLcurrentL'tate E yyLgetLpre&iou'L'tate( #G
KQ 3(ay0 weDre now po'itioned to ma(e the 89;
Q tran'ition$ 6e couldnDt ha&e
Q yyLgetLpre&iou'L'tate(# go ahead and do it
Q for u' becau'e it doe'nDt (now how to deal
Q with the po''ibility of jamming (and we donDt
Q want to build jamming into it becau'e then it
Q will run more 'lowly#$
QK
yyLne>tL'tate E yyLtryL89;Ltran'( yyLcurrentL'tate #G
yyLbp E (yyte>tLptr# F <<LM3%5L)DAG
if ( yyLne>tL'tate #
X
KQ Con'ume the 89;$ QK
yyLcp E FF(yyLcLbufLp#G
yyLcurrentL'tate E yyLne>tL'tateG
B,
goto yyLmatchG
Y
el'e
X
yyLcp E (yyLcLbufLp#G
goto yyLfindLactionG
Y
Y
el'e 'witch ( yyLgetLne>tLbuffer( # #
X
ca'e 531L)C+L58DL3=L=*;57
X
(yyLdidLbufferL'witchLonLeof# E 0G
if ( yywrap( # #
X
KQ 8ote7 becau'e weD&e ta(en care in
Q yyLgetLne>tLbuffer(# to ha&e 'et up
Q yyte>t0 we can now 'et up
Q yyLcLbufLp 'o that if 'ome total
Q ho'er (li(e fle> it'elf# want' to
Q call the 'canner after we return the
Q <<L89;;0 itDll 'till wor( @ another
Q <<L89;; will get returned$
QK
(yyLcLbufLp# E (yyte>tLptr# F
<<LM3%5L)DAG
yyLact E <<LS+)+5L53=(<<LS+)%+#G
goto doLactionG
Y
BB
el'e
X
if ( \ (yyLdidLbufferL'witchLonLeof# #
<<L856L=*;5G
Y
brea(G
Y
ca'e 531L)C+LC38+*895LSC)87
(yyLcLbufLp# E
(yyte>tLptr# F yyLamountLofLmatchedLte>tG
yyLcurrentL'tate E yyLgetLpre&iou'L'tate( #G
yyLcp E (yyLcLbufLp#G
yyLbp E (yyte>tLptr# F <<LM3%5L)DAG
goto yyLmatchG
ca'e 531L)C+L;)S+LM)+C:7
(yyLcLbufLp# E
4<<LC9%%58+L19==5%L;/);95@
JyyLchLbufN(yyLnLchar'#PG
yyLcurrentL'tate E yyLgetLpre&iou'L'tate( #G
yyLcp E (yyLcLbufLp#G
yyLbp E (yyte>tLptr# F <<LM3%5L)DAG
goto yyLfindLactionG
Y
brea(G
Y
default7
<<L=)+);L5%%3%(
BM
Hfatal fle> 'canner internal error@@no action foundH #G
Y KQ end of action 'witch QK
Y KQ end of 'canning one to(en QK
Y KQ end of yyle> QK
KQ yyLgetLne>tLbuffer @ try to read in a new buffer
Q
Q %eturn' a code repre'enting an action7
Q 531L)C+L;)S+LM)+C: @
Q 531L)C+LC38+*895LSC)8 @ continue 'canning from current po'ition
Q 531L)C+L58DL3=L=*;5 @ end of file
QK
'tatic int yyLgetLne>tLbuffer (&oid#
X
regi'ter char Qde't E <<LC9%%58+L19==5%L;/);95@JyyLchLbufG
regi'ter char Q'ource E (yyte>tLptr#G
regi'ter int numberLtoLmo&e0 iG
int retL&alG
if ( (yyLcLbufLp# J 4<<LC9%%58+L19==5%L;/);95@
JyyLchLbufN(yyLnLchar'# F 1P #
<<L=)+);L5%%3%(
Hfatal fle> 'canner internal error@@end of buffer mi''edH #G
if ( <<LC9%%58+L19==5%L;/);95@JyyLfillLbuffer EE 0 #
X KQ DonDt try to fill the buffer0 'o thi' i' an 53=$ QK
if ( (yyLcLbufLp# @ (yyte>tLptr# @ <<LM3%5L)DA EE 1 #
X
KQ 6e matched a 'ingle character0 the 5310 'o
Q treat thi' a' a final 53=$
QK
return 531L)C+L58DL3=L=*;5G
Y
BS
el'e
X
KQ 6e matched 'ome te>t prior to the 5310 fir't
Q proce'' it$
QK
return 531L)C+L;)S+LM)+C:G
Y
Y
KQ +ry to read more data$ QK
KQ =ir't mo&e la't char' to 'tart of buffer$ QK
numberLtoLmo&e E (int# ((yyLcLbufLp# @ (yyte>tLptr## @ 1G
for ( i E 0G i I numberLtoLmo&eG FFi #
Q(de'tFF# E Q('ourceFF#G
if ( <<LC9%%58+L19==5%L;/);95@JyyLbufferL'tatu' EE
<<L19==5%L53=LP58D*8. #
KQ donDt do the read0 itD' not guaranteed to return an 53=0
Q ju't force an 53=
QK
<<LC9%%58+L19==5%L;/);95@JyyLnLchar' E (yyLnLchar'# E
0G
el'e
X
int numLtoLread E
<<LC9%%58+L19==5%L;/);95@JyyLbufL'i?e @
numberLtoLmo&e @ 1G
while ( numLtoLread IE 0 #
X KQ 8ot enough room in the buffer @ grow it$ QK
BU
KQ ju't a 'horter name for the current buffer QK
<<L19==5%LS+)+5 b E <<LC9%%58+L19==5%G
int yyLcLbufLpLoff'et E
(int# ((yyLcLbufLp# @ b@JyyLchLbuf#G
if ( b@JyyLi'LourLbuffer #
X
int newL'i?e E b@JyyLbufL'i?e Q !G
if ( newL'i?e IE 0 #
b@JyyLbufL'i?e FE b@JyyLbufL'i?e K UG
el'e
b@JyyLbufL'i?e QE !G
b@JyyLchLbuf E (char Q#
KQ *nclude room in for ! 531 char'$ QK
yyrealloc((&oid Q# b@JyyLchLbuf0b@
JyyLbufL'i?e F ! #G
Y
el'e
KQ CanDt grow it0 we donDt own it$ QK
b@JyyLchLbuf E 0G
if ( \ b@JyyLchLbuf #
<<L=)+);L5%%3%(
Hfatal error @ 'canner input buffer o&erflowH #G
(yyLcLbufLp# E 4b@JyyLchLbufNyyLcLbufLpLoff'etPG
numLtoLread E <<LC9%%58+L19==5%L;/);95@
JyyLbufL'i?e @
numberLtoLmo&e @ 1G
B
Y
if ( numLtoLread J <<L%5)DL19=LS*O5 #
numLtoLread E <<L%5)DL19=LS*O5G
KQ %ead in more data$ QK
<<L*8P9+( (4<<LC9%%58+L19==5%L;/);95@
JyyLchLbufNnumberLtoLmo&eP#0
(yyLnLchar'#0 ('i?eLt# numLtoLread #G
<<LC9%%58+L19==5%L;/);95@JyyLnLchar' E (yyLnLchar'#G
Y
if ( (yyLnLchar'# EE 0 #
X
if ( numberLtoLmo&e EE <<LM3%5L)DA #
X
retL&al E 531L)C+L58DL3=L=*;5G
yyre'tart(yyin #G
Y
el'e
X
retL&al E 531L)C+L;)S+LM)+C:G
<<LC9%%58+L19==5%L;/);95@JyyLbufferL'tatu' E
<<L19==5%L53=LP58D*8.G
Y
Y
el'e
retL&al E 531L)C+LC38+*895LSC)8G
if ((yyL'i?eLt# ((yyLnLchar'# F numberLtoLmo&e# J
<<LC9%%58+L19==5%L;/);95@JyyLbufL'i?e# X
M0
KQ 5>tend the array by B0W0 plu' the number we really need$ QK
yyL'i?eLt newL'i?e E (yyLnLchar'# F numberLtoLmo&e F
((yyLnLchar'# JJ 1#G
<<LC9%%58+L19==5%L;/);95@JyyLchLbuf E (char Q#
yyrealloc((&oid Q# <<LC9%%58+L19==5%L;/);95@JyyLchLbuf0newL'i?e #G
if ( \ <<LC9%%58+L19==5%L;/);95@JyyLchLbuf #
<<L=)+);L5%%3%( Hout of dynamic memory in
yyLgetLne>tLbuffer(#H #G
Y
(yyLnLchar'# FE numberLtoLmo&eG
<<LC9%%58+L19==5%L;/);95@JyyLchLbufN(yyLnLchar'#P E
<<L58DL3=L19==5%LC:)%G
<<LC9%%58+L19==5%L;/);95@JyyLchLbufN(yyLnLchar'# F 1P E
<<L58DL3=L19==5%LC:)%G
(yyte>tLptr# E 4<<LC9%%58+L19==5%L;/);95@JyyLchLbufN0PG
return retL&alG
Y
KQ yyLgetLpre&iou'L'tate @ get the 'tate ju't before the 531 char wa' reached QK
'tatic yyL'tateLtype yyLgetLpre&iou'L'tate (&oid#
X
regi'ter yyL'tateLtype yyLcurrentL'tateG
regi'ter char QyyLcpG

yyLcurrentL'tate E (yyL'tart#G
for ( yyLcp E (yyte>tLptr# F <<LM3%5L)DAG yyLcp I (yyLcLbufLp#G F
FyyLcp #
X
M1
regi'ter <<LC:)% yyLc E (QyyLcp _
yyLecN<<LSCL+3L9*(QyyLcp#P 7 1#G
if ( yyLacceptNyyLcurrentL'tateP #
X
(yyLla'tLacceptingL'tate# E yyLcurrentL'tateG
(yyLla'tLacceptingLcpo'# E yyLcpG
Y
while ( yyLch(NyyLba'eNyyLcurrentL'tateP F yyLcP \E
yyLcurrentL'tate #
X
yyLcurrentL'tate E (int# yyLdefNyyLcurrentL'tatePG
if ( yyLcurrentL'tate JE 1MB #
yyLc E yyLmetaN(un'igned int# yyLcPG
Y
yyLcurrentL'tate E yyLn>tNyyLba'eNyyLcurrentL'tateP F (un'igned int#
yyLcPG
Y
return yyLcurrentL'tateG
Y
KQ yyLtryL89;Ltran' @ try to ma(e a tran'ition on the 89; character
Q
Q 'ynop'i'
Q ne>tL'tate E yyLtryL89;Ltran'( currentL'tate #G
QK
'tatic yyL'tateLtype yyLtryL89;Ltran' (yyL'tateLtype yyLcurrentL'tate #
X
regi'ter int yyLi'LjamG
regi'ter char QyyLcp E (yyLcLbufLp#G
regi'ter <<LC:)% yyLc E 1G
if ( yyLacceptNyyLcurrentL'tateP #
X
M!
(yyLla'tLacceptingL'tate# E yyLcurrentL'tateG
(yyLla'tLacceptingLcpo'# E yyLcpG
Y
while ( yyLch(NyyLba'eNyyLcurrentL'tateP F yyLcP \E yyLcurrentL'tate #
X
yyLcurrentL'tate E (int# yyLdefNyyLcurrentL'tatePG
if ( yyLcurrentL'tate JE 1MB #
yyLc E yyLmetaN(un'igned int# yyLcPG
Y
yyLcurrentL'tate E yyLn>tNyyLba'eNyyLcurrentL'tateP F (un'igned int# yyLcPG
yyLi'Ljam E (yyLcurrentL'tate EE 1M,#G
return yyLi'Ljam _ 0 7 yyLcurrentL'tateG
Y
'tatic &oid yyunput (int c0 regi'ter char Q yyLbp #
X
regi'ter char QyyLcpG

yyLcp E (yyLcLbufLp#G
KQ undo effect' of 'etting up yyte>t QK
QyyLcp E (yyLholdLchar#G
if ( yyLcp I <<LC9%%58+L19==5%L;/);95@JyyLchLbuf F ! #
X KQ need to 'hift thing' up to ma(e room QK
KQ F! for 531 char'$ QK
regi'ter int numberLtoLmo&e E (yyLnLchar'# F !G
regi'ter char Qde't E 4<<LC9%%58+L19==5%L;/);95@
JyyLchLbufN
<<LC9%%58+L19==5%L;/);95@
JyyLbufL'i?e F !PG
regi'ter char Q'ource E
M"
4<<LC9%%58+L19==5%L;/);95@
JyyLchLbufNnumberLtoLmo&ePG
while ( 'ource J <<LC9%%58+L19==5%L;/);95@JyyLchLbuf #
Q@@de't E Q@@'ourceG
yyLcp FE (int# (de't @ 'ource#G
yyLbp FE (int# (de't @ 'ource#G
<<LC9%%58+L19==5%L;/);95@JyyLnLchar' E
(yyLnLchar'# E <<LC9%%58+L19==5%L;/);95@
JyyLbufL'i?eG
if ( yyLcp I <<LC9%%58+L19==5%L;/);95@JyyLchLbuf F ! #
<<L=)+);L5%%3%( Hfle> 'canner pu'h@bac( o&erflowH #G
Y
Q@@yyLcp E (char# cG
(yyte>tLptr# E yyLbpG
(yyLholdLchar# E QyyLcpG
(yyLcLbufLp# E yyLcpG
Y
Tifndef <<L83L*8P9+
Tifdef LLcplu'plu'
'tatic int yyinput (&oid#
Tel'e
'tatic int input (&oid#
Tendif
X
int cG

Q(yyLcLbufLp# E (yyLholdLchar#G
M,
if ( Q(yyLcLbufLp# EE <<L58DL3=L19==5%LC:)% #
X
KQ yyLcLbufLp now point' to the character we want to return$
Q *f thi' occur' QbeforeQ the 531 character'0 then itD' a
Q &alid 89;G if not0 then weD&e hit the end of the buffer$
QK
if ( (yyLcLbufLp# I 4<<LC9%%58+L19==5%L;/);95@
JyyLchLbufN(yyLnLchar'#P #
KQ +hi' wa' really a 89;$ QK
Q(yyLcLbufLp# E DZ0DG
el'e
X KQ need more input QK
int off'et E (yyLcLbufLp# @ (yyte>tLptr#G
FF(yyLcLbufLp#G
'witch ( yyLgetLne>tLbuffer( # #
X
ca'e 531L)C+L;)S+LM)+C:7
KQ +hi' happen' becau'e yyLgLnLb(#
Q 'ee' that weD&e accumulated a
Q to(en and flag' that we need to
Q try matching the to(en before
Q proceeding$ 1ut for input(#0
Q thereD' no matching to con'ider$
Q So con&ert the 531L)C+L;)S+LM)+C:
Q to 531L)C+L58DL3=L=*;5$
QK
KQ %e'et buffer 'tatu'$ QK
yyre'tart(yyin #G
KQ=);;+:%39.:QK
MB
ca'e 531L)C+L58DL3=L=*;57
X
if ( yywrap( # #
return 53=G
if ( \ (yyLdidLbufferL'witchLonLeof# #
<<L856L=*;5G
Tifdef LLcplu'plu'
return yyinput(#G
Tel'e
return input(#G
Tendif
Y
ca'e 531L)C+LC38+*895LSC)87
(yyLcLbufLp# E (yyte>tLptr# F off'etG
brea(G
Y
Y
Y
c E Q(un'igned char Q# (yyLcLbufLp#GKQ ca't for U@bit charD' QK
Q(yyLcLbufLp# E DZ0DG KQ pre'er&e yyte>t QK
(yyLholdLchar# E QFF(yyLcLbufLp#G
return cG
Y
Tendif KQ ifndef <<L83L*8P9+ QK
KQQ *mmediately 'witch to a different input 'tream$
Q `param inputLfile ) readable 'tream$
Q
Q `note +hi' function doe' not re'et the 'tart condition to `c *8*+*); $
MM
QK
&oid yyre'tart (=*;5 Q inputLfile #
X

if ( \ <<LC9%%58+L19==5% #X
yyen'ureLbufferL'tac( (#G
<<LC9%%58+L19==5%L;/);95 E
yyLcreateLbuffer(yyin0<<L19=LS*O5 #G
Y
yyLinitLbuffer(<<LC9%%58+L19==5%0inputLfile #G
yyLloadLbufferL'tate( #G
Y
KQQ Switch to a different input buffer$
Q `param newLbuffer +he new input buffer$
Q
QK
&oid yyL'witchLtoLbuffer (<<L19==5%LS+)+5 newLbuffer #
X

KQ +3D3$ 6e 'hould be able to replace thi' entire function body
Q with
Q yypopLbufferL'tate(#G
Q yypu'hLbufferL'tate(newLbuffer#G
QK
yyen'ureLbufferL'tac( (#G
if ( <<LC9%%58+L19==5% EE newLbuffer #
returnG
if ( <<LC9%%58+L19==5% #
X
KQ =lu'h out information for old buffer$ QK
Q(yyLcLbufLp# E (yyLholdLchar#G
MS
<<LC9%%58+L19==5%L;/);95@JyyLbufLpo' E (yyLcLbufLp#G
<<LC9%%58+L19==5%L;/);95@JyyLnLchar' E (yyLnLchar'#G
Y
<<LC9%%58+L19==5%L;/);95 E newLbufferG
yyLloadLbufferL'tate( #G
KQ 6e donDt actually (now whether we did thi' 'witch during
Q 53= (yywrap(## proce''ing0 but the only time thi' flag
Q i' loo(ed at i' after yywrap(# i' called0 'o itD' 'afe
Q to go ahead and alway' 'et it$
QK
(yyLdidLbufferL'witchLonLeof# E 1G
Y
'tatic &oid yyLloadLbufferL'tate (&oid#
X
(yyLnLchar'# E <<LC9%%58+L19==5%L;/);95@JyyLnLchar'G
(yyte>tLptr# E (yyLcLbufLp# E <<LC9%%58+L19==5%L;/);95@
JyyLbufLpo'G
yyin E <<LC9%%58+L19==5%L;/);95@JyyLinputLfileG
(yyLholdLchar# E Q(yyLcLbufLp#G
Y
KQQ )llocate and initiali?e an input buffer 'tate$
Q `param file ) readable 'tream$
Q `param 'i?e +he character buffer 'i?e in byte'$ 6hen in doubt0 u'e `c
<<L19=LS*O5$
Q
Q `return the allocated buffer 'tate$
QK
<<L19==5%LS+)+5 yyLcreateLbuffer (=*;5 Q file0 int 'i?e #
X
<<L19==5%LS+)+5 bG
MU

b E (<<L19==5%LS+)+5# yyalloc('i?eof( 'truct yyLbufferL'tate # #G
if ( \ b #
<<L=)+);L5%%3%( Hout of dynamic memory in
yyLcreateLbuffer(#H #G
b@JyyLbufL'i?e E 'i?eG
KQ yyLchLbuf ha' to be ! character' longer than the 'i?e gi&en becau'e
Q we need to put in ! end@of@buffer character'$
QK
b@JyyLchLbuf E (char Q# yyalloc(b@JyyLbufL'i?e F ! #G
if ( \ b@JyyLchLbuf #
<<L=)+);L5%%3%( Hout of dynamic memory in
yyLcreateLbuffer(#H #G
b@JyyLi'LourLbuffer E 1G
yyLinitLbuffer(b0file #G
return bG
Y
KQQ De'troy the buffer$
Q `param b a buffer created with yyLcreateLbuffer(#
Q
QK
&oid yyLdeleteLbuffer (<<L19==5%LS+)+5 b #
X

if ( \ b #
returnG
if ( b EE <<LC9%%58+L19==5% # KQ 8ot 'ure if we 'hould pop here$ QK
M
<<LC9%%58+L19==5%L;/);95 E (<<L19==5%LS+)+5# 0G
if ( b@JyyLi'LourLbuffer #
yyfree((&oid Q# b@JyyLchLbuf #G
yyfree((&oid Q# b #G
Y
Tifndef LLcplu'plu'
e>tern int i'atty (int #G
Tendif KQ LLcplu'plu' QK

KQ *nitiali?e' or reinitiali?e' a buffer$
Q +hi' function i' 'ometime' called more than once on the 'ame buffer0
Q 'uch a' during a yyre'tart(# or at 53=$
QK
'tatic &oid yyLinitLbuffer (<<L19==5%LS+)+5 b0 =*;5 Q file #
X
int oerrno E errnoG

yyLflu'hLbuffer(b #G
b@JyyLinputLfile E fileG
b@JyyLfillLbuffer E 1G
KQ *f b i' the current buffer0 then yyLinitLbuffer wa' LprobablyL
Q called from yyre'tart(# or through yyLgetLne>tLbuffer$
Q *n that ca'e0 we donDt want to re'et the lineno or column$
QK
if (b \E <<LC9%%58+L19==5%#X
b@JyyLb'Llineno E 1G
b@JyyLb'Lcolumn E 0G
Y
S0
b@JyyLi'Linteracti&e E file _ (i'atty( fileno(file# # J 0# 7 0G

errno E oerrnoG
Y
KQQ Di'card all buffered character'$ 3n the ne>t 'can0 <<L*8P9+ will be called$
Q `param b the buffer 'tate to be flu'hed0 u'ually `c <<LC9%%58+L19==5%$
Q
QK
&oid yyLflu'hLbuffer (<<L19==5%LS+)+5 b #
X
if ( \ b #
returnG
b@JyyLnLchar' E 0G
KQ 6e alway' need two end@of@buffer character'$ +he fir't cau'e'
Q a tran'ition to the end@of@buffer 'tate$ +he 'econd cau'e'
Q a jam in that 'tate$
QK
b@JyyLchLbufN0P E <<L58DL3=L19==5%LC:)%G
b@JyyLchLbufN1P E <<L58DL3=L19==5%LC:)%G
b@JyyLbufLpo' E 4b@JyyLchLbufN0PG
b@JyyLatLbol E 1G
b@JyyLbufferL'tatu' E <<L19==5%L856G
if ( b EE <<LC9%%58+L19==5% #
yyLloadLbufferL'tate( #G
Y
KQQ Pu'he' the new 'tate onto the 'tac($ +he new 'tate become'
S1
Q the current 'tate$ +hi' function will allocate the 'tac(
Q if nece''ary$
Q `param newLbuffer +he new 'tate$
Q
QK
&oid yypu'hLbufferL'tate (<<L19==5%LS+)+5 newLbuffer #
X
if (newLbuffer EE 89;;#
returnG
yyen'ureLbufferL'tac((#G
KQ +hi' bloc( i' copied from yyL'witchLtoLbuffer$ QK
if ( <<LC9%%58+L19==5% #
X
KQ =lu'h out information for old buffer$ QK
Q(yyLcLbufLp# E (yyLholdLchar#G
<<LC9%%58+L19==5%L;/);95@JyyLbufLpo' E (yyLcLbufLp#G
<<LC9%%58+L19==5%L;/);95@JyyLnLchar' E (yyLnLchar'#G
Y
KQ 3nly pu'h if top e>i't'$ 3therwi'e0 replace top$ QK
if (<<LC9%%58+L19==5%#
(yyLbufferL'tac(Ltop#FFG
<<LC9%%58+L19==5%L;/);95 E newLbufferG
KQ copied from yyL'witchLtoLbuffer$ QK
yyLloadLbufferL'tate( #G
(yyLdidLbufferL'witchLonLeof# E 1G
Y
KQQ %emo&e' and delete' the top of the 'tac(0 if pre'ent$
Q +he ne>t element become' the new top$
Q
S!
QK
&oid yypopLbufferL'tate (&oid#
X
if (\<<LC9%%58+L19==5%#
returnG
yyLdeleteLbuffer(<<LC9%%58+L19==5% #G
<<LC9%%58+L19==5%L;/);95 E 89;;G
if ((yyLbufferL'tac(Ltop# J 0#
@@(yyLbufferL'tac(Ltop#G
if (<<LC9%%58+L19==5%# X
yyLloadLbufferL'tate( #G
(yyLdidLbufferL'witchLonLeof# E 1G
Y
Y
KQ )llocate' the 'tac( if it doe' not e>i't$
Q .uarantee' 'pace for at lea't one pu'h$
QK
'tatic &oid yyen'ureLbufferL'tac( (&oid#
X
int numLtoLallocG

if (\(yyLbufferL'tac(## X
KQ =ir't allocation i' ju't for ! element'0 'ince we donDt (now if thi'
Q 'canner will e&en need a 'tac($ 6e u'e ! in'tead of 1 to a&oid an
Q immediate realloc on the ne>t call$
QK
numLtoLalloc E 1G
(yyLbufferL'tac(# E ('truct yyLbufferL'tateQQ#yyalloc
(numLtoLalloc Q
'i?eof('truct yyLbufferL'tateQ#
S"
#G
if ( \ (yyLbufferL'tac(# #
<<L=)+);L5%%3%( Hout of dynamic memory in
yyen'ureLbufferL'tac((#H #G

mem'et((yyLbufferL'tac(#0 00 numLtoLalloc Q 'i?eof('truct
yyLbufferL'tateQ##G
(yyLbufferL'tac(Lma># E numLtoLallocG
(yyLbufferL'tac(Ltop# E 0G
returnG
Y
if ((yyLbufferL'tac(Ltop# JE ((yyLbufferL'tac(Lma>## @ 1#X
KQ *ncrea'e the buffer to prepare for a po''ible pu'h$ QK
int growL'i?e E U KQ arbitrary grow 'i?e QKG
numLtoLalloc E (yyLbufferL'tac(Lma># F growL'i?eG
(yyLbufferL'tac(# E ('truct yyLbufferL'tateQQ#yyrealloc
((yyLbufferL'tac(#0
numLtoLalloc Q
'i?eof('truct yyLbufferL'tateQ#
#G
if ( \ (yyLbufferL'tac(# #
<<L=)+);L5%%3%( Hout of dynamic memory in
yyen'ureLbufferL'tac((#H #G
KQ ?ero only the new 'lot'$QK
mem'et((yyLbufferL'tac(# F (yyLbufferL'tac(Lma>#0 00 growL'i?e Q
'i?eof('truct yyLbufferL'tateQ##G
(yyLbufferL'tac(Lma># E numLtoLallocG
Y
Y
S,
KQQ Setup the input buffer 'tate to 'can directly from a u'er@'pecified character buffer$
Q `param ba'e the character buffer
Q `param 'i?e the 'i?e in byte' of the character buffer
Q
Q `return the newly allocated buffer 'tate object$
QK
<<L19==5%LS+)+5 yyL'canLbuffer (char Q ba'e0 yyL'i?eLt 'i?e #
X
<<L19==5%LS+)+5 bG

if ( 'i?e I ! [[
ba'eN'i?e@!P \E <<L58DL3=L19==5%LC:)% [[
ba'eN'i?e@1P \E <<L58DL3=L19==5%LC:)% #
KQ +hey forgot to lea&e room for the 531D'$ QK
return 0G
b E (<<L19==5%LS+)+5# yyalloc('i?eof( 'truct yyLbufferL'tate # #G
if ( \ b #
<<L=)+);L5%%3%( Hout of dynamic memory in
yyL'canLbuffer(#H #G
b@JyyLbufL'i?e E 'i?e @ !G KQ H@ !H to ta(e care of 531D' QK
b@JyyLbufLpo' E b@JyyLchLbuf E ba'eG
b@JyyLi'LourLbuffer E 0G
b@JyyLinputLfile E 0G
b@JyyLnLchar' E b@JyyLbufL'i?eG
b@JyyLi'Linteracti&e E 0G
b@JyyLatLbol E 1G
b@JyyLfillLbuffer E 0G
b@JyyLbufferL'tatu' E <<L19==5%L856G
yyL'witchLtoLbuffer(b #G
SB
return bG
Y
KQQ Setup the input buffer 'tate to 'can a 'tring$ +he ne>t call to yyle>(# will
Q 'can from a `e copy of `a 'tr$
Q `param yy'tr a 89;@terminated 'tring to 'can
Q
Q `return the newly allocated buffer 'tate object$
Q `note *f you want to 'can byte' that may contain 89; &alue'0 then u'e
Q yyL'canLbyte'(# in'tead$
QK
<<L19==5%LS+)+5 yyL'canL'tring (yycon't char Q yy'tr #
X

return yyL'canLbyte'(yy'tr0'trlen(yy'tr# #G
Y
KQQ Setup the input buffer 'tate to 'can the gi&en byte'$ +he ne>t call to yyle>(# will
Q 'can from a `e copy of `a byte'$
Q `param byte' the byte buffer to 'can
Q `param len the number of byte' in the buffer pointed to by `a byte'$
Q
Q `return the newly allocated buffer 'tate object$
QK
<<L19==5%LS+)+5 yyL'canLbyte' (yycon't char Q yybyte'0 int Lyybyte'Llen #
X
<<L19==5%LS+)+5 bG
char QbufG
yyL'i?eLt nG
int iG

KQ .et memory for full buffer0 including 'pace for trailing 531D'$ QK
n E Lyybyte'Llen F !G
buf E (char Q# yyalloc(n #G
SM
if ( \ buf #
<<L=)+);L5%%3%( Hout of dynamic memory in
yyL'canLbyte'(#H #G
for ( i E 0G i I Lyybyte'LlenG FFi #
bufNiP E yybyte'NiPG
bufNLyybyte'LlenP E bufNLyybyte'LlenF1P E <<L58DL3=L19==5%LC:)%G
b E yyL'canLbuffer(buf0n #G
if ( \ b #
<<L=)+);L5%%3%( Hbad buffer in yyL'canLbyte'(#H #G
KQ *tD' o(ay to grow etc$ thi' buffer0 and we 'hould throw it
Q away when weDre done$
QK
b@JyyLi'LourLbuffer E 1G
return bG
Y
Tifndef <<L5]*+L=)*;9%5
Tdefine <<L5]*+L=)*;9%5 !
Tendif
'tatic &oid yyLfatalLerror (yycon't charQ m'g #
X
(&oid# fprintf( 'tderr0 HW'ZnH0 m'g #G
e>it( <<L5]*+L=)*;9%5 #G
Y
KQ %edefine yyle''(# 'o it wor(' in 'ection " code$ QK
Tundef yyle''
SS
Tdefine yyle''(n# Z
do Z
X Z
KQ 9ndo effect' of 'etting up yyte>t$ QK Z
int yyle''LmacroLarg E (n#G Z
<<L;5SSL;*8583(yyle''LmacroLarg#GZ
yyte>tNyylengP E (yyLholdLchar#G Z
(yyLcLbufLp# E yyte>t F yyle''LmacroLargG Z
(yyLholdLchar# E Q(yyLcLbufLp#G Z
Q(yyLcLbufLp# E DZ0DG Z
yyleng E yyle''LmacroLargG Z
Y Z
while ( 0 #
KQ )cce''or method' (getK'et function'# to 'truct member'$ QK
KQQ .et the current line number$
Q
QK
int yygetLlineno (&oid#
X

return yylinenoG
Y
KQQ .et the input 'tream$
Q
QK
=*;5 QyygetLin (&oid#
X
return yyinG
Y
KQQ .et the output 'tream$
SU
Q
QK
=*;5 QyygetLout (&oid#
X
return yyoutG
Y
KQQ .et the length of the current to(en$
Q
QK
int yygetLleng (&oid#
X
return yylengG
Y
KQQ .et the current to(en$
Q
QK
char QyygetLte>t (&oid#
X
return yyte>tG
Y
KQQ Set the current line number$
Q `param lineLnumber
Q
QK
&oid yy'etLlineno (int lineLnumber #
X

yylineno E lineLnumberG
Y
S
KQQ Set the input 'tream$ +hi' doe' not di'card the current
Q input buffer$
Q `param inL'tr ) readable 'tream$
Q
Q `'ee yyL'witchLtoLbuffer
QK
&oid yy'etLin (=*;5 Q inL'tr #
X
yyin E inL'tr G
Y
&oid yy'etLout (=*;5 Q outL'tr #
X
yyout E outL'tr G
Y
int yygetLdebug (&oid#
X
return yyLfle>LdebugG
Y
&oid yy'etLdebug (int bdebug #
X
yyLfle>Ldebug E bdebug G
Y
'tatic int yyLinitLglobal' (&oid#
X
KQ *nitiali?ation i' the 'ame a' for the non@reentrant 'canner$
Q +hi' function i' called from yyle>Lde'troy(#0 'o donDt allocate here$
QK
(yyLbufferL'tac(# E 0G
(yyLbufferL'tac(Ltop# E 0G
U0
(yyLbufferL'tac(Lma># E 0G
(yyLcLbufLp# E (char Q# 0G
(yyLinit# E 0G
(yyL'tart# E 0G
KQ Defined in main$c QK
Tifdef <<LS+D*8*+
yyin E 'tdinG
yyout E 'tdoutG
Tel'e
yyin E (=*;5 Q# 0G
yyout E (=*;5 Q# 0G
Tendif
KQ =or future reference7 Set errno on error0 'ince we are called by
Q yyle>Linit(#
QK
return 0G
Y
KQ yyle>Lde'troy i' for both reentrant and non@reentrant 'canner'$ QK
int yyle>Lde'troy (&oid#
X

KQ Pop the buffer 'tac(0 de'troying each element$ QK
while(<<LC9%%58+L19==5%#X
yyLdeleteLbuffer(<<LC9%%58+L19==5% #G
<<LC9%%58+L19==5%L;/);95 E 89;;G
yypopLbufferL'tate(#G
Y
KQ De'troy the 'tac( it'elf$ QK
yyfree((yyLbufferL'tac(# #G
(yyLbufferL'tac(# E 89;;G
U1
KQ %e'et the global'$ +hi' i' important in a non@reentrant 'canner 'o the ne>t time
Q yyle>(# i' called0 initiali?ation will occur$ QK
yyLinitLglobal'( #G
return 0G
Y
KQ
Q *nternal utility routine'$
QK
Tifndef yyte>tLptr
'tatic &oid yyLfle>L'trncpy (charQ '10 yycon't char Q '!0 int n #
X
regi'ter int iG
for ( i E 0G i I nG FFi #
'1NiP E '!NiPG
Y
Tendif
Tifdef <<L855DLS+%;58
'tatic int yyLfle>L'trlen (yycon't char Q ' #
X
regi'ter int nG
for ( n E 0G 'NnPG FFn #
G
return nG
Y
Tendif
&oid Qyyalloc (yyL'i?eLt 'i?e #
X
U!
return (&oid Q# malloc( 'i?e #G
Y
&oid Qyyrealloc (&oid Q ptr0 yyL'i?eLt 'i?e #
X
KQ +he ca't to (char Q# in the following accommodate' both
Q implementation' that u'e charQ generic pointer'0 and tho'e
Q that u'e &oidQ generic pointer'$ *t wor(' with the latter
Q becau'e both )8S* C and CFF allow ca'tle'' a''ignment from
Q any pointer type to &oidQ0 and deal with argument con&er'ion'
Q a' though doing an a''ignment$
QK
return (&oid Q# realloc( (char Q# ptr0 'i?e #G
Y
&oid yyfree (&oid Q ptr #
X
free( (char Q# ptr #G KQ 'ee yyrealloc(# for (char Q# ca't QK
Y
Tdefine <<+)1;5SL8)M5 Hyytable'H
Tline 1B, Heuo$lH
main(#
X
yyle>(#G
printf(Hnumber of *DD'EWdZt0K5<63%DSEWdZt03P5%)+3%SEWdZtH0id0(ey0op#G
Y
U"
Data file:
if aFb then >FyG
el'e pKqG
while aIEb do
>EyF?G
How to compile:
ale> IfilenameJ
acc le>$yy$c bll
a$Ka$out I data fileJ
Output:
%ecogni?ed K5<63%D7if
%ecogni?ed *D7a
%ecogni?ed *D7b
%ecogni?ed *D7>
%ecogni?ed *D7y
%ecogni?ed K5<63%D7el'e
%ecogni?ed *D7p
%ecogni?ed *D7q
%ecogni?ed K5<63%D7while
%ecogni?ed *D7a
%ecogni?ed *D7b
%ecogni?ed K5<63%D7do

%ecogni?ed *D7>
%ecogni?ed *D7y
%ecogni?ed *D7?
number of *DD'E11 0K5<63%DSEB 03P5%)+3%SEM
U,
PARSER:
Parsing (syntactic analysis) i' the proce'' of analy?ing a 'equence of
to(en' to determine their grammatical 'tructure with re'pect to a gi&en
(more or le''# formal grammar$ Par'er obtain' a 'tring of to(en' from the
le>ical analy?er and &erifie' that it can be generated by the language
for the 'ource program$ +he par'er 'hould report any 'ynta> error' in an
intelligible fa'hion$
The role of the parser:
Par'er7
c perform' conte>t@free 'ynta> analy'i'
c guide' conte>t@'en'iti&e analy'i'
c con'truct' an intermediate repre'entation
c produce' meaningful error me''age'
c attempt' error correction
Yacc Specification:
<acc (yet another compiler compiler# i' a par'er generator0 which i' a
program that ta(e' a' it' input a 'pecification of 'ynta> of the
programming language0 and produce' a' it' output a par'e procedure for
that language who'e name i' yypar'e(#$
+he notation u'ed for preparing thi' 'pecification i' a grammer(C=.#$
*nput to yacc i' a 'pecification file u'ually with $y 'uffi>0 containing the
rule' of grammar 'pecifying the 'tructure of language to be implemented$
+he output i' C 'ource code for par'er0 u'ually in a file y$tab$c or ytab$c$
definition ]

rules ]

UB
programs ]
+he definition 'ection contain' information about to(en'0 data type'0 and
grammar rule'$ *t al'o include' any C code that mu't go directly into the
output file at it' beginning$
Parser Program:
Wto(en 89M
W'tart S
WW
S75 Xprintf(Hthe &alue of e>pre''ion i' WdZnH0a1#GY
G
575DFD+ XaaEa1Fa"GY
G
57+ XaaEa1GY
G
+7+DQD= XaaEa1Qa"GY
G
UM
+7= XaaEa1GY
G
=789M XaaEa1GY
G
WW
TincludeHle>$yy$cH
main(#
X
return(yypar'e(##G
Y
lex.yy.c file of parser:
D*.*+ N0@P
WW
XD*.*+YF Xyyl&alEatoi(yyte>t#G
return(89M#G
Y
NZtPG
return(yyte>tN0P#G
US
y.tab.c file:
Tifndef lint
'tatic con't char yy'cc'idNP E H`(T#yaccpar 1$ (1er(eley# 0!K!1K"HG
Tendif
Tinclude I'tdlib$hJ
Tinclude I'tring$hJ
Tdefine <<1<)CC 1
Tdefine <<M)A3% 1
Tdefine <<M*83%
Tdefine <<P)+C: !00S0B0
Tdefine <<5MP+< (@1#
Tdefine yyclearin (yychar E <<5MP+<#
Tdefine yyerro( (yyerrflag E 0#
Tdefine <<%5C3/5%*8. (yyerrflag \E 0#
e>tern int yypar'e(&oid#G
'tatic int yygrow'tac((&oid#G
Tdefine <<P%5=*] HyyH
Tdefine 89M !BS
Tdefine <<5%%C3D5 !BM
'hort yylh'NP E X @10
00 10 10 !0 !0 "0
YG
'hort yylenNP E X !0
10 "0 10 "0 10 10
YG
'hort yydefredNP E X 00
M0 00 00 00 B0 00 00 00 ,0
YG
'hort yydgotoNP E X !0
UU
"0 ,0 B0
YG
'hort yy'inde>NP E X @!BS0
00 00 @,00 @"U0 00 @!BS0 @!BS0 @"U0 00
YG
'hort yyrinde>NP E X 00
00 00 B0 10 00 00 00 !0 00
YG
'hort yyginde>NP E X 00
00 "0 @10
YG
Tdefine <<+)1;5S*O5 ,B
'hort yytableNP E X 10
"0 !0 M0 S0 10 0 00 00 U0 00
00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00
00 00 00 "0 !0
YG
'hort yychec(NP E X !BS0
00 00 ,"0 ,!0 00 S0 @10 @10 M0 @10
@10 @10 @10 @10 @10 @10 @10 @10 @10 @10
@10 @10 @10 @10 @10 @10 @10 @10 @10 @10
@10 @10 @10 @10 @10 @10 @10 @10 @10 @10
@10 @10 @10 ,"0 ,"0
YG
Tdefine <<=*8); !
Tifndef <<D519.
Tdefine <<D519. 0
Tendif
Tdefine <<M)]+3K58 !BS
Tif <<D519.
char QyynameNP E X
Hend@of@fileH0000000000000000000000000000000000000000000000000000000000000000000
U
0000000000000000HDQDH0HDFDH00000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000H89MH0
YG
char QyyruleNP E X
Haaccept 7 SH0
HS 7 5H0
H5 7 5 DFD +H0
H5 7 +H0
H+ 7 + DQD =H0
H+ 7 =H0
H= 7 89MH0
YG
Tendif
Tifndef <<S+<P5
typedef int <<S+<P5G
Tendif
Tif <<D519.
Tinclude I'tdio$hJ
Tendif
KQ define the initial 'tac(@'i?e' QK
Tifdef <<S+)CKS*O5
Tundef <<M)]D5P+:
Tdefine <<M)]D5P+: <<S+)CKS*O5
Tel'e
Tifdef <<M)]D5P+:
Tdefine <<S+)CKS*O5 <<M)]D5P+:
Tel'e
Tdefine <<S+)CKS*O5 B00
Tdefine <<M)]D5P+: B00
0
Tendif
Tendif
Tdefine <<*8*+S+)CKS*O5 B00
int yydebugG
int yynerr'G
int yyerrflagG
int yycharG
'hort Qyy''pG
<<S+<P5 Qyy&'pG
<<S+<P5 yy&alG
<<S+<P5 yyl&alG
KQ &ariable' for the par'er 'tac( QK
'tatic 'hort Qyy''G
'tatic 'hort Qyy''limG
'tatic <<S+<P5 Qyy&'G
'tatic int yy'tac('i?eG
Tline 1S Hte't$yH
TincludeHle>$yy$cH
main(#
X
return(yypar'e(##G
Y
Tline 1! Hy$tab$cH
KQ allocate initial 'tac( or double 'tac( 'i?e0 up to <<M)]D5P+: QK
'tatic int yygrow'tac((&oid#
X
int new'i?e0 iG
'hort Qnew''G
<<S+<P5 Qnew&'G
1
if ((new'i?e E yy'tac('i?e# EE 0#
new'i?e E <<*8*+S+)CKS*O5G
el'e if (new'i?e JE <<M)]D5P+:#
return @1G
el'e if ((new'i?e QE !# J <<M)]D5P+:#
new'i?e E <<M)]D5P+:G
i E yy''p @ yy''G
new'' E (yy'' \E 0#
_ ('hort Q#realloc(yy''0 new'i?e Q 'i?eof(Qnew''##
7 ('hort Q#malloc(new'i?e Q 'i?eof(Qnew''##G
if (new'' EE 0#
return @1G
yy'' E new''G
yy''p E new'' F iG
new&' E (yy&' \E 0#
_ (<<S+<P5 Q#realloc(yy&'0 new'i?e Q 'i?eof(Qnew&'##
7 (<<S+<P5 Q#malloc(new'i?e Q 'i?eof(Qnew&'##G
if (new&' EE 0#
return @1G
yy&' E new&'G
yy&'p E new&' F iG
yy'tac('i?e E new'i?eG
yy''lim E yy'' F new'i?e @ 1G
return 0G
Y
Tdefine <<)13%+ goto yyabort
Tdefine <<%5A5C+ goto yyabort
Tdefine <<)CC5P+ goto yyaccept
Tdefine <<5%%3% goto yyerrlab
int
!
yypar'e(&oid#
X
regi'ter int yym0 yyn0 yy'tateG
Tif <<D519.
regi'ter con't char Qyy'G
if ((yy' E geten&(H<<D519.H## \E 0#
X
yyn E Qyy'G
if (yyn JE D0D 44 yyn IE DD#
yydebug E yyn @ D0DG
Y
Tendif
yynerr' E 0G
yyerrflag E 0G
yychar E <<5MP+<G
if (yy'' EE 89;; 44 yygrow'tac((## goto yyo&erflowG
yy''p E yy''G
yy&'p E yy&'G
Qyy''p E yy'tate E 0G
yyloop7
if ((yyn E yydefredNyy'tateP# \E 0# goto yyreduceG
if (yychar I 0#
X
if ((yychar E yyle>(## I 0# yychar E 0G
Tif <<D519.
if (yydebug#
X
yy' E 0G
if (yychar IE <<M)]+3K58# yy' E yynameNyycharPG
if (\yy'# yy' E Hillegal@'ymbolHG
"
printf(HW'debug7 'tate Wd0 reading Wd (W'#ZnH0
<<P%5=*]0 yy'tate0 yychar0 yy'#G
Y
Tendif
Y
if ((yyn E yy'inde>Nyy'tateP# 44 (yyn FE yychar# JE 0 44
yyn IE <<+)1;5S*O5 44 yychec(NyynP EE yychar#
X
Tif <<D519.
if (yydebug#
printf(HW'debug7 'tate Wd0 'hifting to 'tate WdZnH0
<<P%5=*]0 yy'tate0 yytableNyynP#G
Tendif
if (yy''p JE yy''lim 44 yygrow'tac((##
X
goto yyo&erflowG
Y
QFFyy''p E yy'tate E yytableNyynPG
QFFyy&'p E yyl&alG
yychar E <<5MP+<G
if (yyerrflag J 0# @@yyerrflagG
goto yyloopG
Y
if ((yyn E yyrinde>Nyy'tateP# 44 (yyn FE yychar# JE 0 44
yyn IE <<+)1;5S*O5 44 yychec(NyynP EE yychar#
X
yyn E yytableNyynPG
goto yyreduceG
Y
if (yyerrflag# goto yyinreco&eryG
yyerror(H'ynta> errorH#G
Tifdef lint
,
goto yyerrlabG
Tendif
yyerrlab7
FFyynerr'G
yyinreco&ery7
if (yyerrflag I "#
X
yyerrflag E "G
for (GG#
X
if ((yyn E yy'inde>NQyy''pP# 44 (yyn FE <<5%%C3D5# JE 0 44
yyn IE <<+)1;5S*O5 44 yychec(NyynP EE <<5%%C3D5#
X
Tif <<D519.
if (yydebug#
printf(HW'debug7 'tate Wd0 error reco&ery 'hiftingZ
to 'tate WdZnH0 <<P%5=*]0 Qyy''p0 yytableNyynP#G
Tendif
if (yy''p JE yy''lim 44 yygrow'tac((##
X
goto yyo&erflowG
Y
QFFyy''p E yy'tate E yytableNyynPG
QFFyy&'p E yyl&alG
goto yyloopG
Y
el'e
X
Tif <<D519.
if (yydebug#
printf(HW'debug7 error reco&ery di'carding 'tate WdZnH0
<<P%5=*]0 Qyy''p#G
B
Tendif
if (yy''p IE yy''# goto yyabortG
@@yy''pG
@@yy&'pG
Y
Y
Y
el'e
X
if (yychar EE 0# goto yyabortG
Tif <<D519.
if (yydebug#
X
yy' E 0G
if (yychar IE <<M)]+3K58# yy' E yynameNyycharPG
if (\yy'# yy' E Hillegal@'ymbolHG
printf(HW'debug7 'tate Wd0 error reco&ery di'card' to(en Wd (W'#ZnH0
<<P%5=*]0 yy'tate0 yychar0 yy'#G
Y
Tendif
yychar E <<5MP+<G
goto yyloopG
Y
yyreduce7
Tif <<D519.
if (yydebug#
printf(HW'debug7 'tate Wd0 reducing by rule Wd (W'#ZnH0
<<P%5=*]0 yy'tate0 yyn0 yyruleNyynP#G
Tendif
yym E yylenNyynPG
if (yym#
yy&al E yy&'pN1@yymPG
el'e
M
mem'et(4yy&al0 00 'i?eof yy&al#G
'witch (yyn#
X
ca'e 17
Tline , Hte't$yH
Xprintf(Hthe &alue of e>pre''ion i' WdZnH0yy&'pN0P#GY
brea(G
ca'e !7
Tline M Hte't$yH
Xyy&alEyy&'pN@!PFyy&'pN0PGY
brea(G
ca'e "7
Tline U Hte't$yH
Xyy&alEyy&'pN0PGY
brea(G
ca'e ,7
Tline 10 Hte't$yH
Xyy&alEyy&'pN@!PQyy&'pN0PGY
brea(G
ca'e B7
Tline 1! Hte't$yH
Xyy&alEyy&'pN0PGY
brea(G
ca'e M7
Tline 1, Hte't$yH
Xyy&alEyy&'pN0PGY
brea(G
Tline "", Hy$tab$cH
Y
yy''p @E yymG
yy'tate E Qyy''pG
yy&'p @E yymG
yym E yylh'NyynPG
if (yy'tate EE 0 44 yym EE 0#
S
X
Tif <<D519.
if (yydebug#
printf(HW'debug7 after reduction0 'hifting from 'tate 0 toZ
'tate WdZnH0 <<P%5=*]0 <<=*8);#G
Tendif
yy'tate E <<=*8);G
QFFyy''p E <<=*8);G
QFFyy&'p E yy&alG
if (yychar I 0#
X
if ((yychar E yyle>(## I 0# yychar E 0G
Tif <<D519.
if (yydebug#
X
yy' E 0G
if (yychar IE <<M)]+3K58# yy' E yynameNyycharPG
if (\yy'# yy' E Hillegal@'ymbolHG
printf(HW'debug7 'tate Wd0 reading Wd (W'#ZnH0
<<P%5=*]0 <<=*8);0 yychar0 yy'#G
Y
Tendif
Y
if (yychar EE 0# goto yyacceptG
goto yyloopG
Y
if ((yyn E yyginde>NyymP# 44 (yyn FE yy'tate# JE 0 44
yyn IE <<+)1;5S*O5 44 yychec(NyynP EE yy'tate#
yy'tate E yytableNyynPG
el'e
yy'tate E yydgotoNyymPG
Tif <<D519.
if (yydebug#
printf(HW'debug7 after reduction0 'hifting from 'tate Wd Z
U
to 'tate WdZnH0 <<P%5=*]0 Qyy''p0 yy'tate#G
Tendif
if (yy''p JE yy''lim 44 yygrow'tac((##
X
goto yyo&erflowG
Y
QFFyy''p E yy'tateG
QFFyy&'p E yy&alG
goto yyloopG
yyo&erflow7
yyerror(Hyacc 'tac( o&erflowH#G
yyabort7
return (1#G
yyaccept7
return (0#G
Y
How to compile:
ayacc Ifile nameJ
acc y$tab$c bll @ly
INPUT: !F"QB
OUTPUT: +he &alue of e>pre''ion i' 1S$

3.0 APPROACHED RESULT AND CONCLUSION


;e>ical analy'i' i' a 'tage in compilation of any program$ *n thi' pha'e we generate
to(en' from the input 'tream of data$ =or performing thi' ta'( we need a ;e>ical
)naly?er$
So we are de'igning a le>ical analy?er that will generate to(en' from the gi&en
input in a high le&el language 'tatement$ 6e ha&e not u'ed any databa'e for 'toring
the 'ymbol table u'ed in thi' project a' 'uch0 a' par'ing the entire 'tatement i' beyond
the 'cope of thi' project$ +hi' ma(e' our le>ical analy?er portable and independent of
a D1MS$ +hi' although reduce' the number of (eyword' and 'pecial character'
identifiable by the le>ical analy?er0 and increa'e' the length of the code0 but on the
other hand reduce' the program comple>ity and increa'e' the o&erall 'peed of the
'y'tem$
+he main feature' of thi' le>ical analy?er can be 'ummari?ed a'7 @
Simple implementation$
=a't le>ical analy'i'$
5fficient re'ource utili?ation$
Portable$
100
4.0 APPLICATIONS AND FUTURE WORK
+hi' le>ical analy?er can be u'ed a' a 'tand alone 'tring analy'i' tool0 which can
analy?e a gi&en 'et of 'tring' and chec( there le>ical correctne''$ +hi' can al'o be
u'ed to analy?e the 'tring 'equence' delimited by white 'pace' in a C K CFF 'ource
code (Q$c K Q$cpp# file and output all the re'ult' in a te>t file0 if proper functionality of
file handling will be u'ed in the 'ource code of the le>ical analy?er0 thi' functionality
will not be a part of the pre'ent project but will be a&ailable in an upgraded &er'ion0 if
time permit' the de&elopment of it$ =urther more the application' of a le>ical analy?er
include7 @
1$ +e>t 5diting
!$ +e>t Proce''ing
"$ Pattern Matching
,$ =ile Searching
)n enhanced &er'ion of thi' le>ical analy?er can be incorporated with a Par'er
ha&ing the functionality of 'ynta> directed tran'lation0 to ma(e a complete Compiler
in the future$ +he le>ical a''embly of the (eyword' and 'pecial character' can be
appropriately modified in the 'ource code to create a new high le&el language li(e CF
F$

101
REFERENCES:
N1P$ <a'hwant Kanet(ar0 -;et 9' C20 *S187 107U1@U"""@1M"@S0 eighth edition0
Page'7 ,!, b ,"S$
N!P$ www$wi(ipedia$org
http7KKen$wi(ipedia$orgKwi(iK;e>icalLanaly'i'
N"P$ www$dragonboo($'tanford$edu
http7KKdragonboo($'tanford$eduKlecture@note'KStanford@CS1,"K0"@;e>ical@
)naly'i'$pdf
N,P$ www$doc'tore$mi($ua
http7KKdoc'tore$mi($uaKorellyKja&aKlangrefKch0!L01$htm
NBP$ www$i'i$edu
http7KKwww$i'i$eduKdpedroK+eachingKCSC*BMB@
Spring10K;ecture'K;e>ical)naly'i'$part"$Mp$pdf
NMP$ www$c'$ber(eley$edu
http7KKwww$c'$ber(eley$eduKdhilfingrKc'1M,KpublicLhtmlKlecture'Knote!$pdf
NSP$ Aohn 5$ :opcroft0 A$D$ 9llman0 -*ntroduction to )utomata +heory0 ;anguage'0
and Computation20 *S187 U1@UB01B@M@10 eighteenth edition0
Page 8o$7 $
NUP$ Pan(aj Aalote0 -)n *ntegrated )pproach +o Software 5ngineering20 *S187 U1@
S"1@!S1@B0 'econd edition0 Page'7 1" b 1S$
10!

Vous aimerez peut-être aussi