1 /* do not edit automatically generated by mc from pge. */
2 /* pge.mod master source file of the ebnf parser generator.
4 Copyright (C) 2003-2023 Free Software Foundation, Inc.
5 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
7 This file is part of GNU Modula-2.
9 GNU Modula-2 is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
14 GNU Modula-2 is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU Modula-2; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
23 # if !defined (PROC_D)
25 typedef void (*PROC_t
) (void);
26 typedef struct { PROC_t proc
; } PROC
;
40 # include "GStorage.h"
42 #if defined(__cplusplus)
46 # include "GPushBackInput.h"
49 # include "GStorage.h"
50 # include "GNameKey.h"
51 # include "GNumberIO.h"
52 # include "GSymbolKey.h"
54 # include "GDynamicStrings.h"
65 # define MaxCodeHunkLength 8192
66 # define MaxFileName 8192
67 # define MaxString 8192
68 # define DefaultRecovery TRUE
69 # define MaxElementsInSet 32
70 # define BaseRightLimit 75
71 # define BaseRightMargin 50
72 # define BaseNewLine 3
73 typedef struct pge_termdesc_r pge_termdesc
;
75 typedef pge_termdesc
*pge_TermDesc
;
77 typedef struct pge_DoProcedure_p pge_DoProcedure
;
79 typedef unsigned int pge_SetOfStop
;
81 typedef struct pge__T1_r pge__T1
;
83 typedef pge__T1
*pge_IdentDesc
;
85 typedef struct pge__T2_r pge__T2
;
87 typedef pge__T2
*pge_ProductionDesc
;
89 typedef struct pge__T3_r pge__T3
;
91 typedef pge__T3
*pge_StatementDesc
;
93 typedef struct pge__T4_r pge__T4
;
95 typedef pge__T4
*pge_ExpressionDesc
;
97 typedef struct pge__T5_r pge__T5
;
99 typedef struct pge__T6_r pge__T6
;
101 typedef pge__T6
*pge_FollowDesc
;
103 typedef struct pge__T7_r pge__T7
;
105 typedef pge__T7
*pge_SetDesc
;
107 typedef struct pge__T8_r pge__T8
;
109 typedef pge__T8
*pge_CodeDesc
;
111 typedef struct pge__T9_r pge__T9
;
113 typedef pge__T9
*pge_CodeHunk
;
115 typedef struct pge__T10_a pge__T10
;
117 typedef struct pge__T11_a pge__T11
;
119 typedef enum {pge_idel
, pge_tokel
, pge_litel
} pge_ElementType
;
121 typedef enum {pge_m2none
, pge_m2if
, pge_m2elsif
, pge_m2while
} pge_m2condition
;
123 typedef enum {pge_unknown
, pge_true
, pge_false
} pge_TraverseResult
;
125 typedef enum {pge_id
, pge_lit
, pge_sub
, pge_opt
, pge_mult
, pge_m2
} pge_FactorType
;
127 typedef pge__T5
*pge_FactorDesc
;
129 struct pge_termdesc_r
{
130 pge_FactorDesc factor
;
132 pge_FollowDesc followinfo
;
136 typedef void (*pge_DoProcedure_t
) (pge_ProductionDesc
);
137 struct pge_DoProcedure_p
{ pge_DoProcedure_t proc
; };
140 pge_ProductionDesc definition
;
146 pge_ProductionDesc next
;
147 pge_StatementDesc statement
;
149 unsigned int firstsolved
;
150 pge_FollowDesc followinfo
;
152 NameKey_Name description
;
157 pge_ExpressionDesc expr
;
158 pge_FollowDesc followinfo
;
164 pge_FollowDesc followinfo
;
169 pge_FollowDesc followinfo
;
172 pge_FactorDesc pushed
;
173 pge_FactorType type
; /* case tag */
177 pge_ExpressionDesc expr
;
183 unsigned int calcfollow
;
185 pge_TraverseResult reachend
;
186 pge_TraverseResult epsilon
;
192 pge_ElementType type
; /* case tag */
205 struct pge__T10_a
{ char array
[MaxCodeHunkLength
+1]; };
206 struct pge__T11_a
{ char array
[MaxFileName
+1]; };
212 static unsigned int LastLineNo
;
213 static unsigned int Finished
;
214 static unsigned int SuppressFileLineTag
;
215 static unsigned int KeywordFormatting
;
216 static unsigned int PrettyPrint
;
217 static unsigned int EmitCode
;
218 static unsigned int Texinfo
;
219 static unsigned int Sphinx
;
220 static unsigned int FreeDocLicense
;
221 static unsigned int Debugging
;
222 static unsigned int WasNoError
;
223 static unsigned int LinePrologue
;
224 static unsigned int LineEpilogue
;
225 static unsigned int LineDeclaration
;
226 static pge_CodeHunk CodePrologue
;
227 static pge_CodeHunk CodeEpilogue
;
228 static pge_CodeHunk CodeDeclaration
;
229 static pge_ProductionDesc CurrentProduction
;
230 static pge_ProductionDesc TailProduction
;
231 static pge_ProductionDesc HeadProduction
;
232 static pge_ExpressionDesc CurrentExpression
;
233 static pge_TermDesc CurrentTerm
;
234 static pge_FactorDesc CurrentFactor
;
235 static pge_IdentDesc CurrentIdent
;
236 static pge_StatementDesc CurrentStatement
;
237 static pge_SetDesc CurrentSetDesc
;
238 static SymbolKey_SymbolTree ReverseValues
;
239 static SymbolKey_SymbolTree Values
;
240 static SymbolKey_SymbolTree ReverseAliases
;
241 static SymbolKey_SymbolTree Aliases
;
242 static NameKey_Name ModuleName
;
243 static NameKey_Name LastLiteral
;
244 static NameKey_Name LastIdent
;
245 static NameKey_Name SymIsProc
;
246 static NameKey_Name TokenTypeProc
;
247 static NameKey_Name ErrorProcArray
;
248 static NameKey_Name ErrorProcString
;
249 static pge__T11 ArgName
;
250 static pge__T11 FileName
;
251 static unsigned int OnLineStart
;
252 static unsigned int BeginningOfLine
;
253 static unsigned int Indent
;
254 static unsigned int EmittedVar
;
255 static unsigned int ErrorRecovery
;
256 static unsigned int LargestValue
;
257 static unsigned int InitialElement
;
258 static unsigned int ParametersUsed
;
261 DescribeStop - issues a message explaining what tokens were expected
264 static DynamicStrings_String
DescribeStop (pge_SetOfStop stopset
);
267 DescribeError - issues a message explaining what tokens were expected
270 static void DescribeError (void);
273 AddEntry - adds an entry into, t, containing [def:value].
276 static void AddEntry (SymbolKey_SymbolTree
*t
, NameKey_Name def
, NameKey_Name value
);
279 Format1 - converts string, src, into, dest, together with encapsulated
280 entity, n. It only formats the first %s or %d with n.
283 static void Format1 (const char *src_
, unsigned int _src_high
, unsigned int n
, char *dest
, unsigned int _dest_high
);
289 static void WarnError1 (const char *a_
, unsigned int _a_high
, unsigned int n
);
295 static void PrettyFollow (const char *start_
, unsigned int _start_high
, const char *end_
, unsigned int _end_high
, pge_FollowDesc f
);
298 NewFollow - creates a new follow descriptor and returns the data structure.
301 static pge_FollowDesc
NewFollow (void);
304 AssignEpsilon - assigns the epsilon value and sets the epsilon to value,
305 providing condition is TRUE.
308 static void AssignEpsilon (unsigned int condition
, pge_FollowDesc f
, pge_TraverseResult value
);
311 GetEpsilon - returns the value of epsilon
314 static pge_TraverseResult
GetEpsilon (pge_FollowDesc f
);
317 AssignReachEnd - assigns the reachend value providing that, condition, is TRUE.
320 static void AssignReachEnd (unsigned int condition
, pge_FollowDesc f
, pge_TraverseResult value
);
323 GetReachEnd - returns the value of reachend
326 static pge_TraverseResult
GetReachEnd (pge_FollowDesc f
);
329 AssignFollow - assigns the follow set and sets the calcfollow to TRUE.
332 static void AssignFollow (pge_FollowDesc f
, pge_SetDesc s
);
335 GetFollow - returns the follow set.
338 static pge_SetDesc
GetFollow (pge_FollowDesc f
);
341 NewProduction - creates a new production and returns the data structure.
344 static pge_ProductionDesc
NewProduction (void);
350 static pge_FactorDesc
NewFactor (void);
353 NewTerm - returns a new term.
356 static pge_TermDesc
NewTerm (void);
359 NewExpression - returns a new expression.
362 static pge_ExpressionDesc
NewExpression (void);
365 NewStatement - returns a new statement.
368 static pge_StatementDesc
NewStatement (void);
371 NewSetDesc - creates a new set description and returns the data structure.
374 static pge_SetDesc
NewSetDesc (void);
377 NewCodeDesc - creates a new code descriptor and initializes all fields to zero.
380 static pge_CodeDesc
NewCodeDesc (void);
383 CodeFragmentPrologue - consumes code text up to a "%" after a newline.
386 static void CodeFragmentPrologue (void);
389 CodeFragmentEpilogue - consumes code text up to a "%" after a newline.
392 static void CodeFragmentEpilogue (void);
395 CodeFragmentDeclaration - consumes code text up to a "%" after a newline.
398 static void CodeFragmentDeclaration (void);
401 GetCodeFragment - collects the code fragment up until ^ %
404 static void GetCodeFragment (pge_CodeHunk
*h
);
407 WriteCodeHunkList - writes the CodeHunk list in the correct order.
410 static void WriteCodeHunkList (pge_CodeHunk l
);
413 WriteIndent - writes, n, spaces.
416 static void WriteIndent (unsigned int n
);
422 static void CheckWrite (char ch
, unsigned int *curpos
, unsigned int left
, unsigned int *seentext
);
425 WriteStringIndent - writes a string but it will try and remove upto indent spaces
429 static void WriteStringIndent (const char *a_
, unsigned int _a_high
, unsigned int indent
, unsigned int *curpos
, unsigned int left
, unsigned int *seentext
);
432 WriteCodeHunkListIndent - writes the CodeHunk list in the correct order
433 but it removes up to indent spaces if they exist.
436 static void WriteCodeHunkListIndent (pge_CodeHunk l
, unsigned int indent
, unsigned int *curpos
, unsigned int left
, unsigned int *seentext
);
439 Add - adds a character to a code hunk and creates another code hunk if necessary.
442 static pge_CodeHunk
Add (pge_CodeHunk
*p
, char ch
, unsigned int *i
);
445 ConsHunk - combine two possible code hunks.
448 static void ConsHunk (pge_CodeHunk
*p
, pge_CodeHunk q
);
451 GetName - returns the next symbol which is checked for a legal name.
454 static NameKey_Name
GetName (void);
457 SyntaxError - after a syntax error we skip all tokens up until we reach
461 static void SyntaxError (pge_SetOfStop stop
);
467 static void SyntaxCheck (pge_SetOfStop stop
);
473 static void Expect (bnflex_TokenType t
, pge_SetOfStop stop
);
476 Ident - error checking varient of Ident
479 static void Ident (pge_SetOfStop stop
);
482 Modula2Code - error checking varient of Modula2Code
485 static void Modula2Code (pge_SetOfStop stop
);
488 StartModName := % ModuleName := GetName() ; ignore begintok CodeFragmentPrologue % =:
491 static void StartModName (pge_SetOfStop stop
);
497 static void EndModName (pge_SetOfStop stop
);
500 DoDeclaration := % CodeFragmentDeclaration % =:
503 static void DoDeclaration (pge_SetOfStop stop
);
507 % LastLiteral := GetCurrentToken() ;
511 first symbols:literaltok
516 static void CollectLiteral (pge_SetOfStop stopset
);
520 % CurrentSetDesc := NewSetDesc() ;
521 WITH CurrentSetDesc^ DO
523 string := GetCurrentToken() ;
525 IF NOT ContainsSymKey(Values, GetCurrentToken())
527 AddEntry(Values, GetCurrentToken(), LargestValue) ;
528 AddEntry(ReverseValues, Name(LargestValue), GetCurrentToken()) ;
529 AddEntry(Aliases, GetCurrentToken(), GetCurrentToken()) ;
530 AddEntry(ReverseAliases, GetCurrentToken(), GetCurrentToken()) ;
536 first symbols:identtok
541 static void CollectTok (pge_SetOfStop stopset
);
545 % AddEntry(Aliases, LastLiteral, GetCurrentToken()) ;
546 AddEntry(ReverseAliases, GetCurrentToken(), LastLiteral) ;
547 AddEntry(Values, GetCurrentToken(), LargestValue) ;
548 AddEntry(ReverseValues, Name(LargestValue), GetCurrentToken()) ;
553 first symbols:identtok
558 static void DefineToken (pge_SetOfStop stopset
);
561 Rules := '%' 'rules' { Defs } ExtBNF
563 first symbols:codetok
568 static void Rules (pge_SetOfStop stopset
);
572 % VAR p: ProductionDesc ; %
574 % p := NewProduction() ;
575 p^.statement := NewStatement() ;
576 p^.statement^.followinfo^.calcfollow := TRUE ;
577 p^.statement^.followinfo^.epsilon := false ;
578 p^.statement^.followinfo^.reachend := false ;
579 p^.statement^.ident := CurrentIdent ;
580 p^.statement^.expr := NIL ;
581 p^.firstsolved := TRUE ;
582 p^.followinfo^.calcfollow := TRUE ;
583 p^.followinfo^.epsilon := false ;
584 p^.followinfo^.reachend := false %
585 First Follow [ 'epsilon'
586 % p^.statement^.followinfo^.epsilon := true ; these are not used - but they are displayed when debugging
587 p^.statement^.followinfo^.reachend := true ;
588 p^.followinfo^.epsilon := true ;
589 p^.followinfo^.reachend := true
592 % p^.description := LastLiteral %
595 first symbols:identtok
600 static void Special (pge_SetOfStop stopset
);
603 Factor := '%' Modula2Code '%' |
605 % WITH CurrentFactor^ DO
607 ident := CurrentIdent
610 % WITH CurrentFactor^ DO
612 string := LastLiteral ;
613 IF GetSymKey(Aliases, LastLiteral)=NulName
615 WarnError1('no token defined for literal %s', LastLiteral)
619 % WITH CurrentFactor^ DO
621 expr := NewExpression() ;
622 CurrentExpression := expr ;
625 % WITH CurrentFactor^ DO
627 expr := NewExpression() ;
628 CurrentExpression := expr ;
631 % WITH CurrentFactor^ DO
633 expr := NewExpression() ;
634 CurrentExpression := expr ;
638 first symbols:dquotetok, squotetok, lparatok, lsparatok, lcparatok, identtok, codetok
643 static void Factor (pge_SetOfStop stopset
);
647 % VAR i: IdentDesc ; %
649 % VAR p: ProductionDesc ; %
651 % p := FindDefinition(CurrentIdent^.name) ;
656 IF NOT ((p^.statement=NIL) OR (p^.statement^.expr=NIL))
658 WarnError1('already declared rule %s', CurrentIdent^.name)
661 i := CurrentIdent ; %
663 % VAR e: ExpressionDesc ; %
665 % e := NewExpression() ;
666 CurrentExpression := e ; %
668 % VAR s: StatementDesc ; %
670 % s := NewStatement() ;
676 % p^.statement := s ; %
679 first symbols:identtok
684 static void Statement (pge_SetOfStop stopset
);
687 Defs := 'special' Special | 'token' Token |
688 'error' ErrorProcedures |
689 'tokenfunc' TokenProcedure |
690 'symfunc' SymProcedure
692 first symbols:symfunctok, tfunctok, errortok, tokentok, specialtok
697 static void Defs (pge_SetOfStop stopset
);
700 ExtBNF := 'BNF' { Production } 'FNB'
707 static void ExtBNF (pge_SetOfStop stopset
);
710 Main := Header Decls Footer Rules
712 first symbols:codetok
717 static void Main (pge_SetOfStop stopset
);
720 Header := '%' 'module' StartModName
722 first symbols:codetok
727 static void Header (pge_SetOfStop stopset
);
730 Decls := '%' 'declaration' DoDeclaration
732 first symbols:codetok
737 static void Decls (pge_SetOfStop stopset
);
740 Footer := '%' 'module' EndModName
742 first symbols:codetok
747 static void Footer (pge_SetOfStop stopset
);
750 First := 'first' '{' { LitOrTokenOrIdent
751 % WITH CurrentSetDesc^ DO
752 next := TailProduction^.first ;
754 TailProduction^.first := CurrentSetDesc
758 first symbols:firsttok
763 static void First (pge_SetOfStop stopset
);
766 Follow := 'follow' '{' { LitOrTokenOrIdent
767 % WITH CurrentSetDesc^ DO
768 next := TailProduction^.followinfo^.follow ;
770 TailProduction^.followinfo^.follow := CurrentSetDesc
774 first symbols:followtok
779 static void Follow (pge_SetOfStop stopset
);
782 LitOrTokenOrIdent := Literal
783 % CurrentSetDesc := NewSetDesc() ;
784 WITH CurrentSetDesc^ DO
786 string := LastLiteral ;
789 | '<' CollectTok '>' |
791 % CurrentSetDesc := NewSetDesc() ;
792 WITH CurrentSetDesc^ DO
794 ident := CurrentIdent ;
799 first symbols:dquotetok, squotetok, identtok, lesstok
804 static void LitOrTokenOrIdent (pge_SetOfStop stopset
);
807 Literal := '"' CollectLiteral '"' |
808 "'" CollectLiteral "'"
810 first symbols:squotetok, dquotetok
815 static void Literal (pge_SetOfStop stopset
);
818 Token := Literal DefineToken
820 first symbols:dquotetok, squotetok
825 static void Token (pge_SetOfStop stopset
);
828 ErrorProcedures := Literal
829 % ErrorProcArray := LastLiteral %
831 % ErrorProcString := LastLiteral %
834 first symbols:dquotetok, squotetok
839 static void ErrorProcedures (pge_SetOfStop stopset
);
842 TokenProcedure := Literal
843 % TokenTypeProc := LastLiteral %
846 first symbols:dquotetok, squotetok
851 static void TokenProcedure (pge_SetOfStop stopset
);
854 SymProcedure := Literal
855 % SymIsProc := LastLiteral %
858 first symbols:dquotetok, squotetok
863 static void SymProcedure (pge_SetOfStop stopset
);
866 Production := Statement
868 first symbols:identtok
873 static void Production (pge_SetOfStop stopset
);
877 % VAR t1, t2: TermDesc ;
878 e : ExpressionDesc ; %
880 % e := CurrentExpression ;
882 CurrentTerm := t1 ; %
893 first symbols:dquotetok, squotetok, lparatok, lsparatok, lcparatok, identtok, codetok
898 static void Expression (pge_SetOfStop stopset
);
902 % VAR t1: TermDesc ; f1, f2: FactorDesc ; %
904 % CurrentFactor := NewFactor() ;
905 f1 := CurrentFactor ;
906 t1 := CurrentTerm ; %
910 CurrentFactor := f2 %
915 CurrentFactor := f2 ; %
918 first symbols:squotetok, dquotetok, codetok, identtok, lcparatok, lsparatok, lparatok
923 static void Term (pge_SetOfStop stopset
);
926 GetDefinitionName - returns the name of the rule inside, p.
929 static NameKey_Name
GetDefinitionName (pge_ProductionDesc p
);
932 FindDefinition - searches and returns the rule which defines, n.
935 static pge_ProductionDesc
FindDefinition (NameKey_Name n
);
938 BackPatchIdent - found an ident, i, we must look for the corresponding rule and
939 set the definition accordingly.
942 static void BackPatchIdent (pge_IdentDesc i
);
945 BackPatchFactor - runs through the factor looking for an ident
948 static void BackPatchFactor (pge_FactorDesc f
);
951 BackPatchTerm - runs through all terms to find idents.
954 static void BackPatchTerm (pge_TermDesc t
);
957 BackPatchExpression - runs through the term to find any idents.
960 static void BackPatchExpression (pge_ExpressionDesc e
);
966 static void BackPatchSet (pge_SetDesc s
);
969 BackPatchIdentToDefinitions - search through all the rules and add a link from any ident
973 static void BackPatchIdentToDefinitions (pge_ProductionDesc d
);
976 CalculateFirstAndFollow -
979 static void CalculateFirstAndFollow (pge_ProductionDesc p
);
985 static void ForeachRuleDo (pge_DoProcedure p
);
991 static void WhileNotCompleteDo (pge_DoProcedure p
);
994 NewLine - generate a newline and indent.
997 static void NewLine (unsigned int Left
);
1003 static void CheckNewLine (unsigned int Left
);
1006 IndentString - writes out a string with a preceeding indent.
1009 static void IndentString (const char *a_
, unsigned int _a_high
);
1012 KeyWord - writes out a keywork with optional formatting directives.
1015 static void KeyWord (NameKey_Name n
);
1021 static void PrettyPara (const char *c1_
, unsigned int _c1_high
, const char *c2_
, unsigned int _c2_high
, pge_ExpressionDesc e
, unsigned int Left
);
1027 static void WriteKeyTexinfo (NameKey_Name s
);
1030 PrettyCommentFactor -
1033 static void PrettyCommentFactor (pge_FactorDesc f
, unsigned int Left
);
1036 PeepTerm - returns the length of characters in term.
1039 static unsigned int PeepTerm (pge_TermDesc t
);
1042 PeepExpression - returns the length of the expression.
1045 static unsigned int PeepExpression (pge_ExpressionDesc e
);
1048 PeepFactor - returns the length of character in the factor
1051 static unsigned int PeepFactor (pge_FactorDesc f
);
1057 static void PrettyCommentTerm (pge_TermDesc t
, unsigned int Left
);
1060 PrettyCommentExpression -
1063 static void PrettyCommentExpression (pge_ExpressionDesc e
, unsigned int Left
);
1066 PrettyCommentStatement -
1069 static void PrettyCommentStatement (pge_StatementDesc s
, unsigned int Left
);
1072 PrettyCommentProduction - generates the comment for rule, p.
1075 static void PrettyCommentProduction (pge_ProductionDesc p
);
1078 PrettyPrintProduction - pretty prints the ebnf rule, p.
1081 static void PrettyPrintProduction (pge_ProductionDesc p
);
1084 EmitFileLineTag - emits a line and file tag using the C preprocessor syntax.
1087 static void EmitFileLineTag (unsigned int line
);
1090 EmitRule - generates a comment and code for rule, p.
1093 static void EmitRule (pge_ProductionDesc p
);
1099 static void CodeCondition (pge_m2condition m
);
1102 CodeThenDo - codes a "THEN" or "DO" depending upon, m.
1105 static void CodeThenDo (pge_m2condition m
);
1108 CodeElseEnd - builds an ELSE END statement using string, end.
1111 static void CodeElseEnd (const char *end_
, unsigned int _end_high
, unsigned int consumed
, pge_FactorDesc f
, unsigned int inopt
);
1114 CodeEnd - codes a "END" depending upon, m.
1117 static void CodeEnd (pge_m2condition m
, pge_TermDesc t
, unsigned int consumed
, pge_FactorDesc f
, unsigned int inopt
);
1120 EmitNonVarCode - writes out, code, providing it is not a variable declaration.
1123 static void EmitNonVarCode (pge_CodeDesc code
, unsigned int curpos
, unsigned int left
);
1129 static pge_FactorDesc
ChainOn (pge_FactorDesc codeStack
, pge_FactorDesc f
);
1135 static void FlushCode (pge_FactorDesc
*codeStack
);
1141 static void CodeFactor (pge_FactorDesc f
, pge_TermDesc t
, pge_m2condition l
, pge_m2condition n
, unsigned int inopt
, unsigned int inwhile
, unsigned int consumed
, pge_FactorDesc codeStack
);
1147 static void CodeTerm (pge_TermDesc t
, pge_m2condition m
, unsigned int inopt
, unsigned int inwhile
, unsigned int consumed
, pge_FactorDesc codeStack
);
1153 static void CodeExpression (pge_ExpressionDesc e
, pge_m2condition m
, unsigned int inopt
, unsigned int inwhile
, unsigned int consumed
, pge_FactorDesc codeStack
);
1159 static void CodeStatement (pge_StatementDesc s
, pge_m2condition m
);
1162 CodeProduction - only encode grammer rules which are not special.
1165 static void CodeProduction (pge_ProductionDesc p
);
1171 static void RecoverCondition (pge_m2condition m
);
1174 ConditionIndent - returns the number of spaces indentation created via, m.
1177 static unsigned int ConditionIndent (pge_m2condition m
);
1180 WriteGetTokenType - writes out the method of determining the token type.
1183 static void WriteGetTokenType (void);
1186 NumberOfElements - returns the number of elements in set, to, which lie between low..high
1189 static unsigned int NumberOfElements (pge_SetDesc to
, unsigned int low
, unsigned int high
);
1192 WriteElement - writes the literal name for element, e.
1195 static void WriteElement (unsigned int e
);
1198 EmitIsInSet - writes out the equivalent of GetTokenType() IN { toset }
1201 static void EmitIsInSet (pge_SetDesc to
, NameKey_Name low
, NameKey_Name high
);
1204 EmitIsInSubSet - writes out a test to see whether GetTokenype() is in { subset }
1207 static void EmitIsInSubSet (pge_SetDesc to
, unsigned int low
, unsigned int high
);
1213 static void EmitIsInFirst (pge_SetDesc to
, pge_m2condition m
);
1214 static void FlushRecoverCode (pge_FactorDesc
*codeStack
);
1220 static void RecoverFactor (pge_FactorDesc f
, pge_m2condition m
, pge_FactorDesc codeStack
);
1223 OptExpSeen - returns TRUE if we can see an optional expression in the factor.
1224 This is not the same as epsilon. Example { '+' } matches epsilon as
1225 well as { '+' | '-' } but OptExpSeen returns TRUE in the second case
1226 and FALSE in the first.
1229 static unsigned int OptExpSeen (pge_FactorDesc f
);
1235 static void RecoverTerm (pge_TermDesc t
, pge_m2condition new_
, pge_m2condition old
);
1241 static void RecoverExpression (pge_ExpressionDesc e
, pge_m2condition new_
, pge_m2condition old
);
1247 static void RecoverStatement (pge_StatementDesc s
, pge_m2condition m
);
1250 EmitFirstFactor - generate a list of all first tokens between the range: low..high.
1253 static void EmitFirstFactor (pge_FactorDesc f
, unsigned int low
, unsigned int high
);
1259 static void EmitUsed (unsigned int wordno
);
1262 EmitStopParameters - generate the stop set.
1265 static void EmitStopParameters (unsigned int FormalParameters
);
1268 IsBetween - returns TRUE if the value of the token, string, is
1269 in the range: low..high
1272 static unsigned int IsBetween (NameKey_Name string
, unsigned int low
, unsigned int high
);
1275 IsEmptySet - returns TRUE if no elements exist in set, to, with values, low..high.
1278 static unsigned int IsEmptySet (pge_SetDesc to
, unsigned int low
, unsigned int high
);
1281 EmitSet - emits the tokens in the set, to, which have values low..high
1284 static void EmitSet (pge_SetDesc to
, unsigned int low
, unsigned int high
);
1287 EmitSetName - emits the tokens in the set, to, which have values low..high, using
1291 static void EmitSetName (pge_SetDesc to
, unsigned int low
, unsigned int high
);
1294 EmitStopParametersAndSet - generates the stop parameters together with a set
1295 inclusion of all the symbols in set, to.
1298 static void EmitStopParametersAndSet (pge_SetDesc to
);
1301 EmitSetAsParameters - generates the first symbols as parameters to a set function.
1304 static void EmitSetAsParameters (pge_SetDesc to
);
1307 EmitStopParametersAndFollow - generates the stop parameters together with a set
1308 inclusion of all the follow symbols for subsequent
1312 static void EmitStopParametersAndFollow (pge_FactorDesc f
, pge_m2condition m
);
1315 EmitFirstAsParameters -
1318 static void EmitFirstAsParameters (pge_FactorDesc f
);
1321 RecoverProduction - only encode grammer rules which are not special.
1322 Generate error recovery code.
1325 static void RecoverProduction (pge_ProductionDesc p
);
1328 IsWhite - returns TRUE if, ch, is a space or a tab.
1331 static unsigned int IsWhite (char ch
);
1334 FindStr - returns TRUE if, str, was seen inside the code hunk
1337 static unsigned int FindStr (pge_CodeHunk
*code
, unsigned int *i
, const char *str_
, unsigned int _str_high
);
1343 static void WriteUpto (pge_CodeHunk code
, pge_CodeHunk upto
, unsigned int limit
);
1346 CheckForVar - checks for any local variables which need to be emitted during
1350 static void CheckForVar (pge_CodeHunk code
);
1356 static void VarFactor (pge_FactorDesc f
);
1362 static void VarTerm (pge_TermDesc t
);
1368 static void VarExpression (pge_ExpressionDesc e
);
1374 static void VarStatement (pge_StatementDesc s
);
1377 VarProduction - writes out all variable declarations.
1380 static void VarProduction (pge_ProductionDesc p
);
1383 In - returns TRUE if token, s, is already in the set, to.
1386 static unsigned int In (pge_SetDesc to
, NameKey_Name s
);
1389 IntersectionIsNil - given two set lists, s1, s2, return TRUE if the
1393 static unsigned int IntersectionIsNil (pge_SetDesc s1
, pge_SetDesc s2
);
1396 AddSet - adds a first symbol to a production.
1399 static void AddSet (pge_SetDesc
*to
, NameKey_Name s
);
1405 static void OrSet (pge_SetDesc
*to
, pge_SetDesc from
);
1411 static void CalcFirstFactor (pge_FactorDesc f
, pge_ProductionDesc from
, pge_SetDesc
*to
);
1417 static void CalcFirstTerm (pge_TermDesc t
, pge_ProductionDesc from
, pge_SetDesc
*to
);
1420 CalcFirstExpression -
1423 static void CalcFirstExpression (pge_ExpressionDesc e
, pge_ProductionDesc from
, pge_SetDesc
*to
);
1426 CalcFirstStatement -
1429 static void CalcFirstStatement (pge_StatementDesc s
, pge_ProductionDesc from
, pge_SetDesc
*to
);
1432 CalcFirstProduction - calculates all of the first symbols for the grammer
1435 static void CalcFirstProduction (pge_ProductionDesc p
, pge_ProductionDesc from
, pge_SetDesc
*to
);
1436 static void WorkOutFollowFactor (pge_FactorDesc f
, pge_SetDesc
*followset
, pge_SetDesc after
);
1442 static void WorkOutFollowTerm (pge_TermDesc t
, pge_SetDesc
*followset
, pge_SetDesc after
);
1445 WorkOutFollowExpression -
1448 static void WorkOutFollowExpression (pge_ExpressionDesc e
, pge_SetDesc
*followset
, pge_SetDesc after
);
1451 CollectFollow - collects the follow set from, f, into, to.
1454 static void CollectFollow (pge_SetDesc
*to
, pge_FollowDesc f
);
1460 static void CalcFollowFactor (pge_FactorDesc f
, pge_SetDesc after
);
1466 static void CalcFollowTerm (pge_TermDesc t
, pge_SetDesc after
);
1469 CalcFollowExpression -
1472 static void CalcFollowExpression (pge_ExpressionDesc e
, pge_SetDesc after
);
1475 CalcFollowStatement - given a bnf statement generate the follow set.
1478 static void CalcFollowStatement (pge_StatementDesc s
);
1481 CalcFollowProduction -
1484 static void CalcFollowProduction (pge_ProductionDesc p
);
1490 static void CalcEpsilonFactor (pge_FactorDesc f
);
1496 static void CalcEpsilonTerm (pge_TermDesc t
);
1499 CalcEpsilonExpression -
1502 static void CalcEpsilonExpression (pge_ExpressionDesc e
);
1505 CalcEpsilonStatement - given a bnf statement generate the follow set.
1508 static void CalcEpsilonStatement (pge_StatementDesc s
);
1511 CalcEpsilonProduction -
1514 static void CalcEpsilonProduction (pge_ProductionDesc p
);
1517 CalcReachEndFactor -
1520 static pge_TraverseResult
CalcReachEndFactor (pge_FactorDesc f
);
1526 static pge_TraverseResult
CalcReachEndTerm (pge_TermDesc t
);
1529 CalcReachEndExpression -
1532 static void CalcReachEndExpression (pge_ExpressionDesc e
);
1535 CalcReachEndStatement -
1538 static void CalcReachEndStatement (pge_StatementDesc s
);
1541 CalcReachEndStatement -
1544 static void stop (void);
1547 CalcReachEndProduction -
1550 static void CalcReachEndProduction (pge_ProductionDesc p
);
1556 static unsigned int EmptyFactor (pge_FactorDesc f
);
1559 EmptyTerm - returns TRUE if the term maybe empty.
1562 static unsigned int EmptyTerm (pge_TermDesc t
);
1568 static unsigned int EmptyExpression (pge_ExpressionDesc e
);
1571 EmptyStatement - returns TRUE if statement, s, is empty.
1574 static unsigned int EmptyStatement (pge_StatementDesc s
);
1577 EmptyProduction - returns if production, p, maybe empty.
1580 static unsigned int EmptyProduction (pge_ProductionDesc p
);
1586 static void EmitFDLNotice (void);
1589 EmitRules - generates the BNF rules.
1592 static void EmitRules (void);
1598 static void DescribeElement (unsigned int name
);
1601 EmitInTestStop - construct a test for stop element, name.
1604 static void EmitInTestStop (NameKey_Name name
);
1607 DescribeStopElement -
1610 static void DescribeStopElement (unsigned int name
);
1616 static void EmitDescribeStop (void);
1622 static void EmitDescribeError (void);
1625 EmitSetTypes - write out the set types used during error recovery
1628 static void EmitSetTypes (void);
1631 EmitSupport - generates the support routines.
1634 static void EmitSupport (void);
1637 DisposeSetDesc - dispose of the set list, s.
1640 static void DisposeSetDesc (pge_SetDesc
*s
);
1646 static unsigned int OptionalFactor (pge_FactorDesc f
);
1649 OptionalTerm - returns TRUE if the term maybe empty.
1652 static unsigned int OptionalTerm (pge_TermDesc t
);
1655 OptionalExpression -
1658 static unsigned int OptionalExpression (pge_ExpressionDesc e
);
1661 OptionalStatement - returns FALSE if statement, s, does not have a optional ambiguity.
1664 static unsigned int OptionalStatement (pge_StatementDesc s
);
1667 OptionalProduction -
1670 static unsigned int OptionalProduction (pge_ProductionDesc p
);
1676 static unsigned int CheckFirstFollow (pge_FactorDesc f
, pge_FactorDesc after
);
1679 ConstrainedEmptyFactor -
1682 static unsigned int ConstrainedEmptyFactor (pge_FactorDesc f
);
1685 ConstrainedEmptyTerm - returns TRUE if the term maybe empty.
1688 static unsigned int ConstrainedEmptyTerm (pge_TermDesc t
);
1691 ConstrainedEmptyExpression -
1694 static unsigned int ConstrainedEmptyExpression (pge_ExpressionDesc e
);
1697 ConstrainedEmptyStatement - returns FALSE if statement, s, does not have a optional ambiguity.
1700 static unsigned int ConstrainedEmptyStatement (pge_StatementDesc s
);
1703 ConstrainedEmptyProduction - returns TRUE if a problem exists with, p.
1706 static unsigned int ConstrainedEmptyProduction (pge_ProductionDesc p
);
1712 static void TestForLALR1 (pge_ProductionDesc p
);
1715 DoEpsilon - runs the epsilon interrelated rules
1718 static void DoEpsilon (pge_ProductionDesc p
);
1721 CheckComplete - checks that production, p, is complete.
1724 static void CheckComplete (pge_ProductionDesc p
);
1727 PostProcessRules - backpatch the ident to rule definitions and emit comments and code.
1730 static void PostProcessRules (void);
1733 DisplayHelp - display a summary help and then exit (0).
1736 static void DisplayHelp (void);
1742 static void ParseArgs (void);
1745 Init - initialize the modules data structures
1748 static void Init (void);
1751 DescribeStop - issues a message explaining what tokens were expected
1754 static DynamicStrings_String
DescribeStop (pge_SetOfStop stopset
);
1757 DescribeError - issues a message explaining what tokens were expected
1760 static void DescribeError (void);
1763 AddEntry - adds an entry into, t, containing [def:value].
1766 static void AddEntry (SymbolKey_SymbolTree
*t
, NameKey_Name def
, NameKey_Name value
);
1769 Format1 - converts string, src, into, dest, together with encapsulated
1770 entity, n. It only formats the first %s or %d with n.
1773 static void Format1 (const char *src_
, unsigned int _src_high
, unsigned int n
, char *dest
, unsigned int _dest_high
);
1779 static void WarnError1 (const char *a_
, unsigned int _a_high
, unsigned int n
);
1785 static void PrettyFollow (const char *start_
, unsigned int _start_high
, const char *end_
, unsigned int _end_high
, pge_FollowDesc f
);
1788 NewFollow - creates a new follow descriptor and returns the data structure.
1791 static pge_FollowDesc
NewFollow (void);
1794 AssignEpsilon - assigns the epsilon value and sets the epsilon to value,
1795 providing condition is TRUE.
1798 static void AssignEpsilon (unsigned int condition
, pge_FollowDesc f
, pge_TraverseResult value
);
1801 GetEpsilon - returns the value of epsilon
1804 static pge_TraverseResult
GetEpsilon (pge_FollowDesc f
);
1807 AssignReachEnd - assigns the reachend value providing that, condition, is TRUE.
1810 static void AssignReachEnd (unsigned int condition
, pge_FollowDesc f
, pge_TraverseResult value
);
1813 GetReachEnd - returns the value of reachend
1816 static pge_TraverseResult
GetReachEnd (pge_FollowDesc f
);
1819 AssignFollow - assigns the follow set and sets the calcfollow to TRUE.
1822 static void AssignFollow (pge_FollowDesc f
, pge_SetDesc s
);
1825 GetFollow - returns the follow set.
1828 static pge_SetDesc
GetFollow (pge_FollowDesc f
);
1831 NewProduction - creates a new production and returns the data structure.
1834 static pge_ProductionDesc
NewProduction (void);
1840 static pge_FactorDesc
NewFactor (void);
1843 NewTerm - returns a new term.
1846 static pge_TermDesc
NewTerm (void);
1849 NewExpression - returns a new expression.
1852 static pge_ExpressionDesc
NewExpression (void);
1855 NewStatement - returns a new statement.
1858 static pge_StatementDesc
NewStatement (void);
1861 NewSetDesc - creates a new set description and returns the data structure.
1864 static pge_SetDesc
NewSetDesc (void);
1867 NewCodeDesc - creates a new code descriptor and initializes all fields to zero.
1870 static pge_CodeDesc
NewCodeDesc (void);
1873 CodeFragmentPrologue - consumes code text up to a "%" after a newline.
1876 static void CodeFragmentPrologue (void);
1879 CodeFragmentEpilogue - consumes code text up to a "%" after a newline.
1882 static void CodeFragmentEpilogue (void);
1885 CodeFragmentDeclaration - consumes code text up to a "%" after a newline.
1888 static void CodeFragmentDeclaration (void);
1891 GetCodeFragment - collects the code fragment up until ^ %
1894 static void GetCodeFragment (pge_CodeHunk
*h
);
1897 WriteCodeHunkList - writes the CodeHunk list in the correct order.
1900 static void WriteCodeHunkList (pge_CodeHunk l
);
1903 WriteIndent - writes, n, spaces.
1906 static void WriteIndent (unsigned int n
);
1912 static void CheckWrite (char ch
, unsigned int *curpos
, unsigned int left
, unsigned int *seentext
);
1915 WriteStringIndent - writes a string but it will try and remove upto indent spaces
1919 static void WriteStringIndent (const char *a_
, unsigned int _a_high
, unsigned int indent
, unsigned int *curpos
, unsigned int left
, unsigned int *seentext
);
1922 WriteCodeHunkListIndent - writes the CodeHunk list in the correct order
1923 but it removes up to indent spaces if they exist.
1926 static void WriteCodeHunkListIndent (pge_CodeHunk l
, unsigned int indent
, unsigned int *curpos
, unsigned int left
, unsigned int *seentext
);
1929 Add - adds a character to a code hunk and creates another code hunk if necessary.
1932 static pge_CodeHunk
Add (pge_CodeHunk
*p
, char ch
, unsigned int *i
);
1935 ConsHunk - combine two possible code hunks.
1938 static void ConsHunk (pge_CodeHunk
*p
, pge_CodeHunk q
);
1941 GetName - returns the next symbol which is checked for a legal name.
1944 static NameKey_Name
GetName (void);
1947 SyntaxError - after a syntax error we skip all tokens up until we reach
1951 static void SyntaxError (pge_SetOfStop stop
);
1957 static void SyntaxCheck (pge_SetOfStop stop
);
1963 static void Expect (bnflex_TokenType t
, pge_SetOfStop stop
);
1966 Ident - error checking varient of Ident
1969 static void Ident (pge_SetOfStop stop
);
1972 Modula2Code - error checking varient of Modula2Code
1975 static void Modula2Code (pge_SetOfStop stop
);
1978 StartModName := % ModuleName := GetName() ; ignore begintok CodeFragmentPrologue % =:
1981 static void StartModName (pge_SetOfStop stop
);
1987 static void EndModName (pge_SetOfStop stop
);
1990 DoDeclaration := % CodeFragmentDeclaration % =:
1993 static void DoDeclaration (pge_SetOfStop stop
);
1997 % LastLiteral := GetCurrentToken() ;
2001 first symbols:literaltok
2006 static void CollectLiteral (pge_SetOfStop stopset
);
2010 % CurrentSetDesc := NewSetDesc() ;
2011 WITH CurrentSetDesc^ DO
2013 string := GetCurrentToken() ;
2015 IF NOT ContainsSymKey(Values, GetCurrentToken())
2017 AddEntry(Values, GetCurrentToken(), LargestValue) ;
2018 AddEntry(ReverseValues, Name(LargestValue), GetCurrentToken()) ;
2019 AddEntry(Aliases, GetCurrentToken(), GetCurrentToken()) ;
2020 AddEntry(ReverseAliases, GetCurrentToken(), GetCurrentToken()) ;
2026 first symbols:identtok
2031 static void CollectTok (pge_SetOfStop stopset
);
2035 % AddEntry(Aliases, LastLiteral, GetCurrentToken()) ;
2036 AddEntry(ReverseAliases, GetCurrentToken(), LastLiteral) ;
2037 AddEntry(Values, GetCurrentToken(), LargestValue) ;
2038 AddEntry(ReverseValues, Name(LargestValue), GetCurrentToken()) ;
2043 first symbols:identtok
2048 static void DefineToken (pge_SetOfStop stopset
);
2051 Rules := '%' 'rules' { Defs } ExtBNF
2053 first symbols:codetok
2058 static void Rules (pge_SetOfStop stopset
);
2062 % VAR p: ProductionDesc ; %
2064 % p := NewProduction() ;
2065 p^.statement := NewStatement() ;
2066 p^.statement^.followinfo^.calcfollow := TRUE ;
2067 p^.statement^.followinfo^.epsilon := false ;
2068 p^.statement^.followinfo^.reachend := false ;
2069 p^.statement^.ident := CurrentIdent ;
2070 p^.statement^.expr := NIL ;
2071 p^.firstsolved := TRUE ;
2072 p^.followinfo^.calcfollow := TRUE ;
2073 p^.followinfo^.epsilon := false ;
2074 p^.followinfo^.reachend := false %
2075 First Follow [ 'epsilon'
2076 % p^.statement^.followinfo^.epsilon := true ; these are not used - but they are displayed when debugging
2077 p^.statement^.followinfo^.reachend := true ;
2078 p^.followinfo^.epsilon := true ;
2079 p^.followinfo^.reachend := true
2082 % p^.description := LastLiteral %
2085 first symbols:identtok
2090 static void Special (pge_SetOfStop stopset
);
2093 Factor := '%' Modula2Code '%' |
2095 % WITH CurrentFactor^ DO
2097 ident := CurrentIdent
2100 % WITH CurrentFactor^ DO
2102 string := LastLiteral ;
2103 IF GetSymKey(Aliases, LastLiteral)=NulName
2105 WarnError1('no token defined for literal %s', LastLiteral)
2109 % WITH CurrentFactor^ DO
2111 expr := NewExpression() ;
2112 CurrentExpression := expr ;
2114 Expression '}' | '['
2115 % WITH CurrentFactor^ DO
2117 expr := NewExpression() ;
2118 CurrentExpression := expr ;
2120 Expression ']' | '('
2121 % WITH CurrentFactor^ DO
2123 expr := NewExpression() ;
2124 CurrentExpression := expr ;
2128 first symbols:dquotetok, squotetok, lparatok, lsparatok, lcparatok, identtok, codetok
2133 static void Factor (pge_SetOfStop stopset
);
2137 % VAR i: IdentDesc ; %
2139 % VAR p: ProductionDesc ; %
2141 % p := FindDefinition(CurrentIdent^.name) ;
2144 p := NewProduction()
2146 IF NOT ((p^.statement=NIL) OR (p^.statement^.expr=NIL))
2148 WarnError1('already declared rule %s', CurrentIdent^.name)
2151 i := CurrentIdent ; %
2153 % VAR e: ExpressionDesc ; %
2155 % e := NewExpression() ;
2156 CurrentExpression := e ; %
2158 % VAR s: StatementDesc ; %
2160 % s := NewStatement() ;
2166 % p^.statement := s ; %
2169 first symbols:identtok
2174 static void Statement (pge_SetOfStop stopset
);
2177 Defs := 'special' Special | 'token' Token |
2178 'error' ErrorProcedures |
2179 'tokenfunc' TokenProcedure |
2180 'symfunc' SymProcedure
2182 first symbols:symfunctok, tfunctok, errortok, tokentok, specialtok
2187 static void Defs (pge_SetOfStop stopset
);
2190 ExtBNF := 'BNF' { Production } 'FNB'
2192 first symbols:BNFtok
2197 static void ExtBNF (pge_SetOfStop stopset
);
2200 Main := Header Decls Footer Rules
2202 first symbols:codetok
2207 static void Main (pge_SetOfStop stopset
);
2210 Header := '%' 'module' StartModName
2212 first symbols:codetok
2217 static void Header (pge_SetOfStop stopset
);
2220 Decls := '%' 'declaration' DoDeclaration
2222 first symbols:codetok
2227 static void Decls (pge_SetOfStop stopset
);
2230 Footer := '%' 'module' EndModName
2232 first symbols:codetok
2237 static void Footer (pge_SetOfStop stopset
);
2240 First := 'first' '{' { LitOrTokenOrIdent
2241 % WITH CurrentSetDesc^ DO
2242 next := TailProduction^.first ;
2244 TailProduction^.first := CurrentSetDesc
2248 first symbols:firsttok
2253 static void First (pge_SetOfStop stopset
);
2256 Follow := 'follow' '{' { LitOrTokenOrIdent
2257 % WITH CurrentSetDesc^ DO
2258 next := TailProduction^.followinfo^.follow ;
2260 TailProduction^.followinfo^.follow := CurrentSetDesc
2264 first symbols:followtok
2269 static void Follow (pge_SetOfStop stopset
);
2272 LitOrTokenOrIdent := Literal
2273 % CurrentSetDesc := NewSetDesc() ;
2274 WITH CurrentSetDesc^ DO
2276 string := LastLiteral ;
2279 | '<' CollectTok '>' |
2281 % CurrentSetDesc := NewSetDesc() ;
2282 WITH CurrentSetDesc^ DO
2284 ident := CurrentIdent ;
2289 first symbols:dquotetok, squotetok, identtok, lesstok
2294 static void LitOrTokenOrIdent (pge_SetOfStop stopset
);
2297 Literal := '"' CollectLiteral '"' |
2298 "'" CollectLiteral "'"
2300 first symbols:squotetok, dquotetok
2305 static void Literal (pge_SetOfStop stopset
);
2308 Token := Literal DefineToken
2310 first symbols:dquotetok, squotetok
2315 static void Token (pge_SetOfStop stopset
);
2318 ErrorProcedures := Literal
2319 % ErrorProcArray := LastLiteral %
2321 % ErrorProcString := LastLiteral %
2324 first symbols:dquotetok, squotetok
2329 static void ErrorProcedures (pge_SetOfStop stopset
);
2332 TokenProcedure := Literal
2333 % TokenTypeProc := LastLiteral %
2336 first symbols:dquotetok, squotetok
2341 static void TokenProcedure (pge_SetOfStop stopset
);
2344 SymProcedure := Literal
2345 % SymIsProc := LastLiteral %
2348 first symbols:dquotetok, squotetok
2353 static void SymProcedure (pge_SetOfStop stopset
);
2356 Production := Statement
2358 first symbols:identtok
2363 static void Production (pge_SetOfStop stopset
);
2367 % VAR t1, t2: TermDesc ;
2368 e : ExpressionDesc ; %
2370 % e := CurrentExpression ;
2372 CurrentTerm := t1 ; %
2383 first symbols:dquotetok, squotetok, lparatok, lsparatok, lcparatok, identtok, codetok
2388 static void Expression (pge_SetOfStop stopset
);
2392 % VAR t1: TermDesc ; f1, f2: FactorDesc ; %
2394 % CurrentFactor := NewFactor() ;
2395 f1 := CurrentFactor ;
2396 t1 := CurrentTerm ; %
2398 % t1^.factor := f1 ;
2400 CurrentFactor := f2 %
2405 CurrentFactor := f2 ; %
2408 first symbols:squotetok, dquotetok, codetok, identtok, lcparatok, lsparatok, lparatok
2413 static void Term (pge_SetOfStop stopset
);
2416 GetDefinitionName - returns the name of the rule inside, p.
2419 static NameKey_Name
GetDefinitionName (pge_ProductionDesc p
);
2422 FindDefinition - searches and returns the rule which defines, n.
2425 static pge_ProductionDesc
FindDefinition (NameKey_Name n
);
2428 BackPatchIdent - found an ident, i, we must look for the corresponding rule and
2429 set the definition accordingly.
2432 static void BackPatchIdent (pge_IdentDesc i
);
2435 BackPatchFactor - runs through the factor looking for an ident
2438 static void BackPatchFactor (pge_FactorDesc f
);
2441 BackPatchTerm - runs through all terms to find idents.
2444 static void BackPatchTerm (pge_TermDesc t
);
2447 BackPatchExpression - runs through the term to find any idents.
2450 static void BackPatchExpression (pge_ExpressionDesc e
);
2456 static void BackPatchSet (pge_SetDesc s
);
2459 BackPatchIdentToDefinitions - search through all the rules and add a link from any ident
2463 static void BackPatchIdentToDefinitions (pge_ProductionDesc d
);
2466 CalculateFirstAndFollow -
2469 static void CalculateFirstAndFollow (pge_ProductionDesc p
);
2475 static void ForeachRuleDo (pge_DoProcedure p
);
2478 WhileNotCompleteDo -
2481 static void WhileNotCompleteDo (pge_DoProcedure p
);
2484 NewLine - generate a newline and indent.
2487 static void NewLine (unsigned int Left
);
2493 static void CheckNewLine (unsigned int Left
);
2496 IndentString - writes out a string with a preceeding indent.
2499 static void IndentString (const char *a_
, unsigned int _a_high
);
2502 KeyWord - writes out a keywork with optional formatting directives.
2505 static void KeyWord (NameKey_Name n
);
2511 static void PrettyPara (const char *c1_
, unsigned int _c1_high
, const char *c2_
, unsigned int _c2_high
, pge_ExpressionDesc e
, unsigned int Left
);
2517 static void WriteKeyTexinfo (NameKey_Name s
);
2520 PrettyCommentFactor -
2523 static void PrettyCommentFactor (pge_FactorDesc f
, unsigned int Left
);
2526 PeepTerm - returns the length of characters in term.
2529 static unsigned int PeepTerm (pge_TermDesc t
);
2532 PeepExpression - returns the length of the expression.
2535 static unsigned int PeepExpression (pge_ExpressionDesc e
);
2538 PeepFactor - returns the length of character in the factor
2541 static unsigned int PeepFactor (pge_FactorDesc f
);
2547 static void PrettyCommentTerm (pge_TermDesc t
, unsigned int Left
);
2550 PrettyCommentExpression -
2553 static void PrettyCommentExpression (pge_ExpressionDesc e
, unsigned int Left
);
2556 PrettyCommentStatement -
2559 static void PrettyCommentStatement (pge_StatementDesc s
, unsigned int Left
);
2562 PrettyCommentProduction - generates the comment for rule, p.
2565 static void PrettyCommentProduction (pge_ProductionDesc p
);
2568 PrettyPrintProduction - pretty prints the ebnf rule, p.
2571 static void PrettyPrintProduction (pge_ProductionDesc p
);
2574 EmitFileLineTag - emits a line and file tag using the C preprocessor syntax.
2577 static void EmitFileLineTag (unsigned int line
);
2580 EmitRule - generates a comment and code for rule, p.
2583 static void EmitRule (pge_ProductionDesc p
);
2589 static void CodeCondition (pge_m2condition m
);
2592 CodeThenDo - codes a "THEN" or "DO" depending upon, m.
2595 static void CodeThenDo (pge_m2condition m
);
2598 CodeElseEnd - builds an ELSE END statement using string, end.
2601 static void CodeElseEnd (const char *end_
, unsigned int _end_high
, unsigned int consumed
, pge_FactorDesc f
, unsigned int inopt
);
2604 CodeEnd - codes a "END" depending upon, m.
2607 static void CodeEnd (pge_m2condition m
, pge_TermDesc t
, unsigned int consumed
, pge_FactorDesc f
, unsigned int inopt
);
2610 EmitNonVarCode - writes out, code, providing it is not a variable declaration.
2613 static void EmitNonVarCode (pge_CodeDesc code
, unsigned int curpos
, unsigned int left
);
2619 static pge_FactorDesc
ChainOn (pge_FactorDesc codeStack
, pge_FactorDesc f
);
2625 static void FlushCode (pge_FactorDesc
*codeStack
);
2631 static void CodeFactor (pge_FactorDesc f
, pge_TermDesc t
, pge_m2condition l
, pge_m2condition n
, unsigned int inopt
, unsigned int inwhile
, unsigned int consumed
, pge_FactorDesc codeStack
);
2637 static void CodeTerm (pge_TermDesc t
, pge_m2condition m
, unsigned int inopt
, unsigned int inwhile
, unsigned int consumed
, pge_FactorDesc codeStack
);
2643 static void CodeExpression (pge_ExpressionDesc e
, pge_m2condition m
, unsigned int inopt
, unsigned int inwhile
, unsigned int consumed
, pge_FactorDesc codeStack
);
2649 static void CodeStatement (pge_StatementDesc s
, pge_m2condition m
);
2652 CodeProduction - only encode grammer rules which are not special.
2655 static void CodeProduction (pge_ProductionDesc p
);
2661 static void RecoverCondition (pge_m2condition m
);
2664 ConditionIndent - returns the number of spaces indentation created via, m.
2667 static unsigned int ConditionIndent (pge_m2condition m
);
2670 WriteGetTokenType - writes out the method of determining the token type.
2673 static void WriteGetTokenType (void);
2676 NumberOfElements - returns the number of elements in set, to, which lie between low..high
2679 static unsigned int NumberOfElements (pge_SetDesc to
, unsigned int low
, unsigned int high
);
2682 WriteElement - writes the literal name for element, e.
2685 static void WriteElement (unsigned int e
);
2688 EmitIsInSet - writes out the equivalent of GetTokenType() IN { toset }
2691 static void EmitIsInSet (pge_SetDesc to
, NameKey_Name low
, NameKey_Name high
);
2694 EmitIsInSubSet - writes out a test to see whether GetTokenype() is in { subset }
2697 static void EmitIsInSubSet (pge_SetDesc to
, unsigned int low
, unsigned int high
);
2703 static void EmitIsInFirst (pge_SetDesc to
, pge_m2condition m
);
2704 static void FlushRecoverCode (pge_FactorDesc
*codeStack
);
2710 static void RecoverFactor (pge_FactorDesc f
, pge_m2condition m
, pge_FactorDesc codeStack
);
2713 OptExpSeen - returns TRUE if we can see an optional expression in the factor.
2714 This is not the same as epsilon. Example { '+' } matches epsilon as
2715 well as { '+' | '-' } but OptExpSeen returns TRUE in the second case
2716 and FALSE in the first.
2719 static unsigned int OptExpSeen (pge_FactorDesc f
);
2725 static void RecoverTerm (pge_TermDesc t
, pge_m2condition new_
, pge_m2condition old
);
2731 static void RecoverExpression (pge_ExpressionDesc e
, pge_m2condition new_
, pge_m2condition old
);
2737 static void RecoverStatement (pge_StatementDesc s
, pge_m2condition m
);
2740 EmitFirstFactor - generate a list of all first tokens between the range: low..high.
2743 static void EmitFirstFactor (pge_FactorDesc f
, unsigned int low
, unsigned int high
);
2749 static void EmitUsed (unsigned int wordno
);
2752 EmitStopParameters - generate the stop set.
2755 static void EmitStopParameters (unsigned int FormalParameters
);
2758 IsBetween - returns TRUE if the value of the token, string, is
2759 in the range: low..high
2762 static unsigned int IsBetween (NameKey_Name string
, unsigned int low
, unsigned int high
);
2765 IsEmptySet - returns TRUE if no elements exist in set, to, with values, low..high.
2768 static unsigned int IsEmptySet (pge_SetDesc to
, unsigned int low
, unsigned int high
);
2771 EmitSet - emits the tokens in the set, to, which have values low..high
2774 static void EmitSet (pge_SetDesc to
, unsigned int low
, unsigned int high
);
2777 EmitSetName - emits the tokens in the set, to, which have values low..high, using
2781 static void EmitSetName (pge_SetDesc to
, unsigned int low
, unsigned int high
);
2784 EmitStopParametersAndSet - generates the stop parameters together with a set
2785 inclusion of all the symbols in set, to.
2788 static void EmitStopParametersAndSet (pge_SetDesc to
);
2791 EmitSetAsParameters - generates the first symbols as parameters to a set function.
2794 static void EmitSetAsParameters (pge_SetDesc to
);
2797 EmitStopParametersAndFollow - generates the stop parameters together with a set
2798 inclusion of all the follow symbols for subsequent
2802 static void EmitStopParametersAndFollow (pge_FactorDesc f
, pge_m2condition m
);
2805 EmitFirstAsParameters -
2808 static void EmitFirstAsParameters (pge_FactorDesc f
);
2811 RecoverProduction - only encode grammer rules which are not special.
2812 Generate error recovery code.
2815 static void RecoverProduction (pge_ProductionDesc p
);
2818 IsWhite - returns TRUE if, ch, is a space or a tab.
2821 static unsigned int IsWhite (char ch
);
2824 FindStr - returns TRUE if, str, was seen inside the code hunk
2827 static unsigned int FindStr (pge_CodeHunk
*code
, unsigned int *i
, const char *str_
, unsigned int _str_high
);
2833 static void WriteUpto (pge_CodeHunk code
, pge_CodeHunk upto
, unsigned int limit
);
2836 CheckForVar - checks for any local variables which need to be emitted during
2840 static void CheckForVar (pge_CodeHunk code
);
2846 static void VarFactor (pge_FactorDesc f
);
2852 static void VarTerm (pge_TermDesc t
);
2858 static void VarExpression (pge_ExpressionDesc e
);
2864 static void VarStatement (pge_StatementDesc s
);
2867 VarProduction - writes out all variable declarations.
2870 static void VarProduction (pge_ProductionDesc p
);
2873 In - returns TRUE if token, s, is already in the set, to.
2876 static unsigned int In (pge_SetDesc to
, NameKey_Name s
);
2879 IntersectionIsNil - given two set lists, s1, s2, return TRUE if the
2883 static unsigned int IntersectionIsNil (pge_SetDesc s1
, pge_SetDesc s2
);
2886 AddSet - adds a first symbol to a production.
2889 static void AddSet (pge_SetDesc
*to
, NameKey_Name s
);
2895 static void OrSet (pge_SetDesc
*to
, pge_SetDesc from
);
2901 static void CalcFirstFactor (pge_FactorDesc f
, pge_ProductionDesc from
, pge_SetDesc
*to
);
2907 static void CalcFirstTerm (pge_TermDesc t
, pge_ProductionDesc from
, pge_SetDesc
*to
);
2910 CalcFirstExpression -
2913 static void CalcFirstExpression (pge_ExpressionDesc e
, pge_ProductionDesc from
, pge_SetDesc
*to
);
2916 CalcFirstStatement -
2919 static void CalcFirstStatement (pge_StatementDesc s
, pge_ProductionDesc from
, pge_SetDesc
*to
);
2922 CalcFirstProduction - calculates all of the first symbols for the grammer
2925 static void CalcFirstProduction (pge_ProductionDesc p
, pge_ProductionDesc from
, pge_SetDesc
*to
);
2926 static void WorkOutFollowFactor (pge_FactorDesc f
, pge_SetDesc
*followset
, pge_SetDesc after
);
2932 static void WorkOutFollowTerm (pge_TermDesc t
, pge_SetDesc
*followset
, pge_SetDesc after
);
2935 WorkOutFollowExpression -
2938 static void WorkOutFollowExpression (pge_ExpressionDesc e
, pge_SetDesc
*followset
, pge_SetDesc after
);
2941 CollectFollow - collects the follow set from, f, into, to.
2944 static void CollectFollow (pge_SetDesc
*to
, pge_FollowDesc f
);
2950 static void CalcFollowFactor (pge_FactorDesc f
, pge_SetDesc after
);
2956 static void CalcFollowTerm (pge_TermDesc t
, pge_SetDesc after
);
2959 CalcFollowExpression -
2962 static void CalcFollowExpression (pge_ExpressionDesc e
, pge_SetDesc after
);
2965 CalcFollowStatement - given a bnf statement generate the follow set.
2968 static void CalcFollowStatement (pge_StatementDesc s
);
2971 CalcFollowProduction -
2974 static void CalcFollowProduction (pge_ProductionDesc p
);
2980 static void CalcEpsilonFactor (pge_FactorDesc f
);
2986 static void CalcEpsilonTerm (pge_TermDesc t
);
2989 CalcEpsilonExpression -
2992 static void CalcEpsilonExpression (pge_ExpressionDesc e
);
2995 CalcEpsilonStatement - given a bnf statement generate the follow set.
2998 static void CalcEpsilonStatement (pge_StatementDesc s
);
3001 CalcEpsilonProduction -
3004 static void CalcEpsilonProduction (pge_ProductionDesc p
);
3007 CalcReachEndFactor -
3010 static pge_TraverseResult
CalcReachEndFactor (pge_FactorDesc f
);
3016 static pge_TraverseResult
CalcReachEndTerm (pge_TermDesc t
);
3019 CalcReachEndExpression -
3022 static void CalcReachEndExpression (pge_ExpressionDesc e
);
3025 CalcReachEndStatement -
3028 static void CalcReachEndStatement (pge_StatementDesc s
);
3031 CalcReachEndStatement -
3034 static void stop (void);
3037 CalcReachEndProduction -
3040 static void CalcReachEndProduction (pge_ProductionDesc p
);
3046 static unsigned int EmptyFactor (pge_FactorDesc f
);
3049 EmptyTerm - returns TRUE if the term maybe empty.
3052 static unsigned int EmptyTerm (pge_TermDesc t
);
3058 static unsigned int EmptyExpression (pge_ExpressionDesc e
);
3061 EmptyStatement - returns TRUE if statement, s, is empty.
3064 static unsigned int EmptyStatement (pge_StatementDesc s
);
3067 EmptyProduction - returns if production, p, maybe empty.
3070 static unsigned int EmptyProduction (pge_ProductionDesc p
);
3076 static void EmitFDLNotice (void);
3079 EmitRules - generates the BNF rules.
3082 static void EmitRules (void);
3088 static void DescribeElement (unsigned int name
);
3091 EmitInTestStop - construct a test for stop element, name.
3094 static void EmitInTestStop (NameKey_Name name
);
3097 DescribeStopElement -
3100 static void DescribeStopElement (unsigned int name
);
3106 static void EmitDescribeStop (void);
3112 static void EmitDescribeError (void);
3115 EmitSetTypes - write out the set types used during error recovery
3118 static void EmitSetTypes (void);
3121 EmitSupport - generates the support routines.
3124 static void EmitSupport (void);
3127 DisposeSetDesc - dispose of the set list, s.
3130 static void DisposeSetDesc (pge_SetDesc
*s
);
3136 static unsigned int OptionalFactor (pge_FactorDesc f
);
3139 OptionalTerm - returns TRUE if the term maybe empty.
3142 static unsigned int OptionalTerm (pge_TermDesc t
);
3145 OptionalExpression -
3148 static unsigned int OptionalExpression (pge_ExpressionDesc e
);
3151 OptionalStatement - returns FALSE if statement, s, does not have a optional ambiguity.
3154 static unsigned int OptionalStatement (pge_StatementDesc s
);
3157 OptionalProduction -
3160 static unsigned int OptionalProduction (pge_ProductionDesc p
);
3166 static unsigned int CheckFirstFollow (pge_FactorDesc f
, pge_FactorDesc after
);
3169 ConstrainedEmptyFactor -
3172 static unsigned int ConstrainedEmptyFactor (pge_FactorDesc f
);
3175 ConstrainedEmptyTerm - returns TRUE if the term maybe empty.
3178 static unsigned int ConstrainedEmptyTerm (pge_TermDesc t
);
3181 ConstrainedEmptyExpression -
3184 static unsigned int ConstrainedEmptyExpression (pge_ExpressionDesc e
);
3187 ConstrainedEmptyStatement - returns FALSE if statement, s, does not have a optional ambiguity.
3190 static unsigned int ConstrainedEmptyStatement (pge_StatementDesc s
);
3193 ConstrainedEmptyProduction - returns TRUE if a problem exists with, p.
3196 static unsigned int ConstrainedEmptyProduction (pge_ProductionDesc p
);
3202 static void TestForLALR1 (pge_ProductionDesc p
);
3205 DoEpsilon - runs the epsilon interrelated rules
3208 static void DoEpsilon (pge_ProductionDesc p
);
3211 CheckComplete - checks that production, p, is complete.
3214 static void CheckComplete (pge_ProductionDesc p
);
3217 PostProcessRules - backpatch the ident to rule definitions and emit comments and code.
3220 static void PostProcessRules (void);
3223 DisplayHelp - display a summary help and then exit (0).
3226 static void DisplayHelp (void);
3232 static void ParseArgs (void);
3235 Init - initialize the modules data structures
3238 static void Init (void);
3242 DescribeStop - issues a message explaining what tokens were expected
3245 static DynamicStrings_String
DescribeStop (pge_SetOfStop stopset
)
3248 DynamicStrings_String str
;
3249 DynamicStrings_String message
;
3252 message
= DynamicStrings_InitString ((const char *) "", 0);
3253 if ((((1 << (bnflex_literaltok
-bnflex_identtok
)) & (stopset
)) != 0))
3255 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "literal", 7)));
3258 if ((((1 << (bnflex_identtok
-bnflex_identtok
)) & (stopset
)) != 0))
3260 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "identifier", 10)));
3263 if ((((1 << (bnflex_FNBtok
-bnflex_identtok
)) & (stopset
)) != 0))
3265 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "FNB", 3)));
3268 if ((((1 << (bnflex_BNFtok
-bnflex_identtok
)) & (stopset
)) != 0))
3270 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "BNF", 3)));
3273 if ((((1 << (bnflex_epsilontok
-bnflex_identtok
)) & (stopset
)) != 0))
3275 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "epsilon", 7)));
3278 if ((((1 << (bnflex_followtok
-bnflex_identtok
)) & (stopset
)) != 0))
3280 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "follow", 6)));
3283 if ((((1 << (bnflex_firsttok
-bnflex_identtok
)) & (stopset
)) != 0))
3285 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "first", 5)));
3288 if ((((1 << (bnflex_specialtok
-bnflex_identtok
)) & (stopset
)) != 0))
3290 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "special", 7)));
3293 if ((((1 << (bnflex_tokentok
-bnflex_identtok
)) & (stopset
)) != 0))
3295 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "token", 5)));
3298 if ((((1 << (bnflex_declarationtok
-bnflex_identtok
)) & (stopset
)) != 0))
3300 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "declaration", 11)));
3303 if ((((1 << (bnflex_endtok
-bnflex_identtok
)) & (stopset
)) != 0))
3305 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "end", 3)));
3308 if ((((1 << (bnflex_rulestok
-bnflex_identtok
)) & (stopset
)) != 0))
3310 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "rules", 5)));
3313 if ((((1 << (bnflex_begintok
-bnflex_identtok
)) & (stopset
)) != 0))
3315 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "begin", 5)));
3318 if ((((1 << (bnflex_moduletok
-bnflex_identtok
)) & (stopset
)) != 0))
3320 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "module", 6)));
3323 if ((((1 << (bnflex_dquotetok
-bnflex_identtok
)) & (stopset
)) != 0))
3325 message
= DynamicStrings_ConCatChar (DynamicStrings_ConCatChar (DynamicStrings_ConCatChar (DynamicStrings_ConCatChar (DynamicStrings_ConCatChar (message
, ' '), '`'), '"'), '\''), ',');
3328 if ((((1 << (bnflex_squotetok
-bnflex_identtok
)) & (stopset
)) != 0))
3330 message
= DynamicStrings_ConCatChar (DynamicStrings_ConCatChar (DynamicStrings_ConCatChar (DynamicStrings_ConCatChar (DynamicStrings_ConCatChar (message
, ' '), '"'), '\''), '"'), ',');
3333 if ((((1 << (bnflex_symfunctok
-bnflex_identtok
)) & (stopset
)) != 0))
3335 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "symfunc", 7)));
3338 if ((((1 << (bnflex_tfunctok
-bnflex_identtok
)) & (stopset
)) != 0))
3340 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "tokenfunc", 9)));
3343 if ((((1 << (bnflex_errortok
-bnflex_identtok
)) & (stopset
)) != 0))
3345 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "error", 5)));
3348 if ((((1 << (bnflex_gretok
-bnflex_identtok
)) & (stopset
)) != 0))
3350 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) ">", 1)));
3353 if ((((1 << (bnflex_lesstok
-bnflex_identtok
)) & (stopset
)) != 0))
3355 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "<", 1)));
3358 if ((((1 << (bnflex_rparatok
-bnflex_identtok
)) & (stopset
)) != 0))
3360 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) ")", 1)));
3363 if ((((1 << (bnflex_lparatok
-bnflex_identtok
)) & (stopset
)) != 0))
3365 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "(", 1)));
3368 if ((((1 << (bnflex_rcparatok
-bnflex_identtok
)) & (stopset
)) != 0))
3370 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "}", 1)));
3373 if ((((1 << (bnflex_lcparatok
-bnflex_identtok
)) & (stopset
)) != 0))
3375 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "{", 1)));
3378 if ((((1 << (bnflex_rsparatok
-bnflex_identtok
)) & (stopset
)) != 0))
3380 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "]", 1)));
3383 if ((((1 << (bnflex_lsparatok
-bnflex_identtok
)) & (stopset
)) != 0))
3385 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "[", 1)));
3388 if ((((1 << (bnflex_bartok
-bnflex_identtok
)) & (stopset
)) != 0))
3390 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "|", 1)));
3393 if ((((1 << (bnflex_rbecomestok
-bnflex_identtok
)) & (stopset
)) != 0))
3395 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "=:", 2)));
3398 if ((((1 << (bnflex_lbecomestok
-bnflex_identtok
)) & (stopset
)) != 0))
3400 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) ":=", 2)));
3403 if ((((1 << (bnflex_codetok
-bnflex_identtok
)) & (stopset
)) != 0))
3405 message
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (message
, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "%", 1)));
3408 if ((((1 << (bnflex_eoftok
-bnflex_identtok
)) & (stopset
)) != 0))
3410 /* eoftok has no token name (needed to generate error messages) */
3413 str
= DynamicStrings_InitString ((const char *) " syntax error", 13);
3414 message
= DynamicStrings_KillString (message
);
3418 /* avoid dangling else. */
3419 str
= DynamicStrings_ConCat (message
, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) " missing ", 9)));
3423 /* avoid dangling else. */
3424 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) " expecting one of", 17), message
);
3425 message
= DynamicStrings_KillString (message
);
3428 /* static analysis guarentees a RETURN statement will be used before here. */
3429 __builtin_unreachable ();
3434 DescribeError - issues a message explaining what tokens were expected
3437 static void DescribeError (void)
3439 DynamicStrings_String str
;
3441 str
= DynamicStrings_InitString ((const char *) "", 0);
3442 switch (bnflex_GetCurrentTokenType ())
3444 case bnflex_literaltok
:
3445 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found literal", 27), DynamicStrings_Mark (str
));
3448 case bnflex_identtok
:
3449 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found identifier", 30), DynamicStrings_Mark (str
));
3453 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found FNB", 23), DynamicStrings_Mark (str
));
3457 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found BNF", 23), DynamicStrings_Mark (str
));
3460 case bnflex_epsilontok
:
3461 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found epsilon", 27), DynamicStrings_Mark (str
));
3464 case bnflex_followtok
:
3465 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found follow", 26), DynamicStrings_Mark (str
));
3468 case bnflex_firsttok
:
3469 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found first", 25), DynamicStrings_Mark (str
));
3472 case bnflex_specialtok
:
3473 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found special", 27), DynamicStrings_Mark (str
));
3476 case bnflex_tokentok
:
3477 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found token", 25), DynamicStrings_Mark (str
));
3480 case bnflex_declarationtok
:
3481 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found declaration", 31), DynamicStrings_Mark (str
));
3485 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found end", 23), DynamicStrings_Mark (str
));
3488 case bnflex_rulestok
:
3489 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found rules", 25), DynamicStrings_Mark (str
));
3492 case bnflex_begintok
:
3493 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found begin", 25), DynamicStrings_Mark (str
));
3496 case bnflex_moduletok
:
3497 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found module", 26), DynamicStrings_Mark (str
));
3500 case bnflex_dquotetok
:
3501 str
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (DynamicStrings_ConCatChar (DynamicStrings_InitString ((const char *) "syntax error, found '", 21), '"'), '\''), DynamicStrings_Mark (str
));
3504 case bnflex_squotetok
:
3505 str
= DynamicStrings_ConCat (DynamicStrings_ConCatChar (DynamicStrings_ConCatChar (DynamicStrings_InitString ((const char *) "syntax error, found \"", 21), '\''), '"'), DynamicStrings_Mark (str
));
3508 case bnflex_symfunctok
:
3509 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found symfunc", 27), DynamicStrings_Mark (str
));
3512 case bnflex_tfunctok
:
3513 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found tokenfunc", 29), DynamicStrings_Mark (str
));
3516 case bnflex_errortok
:
3517 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found error", 25), DynamicStrings_Mark (str
));
3521 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found >", 21), DynamicStrings_Mark (str
));
3524 case bnflex_lesstok
:
3525 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found <", 21), DynamicStrings_Mark (str
));
3528 case bnflex_rparatok
:
3529 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found )", 21), DynamicStrings_Mark (str
));
3532 case bnflex_lparatok
:
3533 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found (", 21), DynamicStrings_Mark (str
));
3536 case bnflex_rcparatok
:
3537 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found }", 21), DynamicStrings_Mark (str
));
3540 case bnflex_lcparatok
:
3541 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found {", 21), DynamicStrings_Mark (str
));
3544 case bnflex_rsparatok
:
3545 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found ]", 21), DynamicStrings_Mark (str
));
3548 case bnflex_lsparatok
:
3549 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found [", 21), DynamicStrings_Mark (str
));
3553 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found |", 21), DynamicStrings_Mark (str
));
3556 case bnflex_rbecomestok
:
3557 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found =:", 22), DynamicStrings_Mark (str
));
3560 case bnflex_lbecomestok
:
3561 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found :=", 22), DynamicStrings_Mark (str
));
3564 case bnflex_codetok
:
3565 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found %", 21), DynamicStrings_Mark (str
));
3569 str
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "syntax error, found ", 20), DynamicStrings_Mark (str
));
3576 PushBackInput_WarnString (str
);
3581 AddEntry - adds an entry into, t, containing [def:value].
3584 static void AddEntry (SymbolKey_SymbolTree
*t
, NameKey_Name def
, NameKey_Name value
)
3586 if (SymbolKey_ContainsSymKey ((*t
), def
))
3588 WarnError1 ((const char *) "already seen a definition for token '%s'", 40, def
);
3592 SymbolKey_PutSymKey ((*t
), def
, value
);
3598 Format1 - converts string, src, into, dest, together with encapsulated
3599 entity, n. It only formats the first %s or %d with n.
3602 static void Format1 (const char *src_
, unsigned int _src_high
, unsigned int n
, char *dest
, unsigned int _dest_high
)
3604 typedef struct Format1__T12_a Format1__T12
;
3606 struct Format1__T12_a
{ char array
[MaxString
+1]; };
3607 unsigned int HighSrc
;
3608 unsigned int HighDest
;
3612 char src
[_src_high
+1];
3614 /* make a local copy of each unbounded array. */
3615 memcpy (src
, src_
, _src_high
+1);
3617 HighSrc
= StrLib_StrLen ((const char *) src
, _src_high
);
3618 HighDest
= _dest_high
;
3621 while ((((i
< HighSrc
) && (src
[i
] != ASCII_nul
)) && (j
< HighDest
)) && (src
[i
] != '%'))
3627 if ((((i
+1) < HighSrc
) && (src
[i
] == '%')) && (j
< HighDest
))
3629 /* avoid gcc warning by using compound statement even if not strictly necessary. */
3630 if (src
[i
+1] == 's')
3632 dest
[j
] = ASCII_nul
;
3633 NameKey_GetKey (n
, (char *) &str
.array
[0], MaxString
);
3634 StrLib_StrConCat ((const char *) dest
, _dest_high
, (const char *) &str
.array
[0], MaxString
, (char *) dest
, _dest_high
);
3635 j
= StrLib_StrLen ((const char *) dest
, _dest_high
);
3638 else if (src
[i
+1] == 'd')
3640 /* avoid dangling else. */
3641 dest
[j
] = ASCII_nul
;
3642 NumberIO_CardToStr (n
, 0, (char *) &str
.array
[0], MaxString
);
3643 StrLib_StrConCat ((const char *) dest
, _dest_high
, (const char *) &str
.array
[0], MaxString
, (char *) dest
, _dest_high
);
3644 j
= StrLib_StrLen ((const char *) dest
, _dest_high
);
3649 /* avoid dangling else. */
3655 /* and finish off copying src into dest */
3656 while (((i
< HighSrc
) && (src
[i
] != ASCII_nul
)) && (j
< HighDest
))
3664 dest
[j
] = ASCII_nul
;
3673 static void WarnError1 (const char *a_
, unsigned int _a_high
, unsigned int n
)
3675 typedef struct WarnError1__T13_a WarnError1__T13
;
3677 struct WarnError1__T13_a
{ char array
[MaxString
+1]; };
3678 WarnError1__T13 line
;
3681 /* make a local copy of each unbounded array. */
3682 memcpy (a
, a_
, _a_high
+1);
3684 Format1 ((const char *) a
, _a_high
, n
, (char *) &line
.array
[0], MaxString
);
3685 PushBackInput_WarnError ((const char *) &line
.array
[0], MaxString
);
3693 static void PrettyFollow (const char *start_
, unsigned int _start_high
, const char *end_
, unsigned int _end_high
, pge_FollowDesc f
)
3695 char start
[_start_high
+1];
3696 char end
[_end_high
+1];
3698 /* make a local copy of each unbounded array. */
3699 memcpy (start
, start_
, _start_high
+1);
3700 memcpy (end
, end_
, _end_high
+1);
3704 Output_WriteString ((const char *) start
, _start_high
);
3709 Output_WriteString ((const char *) "followset defined as:", 21);
3710 EmitSet (f
->follow
, static_cast<unsigned int> (0), static_cast<unsigned int> (0));
3712 switch (f
->reachend
)
3715 Output_WriteString ((const char *) " [E]", 4);
3719 Output_WriteString ((const char *) " [C]", 4);
3723 Output_WriteString ((const char *) " [U]", 4);
3733 Output_WriteString ((const char *) " [e]", 4);
3740 Output_WriteString ((const char *) " [u]", 4);
3748 Output_WriteString ((const char *) end
, _end_high
);
3754 NewFollow - creates a new follow descriptor and returns the data structure.
3757 static pge_FollowDesc
NewFollow (void)
3761 Storage_ALLOCATE ((void **) &f
, sizeof (pge__T6
));
3763 f
->reachend
= pge_unknown
;
3764 f
->epsilon
= pge_unknown
;
3766 /* static analysis guarentees a RETURN statement will be used before here. */
3767 __builtin_unreachable ();
3772 AssignEpsilon - assigns the epsilon value and sets the epsilon to value,
3773 providing condition is TRUE.
3776 static void AssignEpsilon (unsigned int condition
, pge_FollowDesc f
, pge_TraverseResult value
)
3778 if ((condition
&& (value
!= pge_unknown
)) && (f
->epsilon
== pge_unknown
))
3787 GetEpsilon - returns the value of epsilon
3790 static pge_TraverseResult
GetEpsilon (pge_FollowDesc f
)
3794 Debug_Halt ((const char *) "why is the follow info NIL?", 27, 596, (const char *) "m2/gm2-auto/pge.mod", 19);
3800 ReturnException ("m2/gm2-auto/pge.mod", 1, 7);
3801 __builtin_unreachable ();
3806 AssignReachEnd - assigns the reachend value providing that, condition, is TRUE.
3809 static void AssignReachEnd (unsigned int condition
, pge_FollowDesc f
, pge_TraverseResult value
)
3813 if ((f
->reachend
== pge_unknown
) && (value
!= pge_unknown
))
3815 f
->reachend
= value
;
3823 GetReachEnd - returns the value of reachend
3826 static pge_TraverseResult
GetReachEnd (pge_FollowDesc f
)
3830 Debug_Halt ((const char *) "why is the follow info NIL?", 27, 630, (const char *) "m2/gm2-auto/pge.mod", 19);
3836 ReturnException ("m2/gm2-auto/pge.mod", 1, 7);
3837 __builtin_unreachable ();
3842 AssignFollow - assigns the follow set and sets the calcfollow to TRUE.
3845 static void AssignFollow (pge_FollowDesc f
, pge_SetDesc s
)
3849 Debug_Halt ((const char *) "why are we reassigning this follow set?", 39, 646, (const char *) "m2/gm2-auto/pge.mod", 19);
3852 f
->calcfollow
= TRUE
;
3857 GetFollow - returns the follow set.
3860 static pge_SetDesc
GetFollow (pge_FollowDesc f
)
3864 Debug_Halt ((const char *) "why is the follow info NIL?", 27, 662, (const char *) "m2/gm2-auto/pge.mod", 19);
3874 Debug_Halt ((const char *) "not calculated the follow set yet..", 35, 669, (const char *) "m2/gm2-auto/pge.mod", 19);
3877 ReturnException ("m2/gm2-auto/pge.mod", 1, 7);
3878 __builtin_unreachable ();
3883 NewProduction - creates a new production and returns the data structure.
3886 static pge_ProductionDesc
NewProduction (void)
3888 pge_ProductionDesc p
;
3890 Storage_ALLOCATE ((void **) &p
, sizeof (pge__T2
));
3891 if (TailProduction
!= NULL
)
3893 TailProduction
->next
= p
;
3896 if (HeadProduction
== NULL
)
3901 p
->statement
= NULL
;
3903 p
->firstsolved
= FALSE
;
3904 p
->followinfo
= NewFollow ();
3905 p
->line
= PushBackInput_GetCurrentLine ();
3906 p
->description
= NameKey_NulName
;
3908 /* static analysis guarentees a RETURN statement will be used before here. */
3909 __builtin_unreachable ();
3917 static pge_FactorDesc
NewFactor (void)
3921 Storage_ALLOCATE ((void **) &f
, sizeof (pge__T5
));
3923 f
->followinfo
= NewFollow ();
3924 f
->line
= PushBackInput_GetCurrentLine ();
3926 /* static analysis guarentees a RETURN statement will be used before here. */
3927 __builtin_unreachable ();
3932 NewTerm - returns a new term.
3935 static pge_TermDesc
NewTerm (void)
3939 Storage_ALLOCATE ((void **) &t
, sizeof (pge_termdesc
));
3941 t
->followinfo
= NewFollow ();
3943 t
->line
= PushBackInput_GetCurrentLine ();
3945 /* static analysis guarentees a RETURN statement will be used before here. */
3946 __builtin_unreachable ();
3951 NewExpression - returns a new expression.
3954 static pge_ExpressionDesc
NewExpression (void)
3956 pge_ExpressionDesc e
;
3958 Storage_ALLOCATE ((void **) &e
, sizeof (pge__T4
));
3960 e
->followinfo
= NewFollow ();
3961 e
->line
= PushBackInput_GetCurrentLine ();
3963 /* static analysis guarentees a RETURN statement will be used before here. */
3964 __builtin_unreachable ();
3969 NewStatement - returns a new statement.
3972 static pge_StatementDesc
NewStatement (void)
3974 pge_StatementDesc s
;
3976 Storage_ALLOCATE ((void **) &s
, sizeof (pge__T3
));
3979 s
->followinfo
= NewFollow ();
3980 s
->line
= PushBackInput_GetCurrentLine ();
3982 /* static analysis guarentees a RETURN statement will be used before here. */
3983 __builtin_unreachable ();
3988 NewSetDesc - creates a new set description and returns the data structure.
3991 static pge_SetDesc
NewSetDesc (void)
3995 Storage_ALLOCATE ((void **) &s
, sizeof (pge__T7
));
3998 /* static analysis guarentees a RETURN statement will be used before here. */
3999 __builtin_unreachable ();
4004 NewCodeDesc - creates a new code descriptor and initializes all fields to zero.
4007 static pge_CodeDesc
NewCodeDesc (void)
4011 Storage_ALLOCATE ((void **) &c
, sizeof (pge__T8
));
4014 c
->line
= PushBackInput_GetCurrentLine ();
4016 /* static analysis guarentees a RETURN statement will be used before here. */
4017 __builtin_unreachable ();
4022 CodeFragmentPrologue - consumes code text up to a "%" after a newline.
4025 static void CodeFragmentPrologue (void)
4027 LinePrologue
= PushBackInput_GetCurrentLine ();
4028 GetCodeFragment (&CodePrologue
);
4033 CodeFragmentEpilogue - consumes code text up to a "%" after a newline.
4036 static void CodeFragmentEpilogue (void)
4038 LineEpilogue
= PushBackInput_GetCurrentLine ();
4039 GetCodeFragment (&CodeEpilogue
);
4044 CodeFragmentDeclaration - consumes code text up to a "%" after a newline.
4047 static void CodeFragmentDeclaration (void)
4049 LineDeclaration
= PushBackInput_GetCurrentLine ();
4050 GetCodeFragment (&CodeDeclaration
);
4055 GetCodeFragment - collects the code fragment up until ^ %
4058 static void GetCodeFragment (pge_CodeHunk
*h
)
4065 while (((bnflex_PutChar (bnflex_GetChar ())) != '%') && ((bnflex_PutChar (bnflex_GetChar ())) != ASCII_nul
))
4068 while (((bnflex_PutChar (bnflex_GetChar ())) != ASCII_nul
) && ((bnflex_PutChar (bnflex_GetChar ())) != ASCII_lf
))
4070 (*h
) = Add (h
, bnflex_GetChar (), &i
);
4072 if ((bnflex_PutChar (bnflex_GetChar ())) == ASCII_lf
)
4074 /* consume line feed */
4075 (*h
) = Add (h
, bnflex_GetChar (), &i
);
4076 ch
= bnflex_PutChar (ASCII_lf
);
4078 else if ((bnflex_PutChar (bnflex_GetChar ())) == ASCII_nul
)
4080 /* avoid dangling else. */
4081 ch
= bnflex_PutChar (ASCII_nul
);
4082 ch
= bnflex_PutChar (ASCII_lf
);
4086 /* avoid dangling else. */
4087 ch
= bnflex_PutChar (bnflex_PutChar (bnflex_GetChar ()));
4089 } while (! ((bnflex_GetChar ()) == ASCII_lf
));
4091 if ((bnflex_PutChar (bnflex_GetChar ())) == '%')
4093 (*h
) = Add (h
, ASCII_nul
, &i
);
4094 ch
= bnflex_PutChar (' '); /* to give the following token % a delimiter infront of it */
4095 bnflex_AdvanceToken (); /* to give the following token % a delimiter infront of it */
4099 PushBackInput_WarnError ((const char *) "expecting % to terminate code fragment, found end of file", 57);
4105 WriteCodeHunkList - writes the CodeHunk list in the correct order.
4108 static void WriteCodeHunkList (pge_CodeHunk l
)
4112 OnLineStart
= FALSE
;
4114 WriteCodeHunkList (l
->next
);
4115 Output_WriteString ((const char *) &l
->codetext
.array
[0], MaxCodeHunkLength
);
4121 WriteIndent - writes, n, spaces.
4124 static void WriteIndent (unsigned int n
)
4131 OnLineStart
= FALSE
;
4139 static void CheckWrite (char ch
, unsigned int *curpos
, unsigned int left
, unsigned int *seentext
)
4145 (*seentext
) = FALSE
;
4156 WriteStringIndent - writes a string but it will try and remove upto indent spaces
4160 static void WriteStringIndent (const char *a_
, unsigned int _a_high
, unsigned int indent
, unsigned int *curpos
, unsigned int left
, unsigned int *seentext
)
4166 /* make a local copy of each unbounded array. */
4167 memcpy (a
, a_
, _a_high
+1);
4170 l
= StrLib_StrLen ((const char *) a
, _a_high
);
4175 CheckWrite (a
[i
], curpos
, left
, seentext
);
4181 /* ignore space for now */
4186 if ((*curpos
) >= indent
)
4188 WriteIndent ((*curpos
)-indent
);
4191 CheckWrite (a
[i
], curpos
, left
, seentext
);
4200 WriteCodeHunkListIndent - writes the CodeHunk list in the correct order
4201 but it removes up to indent spaces if they exist.
4204 static void WriteCodeHunkListIndent (pge_CodeHunk l
, unsigned int indent
, unsigned int *curpos
, unsigned int left
, unsigned int *seentext
)
4209 WriteCodeHunkListIndent (l
->next
, indent
, curpos
, left
, seentext
);
4210 WriteStringIndent ((const char *) &l
->codetext
.array
[0], MaxCodeHunkLength
, indent
, curpos
, left
, seentext
);
4216 Add - adds a character to a code hunk and creates another code hunk if necessary.
4219 static pge_CodeHunk
Add (pge_CodeHunk
*p
, char ch
, unsigned int *i
)
4223 if (((*p
) == NULL
) || ((*i
) > MaxCodeHunkLength
))
4225 Storage_ALLOCATE ((void **) &q
, sizeof (pge__T9
));
4227 q
->codetext
.array
[0] = ch
;
4233 (*p
)->codetext
.array
[(*i
)] = ch
;
4237 /* static analysis guarentees a RETURN statement will be used before here. */
4238 __builtin_unreachable ();
4243 ConsHunk - combine two possible code hunks.
4246 static void ConsHunk (pge_CodeHunk
*p
, pge_CodeHunk q
)
4253 while (r
->next
!= NULL
)
4264 GetName - returns the next symbol which is checked for a legal name.
4267 static NameKey_Name
GetName (void)
4271 if (bnflex_IsReserved (bnflex_GetCurrentToken ()))
4273 PushBackInput_WarnError ((const char *) "expecting a name and found a reserved word", 42);
4274 bnflex_AdvanceToken (); /* move on to another token */
4275 return NameKey_NulName
; /* move on to another token */
4279 name
= bnflex_GetCurrentToken ();
4280 bnflex_AdvanceToken ();
4283 /* static analysis guarentees a RETURN statement will be used before here. */
4284 __builtin_unreachable ();
4289 SyntaxError - after a syntax error we skip all tokens up until we reach
4293 static void SyntaxError (pge_SetOfStop stop
)
4299 StrIO_WriteString ((const char *) "skipping token *** ", 19);
4301 while (! ((((1 << (bnflex_GetCurrentTokenType ()-bnflex_identtok
)) & (stop
)) != 0)))
4303 bnflex_AdvanceToken ();
4307 StrIO_WriteString ((const char *) " ***", 4);
4318 static void SyntaxCheck (pge_SetOfStop stop
)
4320 if (! ((((1 << (bnflex_GetCurrentTokenType ()-bnflex_identtok
)) & (stop
)) != 0)))
4331 static void Expect (bnflex_TokenType t
, pge_SetOfStop stop
)
4333 if ((bnflex_GetCurrentTokenType ()) == t
)
4335 bnflex_AdvanceToken ();
4346 Ident - error checking varient of Ident
4349 static void Ident (pge_SetOfStop stop
)
4351 if ((bnflex_GetCurrentTokenType ()) == bnflex_identtok
)
4353 Storage_ALLOCATE ((void **) &CurrentIdent
, sizeof (pge__T1
));
4354 CurrentIdent
->definition
= NULL
;
4355 CurrentIdent
->name
= GetName ();
4356 CurrentIdent
->line
= PushBackInput_GetCurrentLine ();
4362 Modula2Code - error checking varient of Modula2Code
4365 static void Modula2Code (pge_SetOfStop stop
)
4371 unsigned int position
;
4373 line
= PushBackInput_GetCurrentLine ();
4374 bnflex_PushBackToken (bnflex_GetCurrentToken ());
4375 position
= PushBackInput_GetColumnPosition ();
4377 bnflex_SkipWhite ();
4378 while (((bnflex_PutChar (bnflex_GetChar ())) != '%') && ((bnflex_PutChar (bnflex_GetChar ())) != ASCII_nul
))
4380 if ((bnflex_PutChar (bnflex_GetChar ())) == '"')
4382 /* avoid dangling else. */
4384 p
= Add (&p
, bnflex_GetChar (), &i
);
4385 } while (! (((bnflex_PutChar (bnflex_GetChar ())) == '"') || ((bnflex_PutChar (bnflex_GetChar ())) == ASCII_nul
)));
4386 p
= Add (&p
, '"', &i
);
4387 if (((bnflex_PutChar (bnflex_GetChar ())) == '"') && ((bnflex_GetChar ()) == '"'))
4390 else if ((bnflex_PutChar (bnflex_GetChar ())) == '\'')
4392 /* avoid dangling else. */
4394 p
= Add (&p
, bnflex_GetChar (), &i
);
4395 } while (! (((bnflex_PutChar (bnflex_GetChar ())) == '\'') || ((bnflex_PutChar (bnflex_GetChar ())) == ASCII_nul
)));
4396 p
= Add (&p
, '\'', &i
);
4397 if (((bnflex_PutChar (bnflex_GetChar ())) == '\'') && ((bnflex_GetChar ()) == '\''))
4400 else if (((bnflex_PutChar (bnflex_GetChar ())) == '\\') && ((bnflex_GetChar ()) == '\\'))
4402 /* avoid dangling else. */
4403 p
= Add (&p
, bnflex_GetChar (), &i
);
4405 else if ((bnflex_PutChar (bnflex_GetChar ())) != '%')
4407 /* avoid dangling else. */
4408 p
= Add (&p
, bnflex_GetChar (), &i
);
4411 p
= Add (&p
, ASCII_nul
, &i
);
4412 CurrentFactor
->type
= pge_m2
;
4413 CurrentFactor
->code
= NewCodeDesc ();
4414 CurrentFactor
->code
->code
= p
;
4415 CurrentFactor
->code
->indent
= position
;
4416 if ((bnflex_PutChar (' ')) == ' ')
4418 bnflex_AdvanceToken (); /* read the next token ready for the parser */
4419 if (! WasNoError
) /* read the next token ready for the parser */
4421 WarnError1 ((const char *) "error probably occurred before the start of inline code on line %d", 66, line
);
4427 StartModName := % ModuleName := GetName() ; ignore begintok CodeFragmentPrologue % =:
4430 static void StartModName (pge_SetOfStop stop
)
4432 ModuleName
= GetName ();
4433 CodeFragmentPrologue ();
4441 static void EndModName (pge_SetOfStop stop
)
4443 if (ModuleName
!= (GetName ()))
4445 PushBackInput_WarnError ((const char *) "expecting same module name at end as beginning", 46);
4447 /* ignore endtok as it consumes the token afterwards */
4448 CodeFragmentEpilogue ();
4453 DoDeclaration := % CodeFragmentDeclaration % =:
4456 static void DoDeclaration (pge_SetOfStop stop
)
4458 if (ModuleName
!= (GetName ()))
4460 PushBackInput_WarnError ((const char *) "expecting same module name in declaration as in the beginning", 61);
4462 /* ignore begintok as it consumes the token afterwards */
4463 CodeFragmentDeclaration ();
4469 % LastLiteral := GetCurrentToken() ;
4473 first symbols:literaltok
4478 static void CollectLiteral (pge_SetOfStop stopset
)
4480 LastLiteral
= bnflex_GetCurrentToken (); /* */
4481 bnflex_AdvanceToken ();
4487 % CurrentSetDesc := NewSetDesc() ;
4488 WITH CurrentSetDesc^ DO
4490 string := GetCurrentToken() ;
4492 IF NOT ContainsSymKey(Values, GetCurrentToken())
4494 AddEntry(Values, GetCurrentToken(), LargestValue) ;
4495 AddEntry(ReverseValues, Name(LargestValue), GetCurrentToken()) ;
4496 AddEntry(Aliases, GetCurrentToken(), GetCurrentToken()) ;
4497 AddEntry(ReverseAliases, GetCurrentToken(), GetCurrentToken()) ;
4503 first symbols:identtok
4508 static void CollectTok (pge_SetOfStop stopset
)
4510 CurrentSetDesc
= NewSetDesc (); /* */
4511 CurrentSetDesc
->type
= pge_tokel
;
4512 CurrentSetDesc
->string
= bnflex_GetCurrentToken ();
4513 if (! (SymbolKey_ContainsSymKey (Values
, bnflex_GetCurrentToken ())))
4515 AddEntry (&Values
, bnflex_GetCurrentToken (), LargestValue
);
4516 AddEntry (&ReverseValues
, (NameKey_Name
) (LargestValue
), bnflex_GetCurrentToken ());
4517 AddEntry (&Aliases
, bnflex_GetCurrentToken (), bnflex_GetCurrentToken ());
4518 AddEntry (&ReverseAliases
, bnflex_GetCurrentToken (), bnflex_GetCurrentToken ());
4521 bnflex_AdvanceToken ();
4527 % AddEntry(Aliases, LastLiteral, GetCurrentToken()) ;
4528 AddEntry(ReverseAliases, GetCurrentToken(), LastLiteral) ;
4529 AddEntry(Values, GetCurrentToken(), LargestValue) ;
4530 AddEntry(ReverseValues, Name(LargestValue), GetCurrentToken()) ;
4535 first symbols:identtok
4540 static void DefineToken (pge_SetOfStop stopset
)
4542 AddEntry (&Aliases
, LastLiteral
, bnflex_GetCurrentToken ()); /* */
4543 AddEntry (&ReverseAliases
, bnflex_GetCurrentToken (), LastLiteral
);
4544 AddEntry (&Values
, bnflex_GetCurrentToken (), LargestValue
);
4545 AddEntry (&ReverseValues
, (NameKey_Name
) (LargestValue
), bnflex_GetCurrentToken ());
4547 bnflex_AdvanceToken ();
4552 Rules := '%' 'rules' { Defs } ExtBNF
4554 first symbols:codetok
4559 static void Rules (pge_SetOfStop stopset
)
4561 Expect (bnflex_codetok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_rulestok
-bnflex_identtok
))));
4562 Expect (bnflex_rulestok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_symfunctok
-bnflex_identtok
)) | (1 << (bnflex_tfunctok
-bnflex_identtok
)) | (1 << (bnflex_errortok
-bnflex_identtok
)) | (1 << (bnflex_tokentok
-bnflex_identtok
)) | (1 << (bnflex_specialtok
-bnflex_identtok
)) | (1 << (bnflex_BNFtok
-bnflex_identtok
))));
4563 while ((((1 << (bnflex_GetCurrentTokenType ())) & ((unsigned int) ((1 << (bnflex_specialtok
)) | (1 << (bnflex_tokentok
)) | (1 << (bnflex_errortok
)) | (1 << (bnflex_tfunctok
)) | (1 << (bnflex_symfunctok
))))) != 0))
4565 Defs (stopset
|(pge_SetOfStop
) ((1 << (bnflex_BNFtok
-bnflex_identtok
)) | (1 << (bnflex_specialtok
-bnflex_identtok
)) | (1 << (bnflex_tokentok
-bnflex_identtok
)) | (1 << (bnflex_errortok
-bnflex_identtok
)) | (1 << (bnflex_tfunctok
-bnflex_identtok
)) | (1 << (bnflex_symfunctok
-bnflex_identtok
))));
4574 % VAR p: ProductionDesc ; %
4576 % p := NewProduction() ;
4577 p^.statement := NewStatement() ;
4578 p^.statement^.followinfo^.calcfollow := TRUE ;
4579 p^.statement^.followinfo^.epsilon := false ;
4580 p^.statement^.followinfo^.reachend := false ;
4581 p^.statement^.ident := CurrentIdent ;
4582 p^.statement^.expr := NIL ;
4583 p^.firstsolved := TRUE ;
4584 p^.followinfo^.calcfollow := TRUE ;
4585 p^.followinfo^.epsilon := false ;
4586 p^.followinfo^.reachend := false %
4587 First Follow [ 'epsilon'
4588 % p^.statement^.followinfo^.epsilon := true ; these are not used - but they are displayed when debugging
4589 p^.statement^.followinfo^.reachend := true ;
4590 p^.followinfo^.epsilon := true ;
4591 p^.followinfo^.reachend := true
4594 % p^.description := LastLiteral %
4597 first symbols:identtok
4602 static void Special (pge_SetOfStop stopset
)
4604 pge_ProductionDesc p
;
4606 Ident (stopset
|(pge_SetOfStop
) ((1 << (bnflex_firsttok
-bnflex_identtok
))));
4607 p
= NewProduction ();
4608 p
->statement
= NewStatement ();
4609 p
->statement
->followinfo
->calcfollow
= TRUE
;
4610 p
->statement
->followinfo
->epsilon
= pge_false
;
4611 p
->statement
->followinfo
->reachend
= pge_false
;
4612 p
->statement
->ident
= CurrentIdent
;
4613 p
->statement
->expr
= NULL
;
4614 p
->firstsolved
= TRUE
;
4615 p
->followinfo
->calcfollow
= TRUE
;
4616 p
->followinfo
->epsilon
= pge_false
;
4617 p
->followinfo
->reachend
= pge_false
;
4618 First (stopset
|(pge_SetOfStop
) ((1 << (bnflex_followtok
-bnflex_identtok
))));
4619 Follow (stopset
|(pge_SetOfStop
) ((1 << (bnflex_epsilontok
-bnflex_identtok
)) | (1 << (bnflex_squotetok
-bnflex_identtok
)) | (1 << (bnflex_dquotetok
-bnflex_identtok
))));
4620 if ((bnflex_GetCurrentTokenType ()) == bnflex_epsilontok
)
4622 Expect (bnflex_epsilontok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_dquotetok
-bnflex_identtok
)) | (1 << (bnflex_squotetok
-bnflex_identtok
))));
4623 p
->statement
->followinfo
->epsilon
= pge_true
; /* these are not used - but they are displayed when debugging */
4624 p
->statement
->followinfo
->reachend
= pge_true
; /* these are not used - but they are displayed when debugging */
4625 p
->followinfo
->epsilon
= pge_true
;
4626 p
->followinfo
->reachend
= pge_true
;
4628 if ((((1 << (bnflex_GetCurrentTokenType ())) & ((unsigned int) ((1 << (bnflex_dquotetok
)) | (1 << (bnflex_squotetok
))))) != 0))
4631 p
->description
= LastLiteral
;
4637 Factor := '%' Modula2Code '%' |
4639 % WITH CurrentFactor^ DO
4641 ident := CurrentIdent
4644 % WITH CurrentFactor^ DO
4646 string := LastLiteral ;
4647 IF GetSymKey(Aliases, LastLiteral)=NulName
4649 WarnError1('no token defined for literal %s', LastLiteral)
4653 % WITH CurrentFactor^ DO
4655 expr := NewExpression() ;
4656 CurrentExpression := expr ;
4658 Expression '}' | '['
4659 % WITH CurrentFactor^ DO
4661 expr := NewExpression() ;
4662 CurrentExpression := expr ;
4664 Expression ']' | '('
4665 % WITH CurrentFactor^ DO
4667 expr := NewExpression() ;
4668 CurrentExpression := expr ;
4672 first symbols:dquotetok, squotetok, lparatok, lsparatok, lcparatok, identtok, codetok
4677 static void Factor (pge_SetOfStop stopset
)
4679 if ((bnflex_GetCurrentTokenType ()) == bnflex_codetok
)
4681 Expect (bnflex_codetok
, stopset
);
4682 Modula2Code (stopset
|(pge_SetOfStop
) ((1 << (bnflex_codetok
-bnflex_identtok
))));
4683 Expect (bnflex_codetok
, stopset
);
4685 else if ((bnflex_GetCurrentTokenType ()) == bnflex_identtok
)
4687 /* avoid dangling else. */
4689 CurrentFactor
->type
= pge_id
;
4690 CurrentFactor
->ident
= CurrentIdent
;
4692 else if ((((1 << (bnflex_GetCurrentTokenType ())) & ((unsigned int) ((1 << (bnflex_dquotetok
)) | (1 << (bnflex_squotetok
))))) != 0))
4694 /* avoid dangling else. */
4696 CurrentFactor
->type
= pge_lit
;
4697 CurrentFactor
->string
= LastLiteral
;
4698 if ((SymbolKey_GetSymKey (Aliases
, LastLiteral
)) == NameKey_NulName
)
4700 WarnError1 ((const char *) "no token defined for literal %s", 31, LastLiteral
);
4703 else if ((bnflex_GetCurrentTokenType ()) == bnflex_lcparatok
)
4705 /* avoid dangling else. */
4706 Expect (bnflex_lcparatok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_lparatok
-bnflex_identtok
)) | (1 << (bnflex_lsparatok
-bnflex_identtok
)) | (1 << (bnflex_lcparatok
-bnflex_identtok
)) | (1 << (bnflex_identtok
-bnflex_identtok
)) | (1 << (bnflex_codetok
-bnflex_identtok
)) | (1 << (bnflex_dquotetok
-bnflex_identtok
)) | (1 << (bnflex_squotetok
-bnflex_identtok
))));
4707 CurrentFactor
->type
= pge_mult
;
4708 CurrentFactor
->expr
= NewExpression ();
4709 CurrentExpression
= CurrentFactor
->expr
;
4710 Expression (stopset
|(pge_SetOfStop
) ((1 << (bnflex_rcparatok
-bnflex_identtok
))));
4711 Expect (bnflex_rcparatok
, stopset
);
4713 else if ((bnflex_GetCurrentTokenType ()) == bnflex_lsparatok
)
4715 /* avoid dangling else. */
4716 Expect (bnflex_lsparatok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_lparatok
-bnflex_identtok
)) | (1 << (bnflex_lsparatok
-bnflex_identtok
)) | (1 << (bnflex_lcparatok
-bnflex_identtok
)) | (1 << (bnflex_identtok
-bnflex_identtok
)) | (1 << (bnflex_codetok
-bnflex_identtok
)) | (1 << (bnflex_dquotetok
-bnflex_identtok
)) | (1 << (bnflex_squotetok
-bnflex_identtok
))));
4717 CurrentFactor
->type
= pge_opt
;
4718 CurrentFactor
->expr
= NewExpression ();
4719 CurrentExpression
= CurrentFactor
->expr
;
4720 Expression (stopset
|(pge_SetOfStop
) ((1 << (bnflex_rsparatok
-bnflex_identtok
))));
4721 Expect (bnflex_rsparatok
, stopset
);
4723 else if ((bnflex_GetCurrentTokenType ()) == bnflex_lparatok
)
4725 /* avoid dangling else. */
4726 Expect (bnflex_lparatok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_lparatok
-bnflex_identtok
)) | (1 << (bnflex_lsparatok
-bnflex_identtok
)) | (1 << (bnflex_lcparatok
-bnflex_identtok
)) | (1 << (bnflex_identtok
-bnflex_identtok
)) | (1 << (bnflex_codetok
-bnflex_identtok
)) | (1 << (bnflex_dquotetok
-bnflex_identtok
)) | (1 << (bnflex_squotetok
-bnflex_identtok
))));
4727 CurrentFactor
->type
= pge_sub
;
4728 CurrentFactor
->expr
= NewExpression ();
4729 CurrentExpression
= CurrentFactor
->expr
;
4730 Expression (stopset
|(pge_SetOfStop
) ((1 << (bnflex_rparatok
-bnflex_identtok
))));
4731 Expect (bnflex_rparatok
, stopset
);
4735 /* avoid dangling else. */
4736 PushBackInput_WarnError ((const char *) "expecting one of: ( [ { \" single quote identifier %", 51);
4743 % VAR i: IdentDesc ; %
4745 % VAR p: ProductionDesc ; %
4747 % p := FindDefinition(CurrentIdent^.name) ;
4750 p := NewProduction()
4752 IF NOT ((p^.statement=NIL) OR (p^.statement^.expr=NIL))
4754 WarnError1('already declared rule %s', CurrentIdent^.name)
4757 i := CurrentIdent ; %
4759 % VAR e: ExpressionDesc ; %
4761 % e := NewExpression() ;
4762 CurrentExpression := e ; %
4764 % VAR s: StatementDesc ; %
4766 % s := NewStatement() ;
4772 % p^.statement := s ; %
4775 first symbols:identtok
4780 static void Statement (pge_SetOfStop stopset
)
4783 pge_ProductionDesc p
;
4784 pge_ExpressionDesc e
;
4785 pge_StatementDesc s
;
4787 Ident (stopset
|(pge_SetOfStop
) ((1 << (bnflex_lbecomestok
-bnflex_identtok
))));
4788 p
= FindDefinition (CurrentIdent
->name
);
4791 p
= NewProduction ();
4795 if (! ((p
->statement
== NULL
) || (p
->statement
->expr
== NULL
)))
4797 WarnError1 ((const char *) "already declared rule %s", 24, CurrentIdent
->name
);
4801 Expect (bnflex_lbecomestok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_lparatok
-bnflex_identtok
)) | (1 << (bnflex_lsparatok
-bnflex_identtok
)) | (1 << (bnflex_lcparatok
-bnflex_identtok
)) | (1 << (bnflex_identtok
-bnflex_identtok
)) | (1 << (bnflex_codetok
-bnflex_identtok
)) | (1 << (bnflex_dquotetok
-bnflex_identtok
)) | (1 << (bnflex_squotetok
-bnflex_identtok
))));
4802 e
= NewExpression ();
4803 CurrentExpression
= e
;
4804 s
= NewStatement ();
4807 Expression (stopset
|(pge_SetOfStop
) ((1 << (bnflex_rbecomestok
-bnflex_identtok
))));
4809 Expect (bnflex_rbecomestok
, stopset
);
4814 Defs := 'special' Special | 'token' Token |
4815 'error' ErrorProcedures |
4816 'tokenfunc' TokenProcedure |
4817 'symfunc' SymProcedure
4819 first symbols:symfunctok, tfunctok, errortok, tokentok, specialtok
4824 static void Defs (pge_SetOfStop stopset
)
4826 if ((bnflex_GetCurrentTokenType ()) == bnflex_specialtok
)
4828 Expect (bnflex_specialtok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_identtok
-bnflex_identtok
))));
4831 else if ((bnflex_GetCurrentTokenType ()) == bnflex_tokentok
)
4833 /* avoid dangling else. */
4834 Expect (bnflex_tokentok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_dquotetok
-bnflex_identtok
)) | (1 << (bnflex_squotetok
-bnflex_identtok
))));
4837 else if ((bnflex_GetCurrentTokenType ()) == bnflex_errortok
)
4839 /* avoid dangling else. */
4840 Expect (bnflex_errortok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_dquotetok
-bnflex_identtok
)) | (1 << (bnflex_squotetok
-bnflex_identtok
))));
4841 ErrorProcedures (stopset
);
4843 else if ((bnflex_GetCurrentTokenType ()) == bnflex_tfunctok
)
4845 /* avoid dangling else. */
4846 Expect (bnflex_tfunctok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_dquotetok
-bnflex_identtok
)) | (1 << (bnflex_squotetok
-bnflex_identtok
))));
4847 TokenProcedure (stopset
);
4849 else if ((bnflex_GetCurrentTokenType ()) == bnflex_symfunctok
)
4851 /* avoid dangling else. */
4852 Expect (bnflex_symfunctok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_dquotetok
-bnflex_identtok
)) | (1 << (bnflex_squotetok
-bnflex_identtok
))));
4853 SymProcedure (stopset
);
4857 /* avoid dangling else. */
4858 PushBackInput_WarnError ((const char *) "expecting one of: symfunc tokenfunc error token special", 55);
4864 ExtBNF := 'BNF' { Production } 'FNB'
4866 first symbols:BNFtok
4871 static void ExtBNF (pge_SetOfStop stopset
)
4873 Expect (bnflex_BNFtok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_FNBtok
-bnflex_identtok
)) | (1 << (bnflex_identtok
-bnflex_identtok
))));
4874 while ((bnflex_GetCurrentTokenType ()) == bnflex_identtok
)
4876 Production (stopset
|(pge_SetOfStop
) ((1 << (bnflex_FNBtok
-bnflex_identtok
)) | (1 << (bnflex_identtok
-bnflex_identtok
))));
4879 Expect (bnflex_FNBtok
, stopset
);
4884 Main := Header Decls Footer Rules
4886 first symbols:codetok
4891 static void Main (pge_SetOfStop stopset
)
4893 Header (stopset
|(pge_SetOfStop
) ((1 << (bnflex_codetok
-bnflex_identtok
))));
4894 Decls (stopset
|(pge_SetOfStop
) ((1 << (bnflex_codetok
-bnflex_identtok
))));
4895 Footer (stopset
|(pge_SetOfStop
) ((1 << (bnflex_codetok
-bnflex_identtok
))));
4901 Header := '%' 'module' StartModName
4903 first symbols:codetok
4908 static void Header (pge_SetOfStop stopset
)
4910 Expect (bnflex_codetok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_moduletok
-bnflex_identtok
))));
4911 Expect (bnflex_moduletok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_identtok
-bnflex_identtok
))));
4912 StartModName (stopset
);
4917 Decls := '%' 'declaration' DoDeclaration
4919 first symbols:codetok
4924 static void Decls (pge_SetOfStop stopset
)
4926 Expect (bnflex_codetok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_declarationtok
-bnflex_identtok
))));
4927 Expect (bnflex_declarationtok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_identtok
-bnflex_identtok
))));
4928 DoDeclaration (stopset
);
4933 Footer := '%' 'module' EndModName
4935 first symbols:codetok
4940 static void Footer (pge_SetOfStop stopset
)
4942 Expect (bnflex_codetok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_moduletok
-bnflex_identtok
))));
4943 Expect (bnflex_moduletok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_identtok
-bnflex_identtok
))));
4944 EndModName (stopset
);
4949 First := 'first' '{' { LitOrTokenOrIdent
4950 % WITH CurrentSetDesc^ DO
4951 next := TailProduction^.first ;
4953 TailProduction^.first := CurrentSetDesc
4957 first symbols:firsttok
4962 static void First (pge_SetOfStop stopset
)
4964 Expect (bnflex_firsttok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_lcparatok
-bnflex_identtok
))));
4965 Expect (bnflex_lcparatok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_rcparatok
-bnflex_identtok
)) | (1 << (bnflex_identtok
-bnflex_identtok
)) | (1 << (bnflex_lesstok
-bnflex_identtok
)) | (1 << (bnflex_dquotetok
-bnflex_identtok
)) | (1 << (bnflex_squotetok
-bnflex_identtok
))));
4966 while ((((1 << (bnflex_GetCurrentTokenType ())) & ((unsigned int) ((1 << (bnflex_lesstok
)) | (1 << (bnflex_identtok
)) | (1 << (bnflex_squotetok
)) | (1 << (bnflex_dquotetok
))))) != 0))
4968 LitOrTokenOrIdent (stopset
|(pge_SetOfStop
) ((1 << (bnflex_rcparatok
-bnflex_identtok
)) | (1 << (bnflex_lesstok
-bnflex_identtok
)) | (1 << (bnflex_identtok
-bnflex_identtok
)) | (1 << (bnflex_squotetok
-bnflex_identtok
)) | (1 << (bnflex_dquotetok
-bnflex_identtok
))));
4969 CurrentSetDesc
->next
= TailProduction
->first
;
4970 TailProduction
->first
= CurrentSetDesc
;
4973 Expect (bnflex_rcparatok
, stopset
);
4978 Follow := 'follow' '{' { LitOrTokenOrIdent
4979 % WITH CurrentSetDesc^ DO
4980 next := TailProduction^.followinfo^.follow ;
4982 TailProduction^.followinfo^.follow := CurrentSetDesc
4986 first symbols:followtok
4991 static void Follow (pge_SetOfStop stopset
)
4993 Expect (bnflex_followtok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_lcparatok
-bnflex_identtok
))));
4994 Expect (bnflex_lcparatok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_rcparatok
-bnflex_identtok
)) | (1 << (bnflex_identtok
-bnflex_identtok
)) | (1 << (bnflex_lesstok
-bnflex_identtok
)) | (1 << (bnflex_dquotetok
-bnflex_identtok
)) | (1 << (bnflex_squotetok
-bnflex_identtok
))));
4995 while ((((1 << (bnflex_GetCurrentTokenType ())) & ((unsigned int) ((1 << (bnflex_lesstok
)) | (1 << (bnflex_identtok
)) | (1 << (bnflex_squotetok
)) | (1 << (bnflex_dquotetok
))))) != 0))
4997 LitOrTokenOrIdent (stopset
|(pge_SetOfStop
) ((1 << (bnflex_rcparatok
-bnflex_identtok
)) | (1 << (bnflex_lesstok
-bnflex_identtok
)) | (1 << (bnflex_identtok
-bnflex_identtok
)) | (1 << (bnflex_squotetok
-bnflex_identtok
)) | (1 << (bnflex_dquotetok
-bnflex_identtok
))));
4998 CurrentSetDesc
->next
= TailProduction
->followinfo
->follow
;
4999 TailProduction
->followinfo
->follow
= CurrentSetDesc
;
5002 Expect (bnflex_rcparatok
, stopset
);
5007 LitOrTokenOrIdent := Literal
5008 % CurrentSetDesc := NewSetDesc() ;
5009 WITH CurrentSetDesc^ DO
5011 string := LastLiteral ;
5014 | '<' CollectTok '>' |
5016 % CurrentSetDesc := NewSetDesc() ;
5017 WITH CurrentSetDesc^ DO
5019 ident := CurrentIdent ;
5024 first symbols:dquotetok, squotetok, identtok, lesstok
5029 static void LitOrTokenOrIdent (pge_SetOfStop stopset
)
5031 if ((((1 << (bnflex_GetCurrentTokenType ())) & ((unsigned int) ((1 << (bnflex_dquotetok
)) | (1 << (bnflex_squotetok
))))) != 0))
5034 CurrentSetDesc
= NewSetDesc ();
5035 CurrentSetDesc
->type
= pge_litel
;
5036 CurrentSetDesc
->string
= LastLiteral
;
5038 else if ((bnflex_GetCurrentTokenType ()) == bnflex_lesstok
)
5040 /* avoid dangling else. */
5041 Expect (bnflex_lesstok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_identtok
-bnflex_identtok
))));
5042 CollectTok (stopset
|(pge_SetOfStop
) ((1 << (bnflex_gretok
-bnflex_identtok
))));
5043 Expect (bnflex_gretok
, stopset
);
5045 else if ((bnflex_GetCurrentTokenType ()) == bnflex_identtok
)
5047 /* avoid dangling else. */
5049 CurrentSetDesc
= NewSetDesc ();
5050 CurrentSetDesc
->type
= pge_idel
;
5051 CurrentSetDesc
->ident
= CurrentIdent
;
5055 /* avoid dangling else. */
5056 PushBackInput_WarnError ((const char *) "expecting one of: identifier < \" single quote", 45);
5062 Literal := '"' CollectLiteral '"' |
5063 "'" CollectLiteral "'"
5065 first symbols:squotetok, dquotetok
5070 static void Literal (pge_SetOfStop stopset
)
5072 if ((bnflex_GetCurrentTokenType ()) == bnflex_dquotetok
)
5074 Expect (bnflex_dquotetok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_literaltok
-bnflex_identtok
))));
5075 CollectLiteral (stopset
|(pge_SetOfStop
) ((1 << (bnflex_dquotetok
-bnflex_identtok
))));
5076 Expect (bnflex_dquotetok
, stopset
);
5078 else if ((bnflex_GetCurrentTokenType ()) == bnflex_squotetok
)
5080 /* avoid dangling else. */
5081 Expect (bnflex_squotetok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_literaltok
-bnflex_identtok
))));
5082 CollectLiteral (stopset
|(pge_SetOfStop
) ((1 << (bnflex_squotetok
-bnflex_identtok
))));
5083 Expect (bnflex_squotetok
, stopset
);
5087 /* avoid dangling else. */
5088 PushBackInput_WarnError ((const char *) "expecting one of: single quote \"", 32);
5094 Token := Literal DefineToken
5096 first symbols:dquotetok, squotetok
5101 static void Token (pge_SetOfStop stopset
)
5103 Literal (stopset
|(pge_SetOfStop
) ((1 << (bnflex_identtok
-bnflex_identtok
))));
5104 DefineToken (stopset
);
5109 ErrorProcedures := Literal
5110 % ErrorProcArray := LastLiteral %
5112 % ErrorProcString := LastLiteral %
5115 first symbols:dquotetok, squotetok
5120 static void ErrorProcedures (pge_SetOfStop stopset
)
5122 Literal (stopset
|(pge_SetOfStop
) ((1 << (bnflex_squotetok
-bnflex_identtok
)) | (1 << (bnflex_dquotetok
-bnflex_identtok
))));
5123 ErrorProcArray
= LastLiteral
;
5125 ErrorProcString
= LastLiteral
;
5130 TokenProcedure := Literal
5131 % TokenTypeProc := LastLiteral %
5134 first symbols:dquotetok, squotetok
5139 static void TokenProcedure (pge_SetOfStop stopset
)
5142 TokenTypeProc
= LastLiteral
;
5147 SymProcedure := Literal
5148 % SymIsProc := LastLiteral %
5151 first symbols:dquotetok, squotetok
5156 static void SymProcedure (pge_SetOfStop stopset
)
5159 SymIsProc
= LastLiteral
;
5164 Production := Statement
5166 first symbols:identtok
5171 static void Production (pge_SetOfStop stopset
)
5173 Statement (stopset
);
5179 % VAR t1, t2: TermDesc ;
5180 e : ExpressionDesc ; %
5182 % e := CurrentExpression ;
5184 CurrentTerm := t1 ; %
5195 first symbols:dquotetok, squotetok, lparatok, lsparatok, lcparatok, identtok, codetok
5200 static void Expression (pge_SetOfStop stopset
)
5204 pge_ExpressionDesc e
;
5206 e
= CurrentExpression
;
5209 Term (stopset
|(pge_SetOfStop
) ((1 << (bnflex_bartok
-bnflex_identtok
))));
5211 while ((bnflex_GetCurrentTokenType ()) == bnflex_bartok
)
5213 Expect (bnflex_bartok
, stopset
|(pge_SetOfStop
) ((1 << (bnflex_codetok
-bnflex_identtok
)) | (1 << (bnflex_identtok
-bnflex_identtok
)) | (1 << (bnflex_lcparatok
-bnflex_identtok
)) | (1 << (bnflex_lsparatok
-bnflex_identtok
)) | (1 << (bnflex_lparatok
-bnflex_identtok
)) | (1 << (bnflex_squotetok
-bnflex_identtok
)) | (1 << (bnflex_dquotetok
-bnflex_identtok
))));
5216 Term (stopset
|(pge_SetOfStop
) ((1 << (bnflex_bartok
-bnflex_identtok
))));
5226 % VAR t1: TermDesc ; f1, f2: FactorDesc ; %
5228 % CurrentFactor := NewFactor() ;
5229 f1 := CurrentFactor ;
5230 t1 := CurrentTerm ; %
5232 % t1^.factor := f1 ;
5234 CurrentFactor := f2 %
5239 CurrentFactor := f2 ; %
5242 first symbols:squotetok, dquotetok, codetok, identtok, lcparatok, lsparatok, lparatok
5247 static void Term (pge_SetOfStop stopset
)
5253 CurrentFactor
= NewFactor ();
5256 Factor (stopset
|(pge_SetOfStop
) ((1 << (bnflex_lparatok
-bnflex_identtok
)) | (1 << (bnflex_lsparatok
-bnflex_identtok
)) | (1 << (bnflex_lcparatok
-bnflex_identtok
)) | (1 << (bnflex_identtok
-bnflex_identtok
)) | (1 << (bnflex_codetok
-bnflex_identtok
)) | (1 << (bnflex_dquotetok
-bnflex_identtok
)) | (1 << (bnflex_squotetok
-bnflex_identtok
))));
5260 while ((((1 << (bnflex_GetCurrentTokenType ())) & ((unsigned int) ((1 << (bnflex_codetok
)) | (1 << (bnflex_identtok
)) | (1 << (bnflex_lcparatok
)) | (1 << (bnflex_lsparatok
)) | (1 << (bnflex_lparatok
)) | (1 << (bnflex_squotetok
)) | (1 << (bnflex_dquotetok
))))) != 0))
5262 Factor (stopset
|(pge_SetOfStop
) ((1 << (bnflex_codetok
-bnflex_identtok
)) | (1 << (bnflex_identtok
-bnflex_identtok
)) | (1 << (bnflex_lcparatok
-bnflex_identtok
)) | (1 << (bnflex_lsparatok
-bnflex_identtok
)) | (1 << (bnflex_lparatok
-bnflex_identtok
)) | (1 << (bnflex_squotetok
-bnflex_identtok
)) | (1 << (bnflex_dquotetok
-bnflex_identtok
))));
5273 GetDefinitionName - returns the name of the rule inside, p.
5276 static NameKey_Name
GetDefinitionName (pge_ProductionDesc p
)
5280 if ((p
->statement
!= NULL
) && (p
->statement
->ident
!= NULL
))
5282 return p
->statement
->ident
->name
;
5285 return NameKey_NulName
;
5286 /* static analysis guarentees a RETURN statement will be used before here. */
5287 __builtin_unreachable ();
5292 FindDefinition - searches and returns the rule which defines, n.
5295 static pge_ProductionDesc
FindDefinition (NameKey_Name n
)
5297 pge_ProductionDesc p
;
5298 pge_ProductionDesc f
;
5304 if ((GetDefinitionName (p
)) == n
)
5306 /* avoid gcc warning by using compound statement even if not strictly necessary. */
5313 StrIO_WriteString ((const char *) "multiple definition for rule: ", 30);
5314 NameKey_WriteKey (n
);
5321 /* static analysis guarentees a RETURN statement will be used before here. */
5322 __builtin_unreachable ();
5327 BackPatchIdent - found an ident, i, we must look for the corresponding rule and
5328 set the definition accordingly.
5331 static void BackPatchIdent (pge_IdentDesc i
)
5335 i
->definition
= FindDefinition (i
->name
);
5336 if (i
->definition
== NULL
)
5338 WarnError1 ((const char *) "unable to find production %s", 28, i
->name
);
5346 BackPatchFactor - runs through the factor looking for an ident
5349 static void BackPatchFactor (pge_FactorDesc f
)
5356 BackPatchIdent (f
->ident
);
5362 BackPatchExpression (f
->expr
);
5375 BackPatchTerm - runs through all terms to find idents.
5378 static void BackPatchTerm (pge_TermDesc t
)
5382 BackPatchFactor (t
->factor
);
5389 BackPatchExpression - runs through the term to find any idents.
5392 static void BackPatchExpression (pge_ExpressionDesc e
)
5396 BackPatchTerm (e
->term
);
5405 static void BackPatchSet (pge_SetDesc s
)
5412 BackPatchIdent (s
->ident
);
5425 BackPatchIdentToDefinitions - search through all the rules and add a link from any ident
5429 static void BackPatchIdentToDefinitions (pge_ProductionDesc d
)
5431 if ((d
!= NULL
) && (d
->statement
!= NULL
))
5433 BackPatchExpression (d
->statement
->expr
);
5439 CalculateFirstAndFollow -
5442 static void CalculateFirstAndFollow (pge_ProductionDesc p
)
5447 NameKey_WriteKey (p
->statement
->ident
->name
);
5449 StrIO_WriteString ((const char *) " calculating first", 19);
5451 CalcFirstProduction (p
, p
, &p
->first
);
5452 BackPatchSet (p
->first
);
5455 StrIO_WriteString ((const char *) " calculating follow set", 24);
5457 if (p
->followinfo
->follow
== NULL
)
5459 CalcFollowProduction (p
);
5461 BackPatchSet (p
->followinfo
->follow
);
5469 static void ForeachRuleDo (pge_DoProcedure p
)
5471 CurrentProduction
= HeadProduction
;
5472 while (CurrentProduction
!= NULL
)
5474 (*p
.proc
) (CurrentProduction
);
5475 CurrentProduction
= CurrentProduction
->next
;
5481 WhileNotCompleteDo -
5484 static void WhileNotCompleteDo (pge_DoProcedure p
)
5489 } while (! (Finished
));
5494 NewLine - generate a newline and indent.
5497 static void NewLine (unsigned int Left
)
5500 BeginningOfLine
= TRUE
;
5502 while (Indent
< Left
)
5514 static void CheckNewLine (unsigned int Left
)
5520 if (Indent
> BaseRightMargin
)
5528 IndentString - writes out a string with a preceeding indent.
5531 static void IndentString (const char *a_
, unsigned int _a_high
)
5536 /* make a local copy of each unbounded array. */
5537 memcpy (a
, a_
, _a_high
+1);
5545 Output_WriteString ((const char *) a
, _a_high
);
5551 KeyWord - writes out a keywork with optional formatting directives.
5554 static void KeyWord (NameKey_Name n
)
5556 if (KeywordFormatting
)
5558 Output_WriteString ((const char *) "{%K", 3);
5559 if (((n
== (NameKey_MakeKey ((const char *) "}", 1))) || (n
== (NameKey_MakeKey ((const char *) "{", 1)))) || (n
== (NameKey_MakeKey ((const char *) "%", 1))))
5561 Output_Write ('%'); /* escape }, { or % */
5563 Output_WriteKey (n
);
5568 Output_WriteKey (n
);
5577 static void PrettyPara (const char *c1_
, unsigned int _c1_high
, const char *c2_
, unsigned int _c2_high
, pge_ExpressionDesc e
, unsigned int Left
)
5579 char c1
[_c1_high
+1];
5580 char c2
[_c2_high
+1];
5582 /* make a local copy of each unbounded array. */
5583 memcpy (c1
, c1_
, _c1_high
+1);
5584 memcpy (c2
, c2_
, _c2_high
+1);
5586 Output_WriteString ((const char *) c1
, _c1_high
);
5587 Indent
+= StrLib_StrLen ((const char *) c1
, _c1_high
);
5589 PrettyCommentExpression (e
, Left
);
5590 Output_WriteString ((const char *) c2
, _c2_high
);
5591 Indent
+= StrLib_StrLen ((const char *) c2
, _c2_high
);
5599 static void WriteKeyTexinfo (NameKey_Name s
)
5601 DynamicStrings_String ds
;
5608 ds
= DynamicStrings_InitStringCharStar (NameKey_KeyToCharStar (s
));
5609 l
= DynamicStrings_Length (ds
);
5613 ch
= DynamicStrings_char (ds
, static_cast<int> (i
));
5614 if ((ch
== '{') || (ch
== '}'))
5624 Output_WriteKey (s
);
5630 PrettyCommentFactor -
5633 static void PrettyCommentFactor (pge_FactorDesc f
, unsigned int Left
)
5635 unsigned int curpos
;
5636 unsigned int seentext
;
5640 CheckNewLine (Left
);
5644 Output_WriteKey (f
->ident
->name
);
5645 Output_WriteString ((const char *) " ", 1);
5646 Indent
+= (NameKey_LengthKey (f
->ident
->name
))+1;
5650 if ((NameKey_MakeKey ((const char *) "'", 1)) == f
->string
)
5653 WriteKeyTexinfo (f
->string
);
5654 Output_WriteString ((const char *) "\" ", 2);
5658 Output_Write ('\'');
5659 WriteKeyTexinfo (f
->string
);
5660 Output_WriteString ((const char *) "' ", 2);
5662 Indent
+= (NameKey_LengthKey (f
->string
))+3;
5666 PrettyPara ((const char *) "( ", 2, (const char *) " ) ", 3, f
->expr
, Left
);
5670 PrettyPara ((const char *) "[ ", 2, (const char *) " ] ", 3, f
->expr
, Left
);
5676 PrettyPara ((const char *) "@{ ", 3, (const char *) " @} ", 4, f
->expr
, Left
);
5680 PrettyPara ((const char *) "{ ", 2, (const char *) " } ", 3, f
->expr
, Left
);
5688 Output_WriteString ((const char *) "% ", 2);
5691 WriteCodeHunkListIndent (f
->code
->code
, f
->code
->indent
, &curpos
, Left
+2, &seentext
);
5692 Output_WriteString ((const char *) " %", 2);
5701 PrettyFollow ((const char *) "<f:", 3, (const char *) ":f>", 3, f
->followinfo
);
5708 PeepTerm - returns the length of characters in term.
5711 static unsigned int PeepTerm (pge_TermDesc t
)
5718 l
+= PeepFactor (t
->factor
);
5719 if (t
->next
!= NULL
)
5726 /* static analysis guarentees a RETURN statement will be used before here. */
5727 __builtin_unreachable ();
5732 PeepExpression - returns the length of the expression.
5735 static unsigned int PeepExpression (pge_ExpressionDesc e
)
5743 return PeepTerm (e
->term
);
5745 /* static analysis guarentees a RETURN statement will be used before here. */
5746 __builtin_unreachable ();
5751 PeepFactor - returns the length of character in the factor
5754 static unsigned int PeepFactor (pge_FactorDesc f
)
5764 l
+= (NameKey_LengthKey (f
->ident
->name
))+1;
5768 l
+= (NameKey_LengthKey (f
->string
))+3;
5774 l
+= PeepExpression (f
->expr
);
5784 f
= f
->next
; /* empty */
5787 /* static analysis guarentees a RETURN statement will be used before here. */
5788 __builtin_unreachable ();
5796 static void PrettyCommentTerm (pge_TermDesc t
, unsigned int Left
)
5800 CheckNewLine (Left
);
5801 PrettyCommentFactor (t
->factor
, Left
);
5802 if (t
->next
!= NULL
)
5804 Output_WriteString ((const char *) " | ", 3);
5806 if (((PeepFactor (t
->factor
))+Indent
) > BaseRightMargin
)
5811 PrettyFollow ((const char *) "<t:", 3, (const char *) ":t>", 3, t
->followinfo
);
5818 PrettyCommentExpression -
5821 static void PrettyCommentExpression (pge_ExpressionDesc e
, unsigned int Left
)
5825 PrettyCommentTerm (e
->term
, Left
);
5826 PrettyFollow ((const char *) "<e:", 3, (const char *) ":e>", 3, e
->followinfo
);
5832 PrettyCommentStatement -
5835 static void PrettyCommentStatement (pge_StatementDesc s
, unsigned int Left
)
5839 PrettyCommentExpression (s
->expr
, Left
);
5840 PrettyFollow ((const char *) "<s:", 3, (const char *) ":s>", 3, s
->followinfo
);
5846 PrettyCommentProduction - generates the comment for rule, p.
5849 static void PrettyCommentProduction (pge_ProductionDesc p
)
5855 BeginningOfLine
= TRUE
;
5857 Output_WriteString ((const char *) "(*", 2);
5859 Output_WriteKey (GetDefinitionName (p
));
5860 Output_WriteString ((const char *) " := ", 4);
5861 Indent
+= (NameKey_LengthKey (GetDefinitionName (p
)))+4;
5862 PrettyCommentStatement (p
->statement
, Indent
);
5867 Output_WriteString ((const char *) "first symbols:", 15);
5868 EmitSet (p
->first
, static_cast<unsigned int> (0), static_cast<unsigned int> (0));
5870 PrettyFollow ((const char *) "<p:", 3, (const char *) ":p>", 3, p
->followinfo
);
5872 switch (GetReachEnd (p
->followinfo
))
5875 Output_WriteString ((const char *) "reachend", 8);
5879 Output_WriteString ((const char *) "cannot reachend", 15);
5883 Output_WriteString ((const char *) "unknown...", 10);
5892 Output_WriteString ((const char *) "*)", 2);
5899 PrettyPrintProduction - pretty prints the ebnf rule, p.
5902 static void PrettyPrintProduction (pge_ProductionDesc p
)
5908 BeginningOfLine
= TRUE
;
5912 Output_WriteString ((const char *) "@example", 8);
5917 /* avoid dangling else. */
5918 Output_WriteString ((const char *) ".. code-block:: ebnf", 20);
5921 Output_WriteKey (GetDefinitionName (p
));
5922 Output_WriteString ((const char *) " := ", 4);
5923 Indent
+= (NameKey_LengthKey (GetDefinitionName (p
)))+4;
5924 PrettyCommentStatement (p
->statement
, Indent
);
5925 if (p
->description
!= NameKey_NulName
)
5927 Output_WriteKey (p
->description
);
5930 WriteIndent ((NameKey_LengthKey (GetDefinitionName (p
)))+1);
5931 Output_WriteString ((const char *) " =: ", 4);
5935 Output_WriteString ((const char *) "@findex ", 8);
5936 Output_WriteKey (GetDefinitionName (p
));
5937 Output_WriteString ((const char *) " (ebnf)", 7);
5939 Output_WriteString ((const char *) "@end example", 12);
5944 /* avoid dangling else. */
5945 Output_WriteString ((const char *) ".. index::", 10);
5947 Output_WriteString ((const char *) " pair: ", 8);
5948 Output_WriteKey (GetDefinitionName (p
));
5949 Output_WriteString ((const char *) "; (ebnf)", 8);
5958 EmitFileLineTag - emits a line and file tag using the C preprocessor syntax.
5961 static void EmitFileLineTag (unsigned int line
)
5963 if (! SuppressFileLineTag
&& (line
!= LastLineNo
))
5970 Output_WriteString ((const char *) "# ", 2);
5971 Output_WriteCard (line
, 0);
5972 Output_WriteString ((const char *) " \"", 2);
5973 Output_WriteString ((const char *) &FileName
.array
[0], MaxFileName
);
5982 EmitRule - generates a comment and code for rule, p.
5985 static void EmitRule (pge_ProductionDesc p
)
5989 PrettyPrintProduction (p
);
5993 PrettyCommentProduction (p
);
5996 RecoverProduction (p
);
6010 static void CodeCondition (pge_m2condition m
)
6016 IndentString ((const char *) "IF ", 3);
6020 IndentString ((const char *) "ELSIF ", 6);
6024 IndentString ((const char *) "WHILE ", 6);
6029 Debug_Halt ((const char *) "unrecognised m2condition", 24, 2680, (const char *) "m2/gm2-auto/pge.mod", 19);
6036 CodeThenDo - codes a "THEN" or "DO" depending upon, m.
6039 static void CodeThenDo (pge_m2condition m
)
6046 if (LastLineNo
== 0)
6050 IndentString ((const char *) "THEN", 4);
6055 Output_WriteString ((const char *) " DO", 3);
6061 Debug_Halt ((const char *) "unrecognised m2condition", 24, 2705, (const char *) "m2/gm2-auto/pge.mod", 19);
6069 CodeElseEnd - builds an ELSE END statement using string, end.
6072 static void CodeElseEnd (const char *end_
, unsigned int _end_high
, unsigned int consumed
, pge_FactorDesc f
, unsigned int inopt
)
6074 char end
[_end_high
+1];
6076 /* make a local copy of each unbounded array. */
6077 memcpy (end
, end_
, _end_high
+1);
6081 EmitFileLineTag (f
->line
);
6084 IndentString ((const char *) "ELSE", 4);
6089 IndentString ((const char *) "", 0);
6090 Output_WriteKey (ErrorProcArray
);
6095 Output_Write ('\'');
6096 Output_WriteKey (f
->ident
->name
);
6097 Output_WriteString ((const char *) " - expected", 11);
6098 Output_WriteString ((const char *) "') ;", 4);
6102 if ((NameKey_MakeKey ((const char *) "'", 1)) == f
->string
)
6105 KeyWord (f
->string
);
6106 Output_WriteString ((const char *) " - expected", 11);
6107 Output_WriteString ((const char *) "\") ;", 4);
6109 else if ((NameKey_MakeKey ((const char *) "\"", 1)) == f
->string
)
6111 /* avoid dangling else. */
6112 Output_Write ('\'');
6113 KeyWord (f
->string
);
6114 Output_WriteString ((const char *) " - expected", 11);
6115 Output_WriteString ((const char *) "') ;", 4);
6119 /* avoid dangling else. */
6121 Output_Write ('\'');
6122 KeyWord (f
->string
);
6123 Output_WriteString ((const char *) "' - expected", 12);
6124 Output_WriteString ((const char *) "\") ;", 4);
6134 IndentString ((const char *) "RETURN( FALSE )", 15);
6138 IndentString ((const char *) end
, _end_high
);
6145 CodeEnd - codes a "END" depending upon, m.
6148 static void CodeEnd (pge_m2condition m
, pge_TermDesc t
, unsigned int consumed
, pge_FactorDesc f
, unsigned int inopt
)
6158 CodeElseEnd ((const char *) "END ;", 5, consumed
, f
, inopt
);
6165 CodeElseEnd ((const char *) "END ; (* if *)", 15, consumed
, f
, inopt
);
6172 CodeElseEnd ((const char *) "END ; (* elsif *)", 18, consumed
, f
, inopt
);
6177 IndentString ((const char *) "END ; (* while *)", 18);
6182 Debug_Halt ((const char *) "unrecognised m2condition", 24, 2788, (const char *) "m2/gm2-auto/pge.mod", 19);
6185 OnLineStart
= FALSE
;
6190 EmitNonVarCode - writes out, code, providing it is not a variable declaration.
6193 static void EmitNonVarCode (pge_CodeDesc code
, unsigned int curpos
, unsigned int left
)
6197 unsigned int seentext
;
6200 if ((! (FindStr (&t
, &i
, (const char *) "VAR", 3))) && EmitCode
)
6204 EmitFileLineTag (code
->line
);
6205 IndentString ((const char *) "", 0);
6206 WriteCodeHunkListIndent (code
->code
, code
->indent
, &curpos
, left
, &seentext
);
6207 Output_WriteString ((const char *) " ;", 2);
6218 static pge_FactorDesc
ChainOn (pge_FactorDesc codeStack
, pge_FactorDesc f
)
6223 if (codeStack
== NULL
)
6230 while (s
->pushed
!= NULL
)
6237 /* static analysis guarentees a RETURN statement will be used before here. */
6238 __builtin_unreachable ();
6246 static void FlushCode (pge_FactorDesc
*codeStack
)
6248 if ((*codeStack
) != NULL
)
6251 Output_WriteString ((const char *) "(* begin flushing code *)", 25);
6252 OnLineStart
= FALSE
;
6253 while ((*codeStack
) != NULL
)
6256 EmitNonVarCode ((*codeStack
)->code
, 0, Indent
);
6258 (*codeStack
) = (*codeStack
)->pushed
;
6259 if ((*codeStack
) != NULL
)
6261 Output_WriteString ((const char *) " (* again flushing code *)", 26);
6267 Output_WriteString ((const char *) "(* end flushing code *)", 23);
6268 OnLineStart
= FALSE
;
6277 static void CodeFactor (pge_FactorDesc f
, pge_TermDesc t
, pge_m2condition l
, pge_m2condition n
, unsigned int inopt
, unsigned int inwhile
, unsigned int consumed
, pge_FactorDesc codeStack
)
6281 /* avoid dangling else. */
6282 if (! inwhile
&& ! inopt
) /* ((l=m2elsif) OR (l=m2if) OR (l=m2none)) AND */
6285 IndentString ((const char *) "RETURN( TRUE )", 14);
6286 OnLineStart
= FALSE
;
6291 EmitFileLineTag (f
->line
);
6295 FlushCode (&codeStack
);
6297 Output_WriteKey (f
->ident
->name
);
6298 Output_WriteString ((const char *) "()", 2);
6301 CodeFactor (f
->next
, NULL
, n
, pge_m2none
, inopt
, inwhile
, TRUE
, NULL
);
6302 CodeEnd (n
, t
, consumed
, f
, inopt
);
6306 FlushCode (&codeStack
);
6308 Output_WriteKey (SymIsProc
);
6310 Output_WriteKey (SymbolKey_GetSymKey (Aliases
, f
->string
));
6314 CodeFactor (f
->next
, NULL
, n
, pge_m2none
, inopt
, inwhile
, TRUE
, NULL
);
6315 CodeEnd (n
, t
, consumed
, f
, inopt
);
6319 FlushCode (&codeStack
);
6320 CodeExpression (f
->expr
, pge_m2none
, inopt
, inwhile
, consumed
, NULL
);
6321 if (f
->next
!= NULL
)
6324 * the test above makes sure that we don't emit a RETURN( TRUE )
6325 * after a subexpression. Remember sub expressions are not conditional
6327 CodeFactor (f
->next
, t
, n
, pge_m2none
, inopt
, inwhile
, TRUE
, NULL
);
6332 FlushCode (&codeStack
);
6333 CodeExpression (f
->expr
, pge_m2if
, TRUE
, inwhile
, FALSE
, NULL
);
6334 CodeFactor (f
->next
, t
, n
, pge_m2none
, inopt
, inwhile
, consumed
, NULL
);
6338 FlushCode (&codeStack
);
6339 CodeExpression (f
->expr
, pge_m2while
, FALSE
, TRUE
, consumed
, NULL
);
6340 CodeFactor (f
->next
, t
, n
, pge_m2none
, inopt
, inwhile
, consumed
, NULL
);
6344 codeStack
= ChainOn (codeStack
, f
);
6345 if (consumed
|| (f
->next
== NULL
))
6347 FlushCode (&codeStack
);
6349 CodeFactor (f
->next
, t
, n
, pge_m2none
, inopt
, inwhile
, consumed
, codeStack
);
6364 static void CodeTerm (pge_TermDesc t
, pge_m2condition m
, unsigned int inopt
, unsigned int inwhile
, unsigned int consumed
, pge_FactorDesc codeStack
)
6371 EmitFileLineTag (t
->line
);
6372 if ((t
->factor
->type
== pge_m2
) && (m
== pge_m2elsif
))
6375 IndentString ((const char *) "ELSE", 4);
6379 CodeFactor (t
->factor
, t
->next
, pge_m2none
, pge_m2none
, inopt
, inwhile
, consumed
, codeStack
);
6381 IndentString ((const char *) "END ;", 5);
6387 CodeFactor (t
->factor
, t
->next
, pge_m2none
, m
, inopt
, inwhile
, consumed
, codeStack
);
6390 if (t
->next
!= NULL
)
6403 static void CodeExpression (pge_ExpressionDesc e
, pge_m2condition m
, unsigned int inopt
, unsigned int inwhile
, unsigned int consumed
, pge_FactorDesc codeStack
)
6407 EmitFileLineTag (e
->line
);
6408 CodeTerm (e
->term
, m
, inopt
, inwhile
, consumed
, codeStack
);
6417 static void CodeStatement (pge_StatementDesc s
, pge_m2condition m
)
6421 EmitFileLineTag (s
->line
);
6422 CodeExpression (s
->expr
, m
, FALSE
, FALSE
, FALSE
, NULL
);
6428 CodeProduction - only encode grammer rules which are not special.
6431 static void CodeProduction (pge_ProductionDesc p
)
6433 if ((p
!= NULL
) && (! p
->firstsolved
|| ((p
->statement
!= NULL
) && (p
->statement
->expr
!= NULL
))))
6435 BeginningOfLine
= TRUE
;
6438 EmitFileLineTag (p
->line
);
6439 IndentString ((const char *) "PROCEDURE ", 10);
6440 Output_WriteKey (GetDefinitionName (p
));
6441 Output_WriteString ((const char *) " () : BOOLEAN ;", 15);
6445 EmitFileLineTag (p
->line
);
6446 IndentString ((const char *) "BEGIN", 5);
6448 OnLineStart
= FALSE
;
6449 EmitFileLineTag (p
->line
);
6451 CodeStatement (p
->statement
, pge_m2none
);
6454 IndentString ((const char *) "END ", 4);
6455 NameKey_WriteKey (GetDefinitionName (p
));
6456 Output_WriteString ((const char *) " ;", 2);
6468 static void RecoverCondition (pge_m2condition m
)
6473 IndentString ((const char *) "IF ", 3);
6477 IndentString ((const char *) "IF ", 3);
6481 IndentString ((const char *) "ELSIF ", 6);
6485 IndentString ((const char *) "WHILE ", 6);
6490 Debug_Halt ((const char *) "unrecognised m2condition", 24, 3045, (const char *) "m2/gm2-auto/pge.mod", 19);
6497 ConditionIndent - returns the number of spaces indentation created via, m.
6500 static unsigned int ConditionIndent (pge_m2condition m
)
6522 Debug_Halt ((const char *) "unrecognised m2condition", 24, 3064, (const char *) "m2/gm2-auto/pge.mod", 19);
6525 ReturnException ("m2/gm2-auto/pge.mod", 1, 7);
6526 __builtin_unreachable ();
6531 WriteGetTokenType - writes out the method of determining the token type.
6534 static void WriteGetTokenType (void)
6536 Output_WriteKey (TokenTypeProc
);
6541 NumberOfElements - returns the number of elements in set, to, which lie between low..high
6544 static unsigned int NumberOfElements (pge_SetDesc to
, unsigned int low
, unsigned int high
)
6554 if ((high
== 0) || (IsBetween (to
->string
, low
, high
)))
6561 if ((high
== 0) || (IsBetween (SymbolKey_GetSymKey (Aliases
, to
->string
), low
, high
)))
6568 PushBackInput_WarnError ((const char *) "not expecting ident in first symbol list", 40);
6574 PushBackInput_WarnError ((const char *) "unknown enuneration element", 27);
6581 /* static analysis guarentees a RETURN statement will be used before here. */
6582 __builtin_unreachable ();
6587 WriteElement - writes the literal name for element, e.
6590 static void WriteElement (unsigned int e
)
6592 Output_WriteKey (SymbolKey_GetSymKey (ReverseValues
, e
));
6597 EmitIsInSet - writes out the equivalent of GetTokenType() IN { toset }
6600 static void EmitIsInSet (pge_SetDesc to
, NameKey_Name low
, NameKey_Name high
)
6602 if ((NumberOfElements (to
, low
, high
)) == 1)
6604 WriteGetTokenType ();
6606 EmitSet (to
, low
, high
);
6610 WriteGetTokenType ();
6611 Output_WriteString ((const char *) " IN SetOfStop", 13);
6612 if (LargestValue
> MaxElementsInSet
)
6614 Output_WriteCard (((unsigned int ) (low
)) / MaxElementsInSet
, 0);
6616 Output_WriteString ((const char *) " {", 2);
6617 EmitSet (to
, low
, high
);
6618 Output_WriteString ((const char *) "}", 1);
6624 EmitIsInSubSet - writes out a test to see whether GetTokenype() is in { subset }
6627 static void EmitIsInSubSet (pge_SetDesc to
, unsigned int low
, unsigned int high
)
6629 if ((NumberOfElements (to
, low
, high
)) == 1)
6632 EmitIsInSet (to
, low
, high
);
6637 /* avoid dangling else. */
6638 /* no need to check whether GetTokenType > low */
6639 Output_WriteString ((const char *) "((", 2);
6640 WriteGetTokenType ();
6642 WriteElement (static_cast<unsigned int> (((int ) (high
))+1));
6643 Output_WriteString ((const char *) ") AND (", 7);
6644 EmitIsInSet (to
, low
, high
);
6645 Output_WriteString ((const char *) "))", 2);
6647 else if (((unsigned int ) (high
)) > LargestValue
)
6649 /* avoid dangling else. */
6650 /* no need to check whether GetTokenType < high */
6651 Output_WriteString ((const char *) "((", 2);
6652 WriteGetTokenType ();
6653 Output_WriteString ((const char *) ">=", 2);
6655 Output_WriteString ((const char *) ") AND (", 7);
6656 EmitIsInSet (to
, low
, high
);
6657 Output_WriteString ((const char *) "))", 2);
6661 /* avoid dangling else. */
6662 Output_WriteString ((const char *) "((", 2);
6663 WriteGetTokenType ();
6664 Output_WriteString ((const char *) ">=", 2);
6666 Output_WriteString ((const char *) ") AND (", 7);
6667 WriteGetTokenType ();
6669 WriteElement (static_cast<unsigned int> (((int ) (high
))+1));
6670 Output_WriteString ((const char *) ") AND (", 7);
6671 EmitIsInSet (to
, low
, high
);
6672 Output_WriteString ((const char *) "))", 2);
6681 static void EmitIsInFirst (pge_SetDesc to
, pge_m2condition m
)
6686 if ((NumberOfElements (to
, static_cast<unsigned int> (0), static_cast<unsigned int> (0))) == 1)
6688 /* only one element */
6689 WriteGetTokenType ();
6691 EmitSet (to
, static_cast<unsigned int> (0), static_cast<unsigned int> (0));
6695 if (LargestValue
<= MaxElementsInSet
)
6698 WriteGetTokenType ();
6699 Output_WriteString ((const char *) " IN ", 4);
6700 EmitSetAsParameters (to
);
6701 Output_WriteString ((const char *) ")", 1);
6708 if (! (IsEmptySet (to
, i
*MaxElementsInSet
, ((i
+1)*MaxElementsInSet
)-1)))
6712 Output_WriteString ((const char *) " OR", 3);
6713 NewLine (Indent
+(ConditionIndent (m
)));
6714 Indent
-= ConditionIndent (m
);
6716 EmitIsInSubSet (to
, i
*MaxElementsInSet
, ((i
+1)*MaxElementsInSet
)-1);
6720 } while (! ((i
*MaxElementsInSet
) > LargestValue
));
6725 static void FlushRecoverCode (pge_FactorDesc
*codeStack
)
6730 if ((*codeStack
) != NULL
)
6732 while ((*codeStack
) != NULL
)
6734 EmitNonVarCode ((*codeStack
)->code
, 0, Indent
);
6735 (*codeStack
) = (*codeStack
)->pushed
;
6745 static void RecoverFactor (pge_FactorDesc f
, pge_m2condition m
, pge_FactorDesc codeStack
)
6753 EmitFileLineTag (f
->line
);
6758 CalcFirstFactor (f
, NULL
, &to
);
6759 if ((to
!= NULL
) && (m
!= pge_m2none
))
6761 RecoverCondition (m
);
6762 EmitIsInFirst (to
, m
);
6766 FlushRecoverCode (&codeStack
);
6767 IndentString ((const char *) "", 0);
6768 Output_WriteKey (f
->ident
->name
);
6770 EmitStopParametersAndFollow (f
, m
);
6771 Output_WriteString ((const char *) ") ;", 3);
6773 RecoverFactor (f
->next
, pge_m2none
, codeStack
);
6774 if ((to
!= NULL
) && (m
!= pge_m2none
))
6781 if (m
== pge_m2none
)
6783 FlushRecoverCode (&codeStack
);
6784 IndentString ((const char *) "Expect(", 7);
6785 Output_WriteKey (SymbolKey_GetSymKey (Aliases
, f
->string
));
6786 Output_WriteString ((const char *) ", ", 2);
6787 EmitStopParametersAndFollow (f
, m
);
6788 Output_WriteString ((const char *) ") ;", 3);
6790 RecoverFactor (f
->next
, pge_m2none
, codeStack
);
6794 RecoverCondition (m
);
6795 WriteGetTokenType ();
6797 Output_WriteKey (SymbolKey_GetSymKey (Aliases
, f
->string
));
6800 IndentString ((const char *) "Expect(", 7);
6801 Output_WriteKey (SymbolKey_GetSymKey (Aliases
, f
->string
));
6802 Output_WriteString ((const char *) ", ", 2);
6803 EmitStopParametersAndFollow (f
, m
);
6804 Output_WriteString ((const char *) ") ;", 3);
6806 FlushRecoverCode (&codeStack
);
6807 RecoverFactor (f
->next
, pge_m2none
, codeStack
);
6813 FlushRecoverCode (&codeStack
);
6814 RecoverExpression (f
->expr
, pge_m2none
, m
);
6815 RecoverFactor (f
->next
, pge_m2none
, codeStack
);
6819 FlushRecoverCode (&codeStack
);
6823 CalcFirstExpression (f
->expr
, NULL
, &to
);
6824 RecoverCondition (m
);
6825 EmitIsInFirst (to
, m
);
6828 IndentString ((const char *) "(* seen optional [ | ] expression *)", 36);
6831 RecoverExpression (f
->expr
, pge_m2none
, pge_m2if
);
6832 IndentString ((const char *) "(* end of optional [ | ] expression *)", 38);
6835 IndentString ((const char *) "END ;", 5);
6840 RecoverExpression (f
->expr
, pge_m2if
, m
);
6842 RecoverFactor (f
->next
, pge_m2none
, codeStack
);
6846 FlushRecoverCode (&codeStack
);
6847 if (((OptExpSeen (f
)) || (m
== pge_m2if
)) || (m
== pge_m2elsif
))
6849 /* avoid dangling else. */
6851 CalcFirstExpression (f
->expr
, NULL
, &to
);
6852 RecoverCondition (m
);
6853 EmitIsInFirst (to
, m
);
6856 IndentString ((const char *) "(* seen optional { | } expression *)", 36);
6858 RecoverCondition (pge_m2while
);
6859 EmitIsInFirst (to
, pge_m2while
);
6860 CodeThenDo (pge_m2while
);
6862 RecoverExpression (f
->expr
, pge_m2none
, pge_m2while
);
6863 IndentString ((const char *) "(* end of optional { | } expression *)", 38);
6866 IndentString ((const char *) "END ;", 5);
6869 if (m
== pge_m2none
)
6871 IndentString ((const char *) "END ;", 5);
6878 RecoverExpression (f
->expr
, pge_m2while
, m
);
6880 RecoverFactor (f
->next
, pge_m2none
, codeStack
);
6884 codeStack
= ChainOn (codeStack
, f
);
6885 if (f
->next
== NULL
)
6887 FlushRecoverCode (&codeStack
);
6891 RecoverFactor (f
->next
, m
, codeStack
); /* was m2none */
6904 OptExpSeen - returns TRUE if we can see an optional expression in the factor.
6905 This is not the same as epsilon. Example { '+' } matches epsilon as
6906 well as { '+' | '-' } but OptExpSeen returns TRUE in the second case
6907 and FALSE in the first.
6910 static unsigned int OptExpSeen (pge_FactorDesc f
)
6926 return FALSE
; /* is this correct? */
6931 return ((f
->expr
!= NULL
) && (f
->expr
->term
!= NULL
)) && (f
->expr
->term
->next
!= NULL
); /* is this correct? */
6943 PushBackInput_WarnError ((const char *) "all cases were not handled", 26);
6945 ReturnException ("m2/gm2-auto/pge.mod", 1, 7);
6946 __builtin_unreachable ();
6954 static void RecoverTerm (pge_TermDesc t
, pge_m2condition new_
, pge_m2condition old
)
6956 unsigned int LastWasM2Only
;
6957 unsigned int alternative
;
6960 LastWasM2Only
= (t
->factor
->type
== pge_m2
) && (t
->factor
->next
== NULL
); /* does the factor only contain inline code? */
6962 CalcFirstTerm (t
, NULL
, &to
);
6963 alternative
= FALSE
;
6964 if (t
->next
!= NULL
)
6970 EmitFileLineTag (t
->line
);
6971 LastWasM2Only
= (t
->factor
->type
== pge_m2
) && (t
->factor
->next
== NULL
);
6972 if ((t
->factor
->type
== pge_m2
) && (new_
== pge_m2elsif
))
6975 IndentString ((const char *) "ELSE", 4);
6978 RecoverFactor (t
->factor
, pge_m2none
, NULL
);
6979 alternative
= FALSE
;
6983 RecoverFactor (t
->factor
, new_
, NULL
);
6985 if (t
->next
!= NULL
)
6992 if ((new_
== pge_m2if
) || (new_
== pge_m2elsif
))
6994 if (alternative
&& (old
!= pge_m2while
))
6996 IndentString ((const char *) "ELSE", 4);
6999 IndentString ((const char *) "", 0);
7000 Output_WriteKey (ErrorProcArray
);
7001 Output_WriteString ((const char *) "('expecting one of: ", 20);
7002 EmitSetName (to
, static_cast<unsigned int> (0), static_cast<unsigned int> (0));
7003 Output_WriteString ((const char *) "')", 2);
7007 else if (LastWasM2Only
)
7009 /* avoid dangling else. */
7012 IndentString ((const char *) "END ;", 5);
7015 else if (new_
== pge_m2while
)
7017 /* avoid dangling else. */
7018 IndentString ((const char *) "END (* while *) ;", 17);
7021 else if (LastWasM2Only
)
7023 /* avoid dangling else. */
7033 static void RecoverExpression (pge_ExpressionDesc e
, pge_m2condition new_
, pge_m2condition old
)
7037 EmitFileLineTag (e
->line
);
7038 RecoverTerm (e
->term
, new_
, old
);
7047 static void RecoverStatement (pge_StatementDesc s
, pge_m2condition m
)
7051 EmitFileLineTag (s
->line
);
7052 RecoverExpression (s
->expr
, m
, pge_m2none
);
7058 EmitFirstFactor - generate a list of all first tokens between the range: low..high.
7061 static void EmitFirstFactor (pge_FactorDesc f
, unsigned int low
, unsigned int high
)
7070 static void EmitUsed (unsigned int wordno
)
7072 if (! ((((1 << (wordno
)) & (ParametersUsed
)) != 0)))
7074 Output_WriteString ((const char *) " (* <* unused *> *) ", 20);
7080 EmitStopParameters - generate the stop set.
7083 static void EmitStopParameters (unsigned int FormalParameters
)
7087 if (LargestValue
<= MaxElementsInSet
)
7089 Output_WriteString ((const char *) "stopset", 7);
7090 if (FormalParameters
)
7092 Output_WriteString ((const char *) ": SetOfStop", 11);
7097 ParametersUsed
|= (1 << (0 ));
7104 Output_WriteString ((const char *) "stopset", 7);
7105 Output_WriteCard (i
, 0);
7106 if (FormalParameters
)
7108 Output_WriteString ((const char *) ": SetOfStop", 11);
7109 Output_WriteCard (i
, 0);
7114 ParametersUsed
|= (1 << (i
));
7117 if ((i
*MaxElementsInSet
) < LargestValue
)
7119 /* avoid gcc warning by using compound statement even if not strictly necessary. */
7120 if (FormalParameters
)
7122 Output_WriteString ((const char *) "; ", 2);
7126 Output_WriteString ((const char *) ", ", 2);
7129 } while (! ((i
*MaxElementsInSet
) >= LargestValue
));
7135 IsBetween - returns TRUE if the value of the token, string, is
7136 in the range: low..high
7139 static unsigned int IsBetween (NameKey_Name string
, unsigned int low
, unsigned int high
)
7141 return ((SymbolKey_GetSymKey (Values
, string
)) >= low
) && ((SymbolKey_GetSymKey (Values
, string
)) <= high
);
7142 /* static analysis guarentees a RETURN statement will be used before here. */
7143 __builtin_unreachable ();
7148 IsEmptySet - returns TRUE if no elements exist in set, to, with values, low..high.
7151 static unsigned int IsEmptySet (pge_SetDesc to
, unsigned int low
, unsigned int high
)
7158 if (IsBetween (to
->string
, low
, high
))
7165 if (IsBetween (SymbolKey_GetSymKey (Aliases
, to
->string
), low
, high
))
7172 PushBackInput_WarnError ((const char *) "not expecting ident in first symbol list", 40);
7178 PushBackInput_WarnError ((const char *) "unknown enuneration element", 27);
7185 /* static analysis guarentees a RETURN statement will be used before here. */
7186 __builtin_unreachable ();
7191 EmitSet - emits the tokens in the set, to, which have values low..high
7194 static void EmitSet (pge_SetDesc to
, unsigned int low
, unsigned int high
)
7204 if ((high
== 0) || (IsBetween (to
->string
, low
, high
)))
7208 Output_WriteString ((const char *) ", ", 2);
7210 Output_WriteKey (to
->string
);
7216 if ((high
== 0) || (IsBetween (SymbolKey_GetSymKey (Aliases
, to
->string
), low
, high
)))
7220 Output_WriteString ((const char *) ", ", 2);
7222 Output_WriteKey (SymbolKey_GetSymKey (Aliases
, to
->string
));
7228 PushBackInput_WarnError ((const char *) "not expecting ident in first symbol list", 40);
7234 PushBackInput_WarnError ((const char *) "unknown enuneration element", 27);
7244 EmitSetName - emits the tokens in the set, to, which have values low..high, using
7248 static void EmitSetName (pge_SetDesc to
, unsigned int low
, unsigned int high
)
7255 if ((high
== 0) || (IsBetween (to
->string
, low
, high
)))
7257 /* avoid gcc warning by using compound statement even if not strictly necessary. */
7258 if ((NameKey_MakeKey ((const char *) "'", 1)) == (SymbolKey_GetSymKey (ReverseAliases
, to
->string
)))
7260 Output_WriteString ((const char *) "single quote", 12);
7264 KeyWord (SymbolKey_GetSymKey (ReverseAliases
, to
->string
));
7270 if ((high
== 0) || (IsBetween (SymbolKey_GetSymKey (Aliases
, to
->string
), low
, high
)))
7272 Output_WriteKey (to
->string
);
7277 PushBackInput_WarnError ((const char *) "not expecting ident in first symbol list", 40);
7283 PushBackInput_WarnError ((const char *) "unknown enuneration element", 27);
7297 EmitStopParametersAndSet - generates the stop parameters together with a set
7298 inclusion of all the symbols in set, to.
7301 static void EmitStopParametersAndSet (pge_SetDesc to
)
7305 if (LargestValue
<= MaxElementsInSet
)
7307 /* avoid dangling else. */
7308 Output_WriteString ((const char *) "stopset", 7);
7309 ParametersUsed
|= (1 << (0 ));
7310 if ((to
!= NULL
) && ((NumberOfElements (to
, static_cast<unsigned int> (0), static_cast<unsigned int> (MaxElementsInSet
-1))) > 0))
7312 Output_WriteString ((const char *) " + SetOfStop", 12);
7314 EmitSet (to
, static_cast<unsigned int> (0), static_cast<unsigned int> (MaxElementsInSet
-1));
7322 Output_WriteString ((const char *) "stopset", 7);
7323 Output_WriteCard (i
, 0);
7324 ParametersUsed
|= (1 << (i
));
7325 if ((to
!= NULL
) && ((NumberOfElements (to
, i
*MaxElementsInSet
, ((i
+1)*MaxElementsInSet
)-1)) > 0))
7327 Output_WriteString ((const char *) " + SetOfStop", 12);
7328 Output_WriteCard (i
, 0);
7330 EmitSet (to
, i
*MaxElementsInSet
, ((i
+1)*MaxElementsInSet
)-1);
7334 if ((i
*MaxElementsInSet
) < LargestValue
)
7336 Output_WriteString ((const char *) ", ", 2);
7338 } while (! ((i
*MaxElementsInSet
) >= LargestValue
));
7344 EmitSetAsParameters - generates the first symbols as parameters to a set function.
7347 static void EmitSetAsParameters (pge_SetDesc to
)
7351 if (LargestValue
<= MaxElementsInSet
)
7354 EmitSet (to
, static_cast<unsigned int> (0), static_cast<unsigned int> (MaxElementsInSet
-1));
7361 EmitSet (to
, i
*MaxElementsInSet
, ((i
+1)*MaxElementsInSet
)-1);
7363 if (((i
+1)*MaxElementsInSet
) > LargestValue
)
7365 Output_WriteString ((const char *) "}, ", 3);
7367 } while (! (((i
+1)*MaxElementsInSet
) >= LargestValue
));
7374 EmitStopParametersAndFollow - generates the stop parameters together with a set
7375 inclusion of all the follow symbols for subsequent
7379 static void EmitStopParametersAndFollow (pge_FactorDesc f
, pge_m2condition m
)
7387 CalcFirstFactor(f, NIL, to)
7390 CollectFollow (&to
, f
->followinfo
);
7391 EmitStopParametersAndSet (to
);
7395 Output_WriteString ((const char *) "factor is: ", 11);
7396 PrettyCommentFactor (f
, StrLib_StrLen ((const char *) "factor is: ", 11));
7398 Output_WriteString ((const char *) "follow set:", 11);
7399 EmitSet (to
, static_cast<unsigned int> (0), static_cast<unsigned int> (0));
7406 EmitFirstAsParameters -
7409 static void EmitFirstAsParameters (pge_FactorDesc f
)
7414 CalcFirstFactor (f
, NULL
, &to
);
7415 EmitSetAsParameters (to
);
7420 RecoverProduction - only encode grammer rules which are not special.
7421 Generate error recovery code.
7424 static void RecoverProduction (pge_ProductionDesc p
)
7426 DynamicStrings_String s
;
7428 if ((p
!= NULL
) && (! p
->firstsolved
|| ((p
->statement
!= NULL
) && (p
->statement
->expr
!= NULL
))))
7430 BeginningOfLine
= TRUE
;
7433 OnLineStart
= FALSE
;
7434 EmitFileLineTag (p
->line
);
7435 IndentString ((const char *) "PROCEDURE ", 10);
7436 Output_WriteKey (GetDefinitionName (p
));
7437 Output_WriteString ((const char *) " (", 2);
7438 ParametersUsed
= (unsigned int) 0;
7439 Output_StartBuffer ();
7440 Output_WriteString ((const char *) ") ;", 3);
7443 OnLineStart
= FALSE
;
7444 EmitFileLineTag (p
->line
);
7446 IndentString ((const char *) "BEGIN", 5);
7448 OnLineStart
= FALSE
;
7449 EmitFileLineTag (p
->line
);
7451 RecoverStatement (p
->statement
, pge_m2none
);
7453 IndentString ((const char *) "END ", 4);
7454 Output_WriteKey (GetDefinitionName (p
));
7455 Output_WriteString ((const char *) " ;", 2);
7459 s
= Output_EndBuffer ();
7460 EmitStopParameters (TRUE
);
7461 Output_KillWriteS (s
);
7467 IsWhite - returns TRUE if, ch, is a space or a tab.
7470 static unsigned int IsWhite (char ch
)
7472 return ((ch
== ' ') || (ch
== ASCII_tab
)) || (ch
== ASCII_lf
);
7473 /* static analysis guarentees a RETURN statement will be used before here. */
7474 __builtin_unreachable ();
7479 FindStr - returns TRUE if, str, was seen inside the code hunk
7482 static unsigned int FindStr (pge_CodeHunk
*code
, unsigned int *i
, const char *str_
, unsigned int _str_high
)
7487 char str
[_str_high
+1];
7489 /* make a local copy of each unbounded array. */
7490 memcpy (str
, str_
, _str_high
+1);
7493 k
= (StrLib_StrLen ((const char *) &(*code
)->codetext
.array
[0], MaxCodeHunkLength
))+1;
7497 while ((k
> 0) && (IsWhite (t
->codetext
.array
[k
-1])))
7504 k
= MaxCodeHunkLength
+1;
7506 } while (! ((t
== NULL
) || (! (IsWhite (t
->codetext
.array
[k
-1])))));
7507 /* found another word check it */
7510 j
= StrLib_StrLen ((const char *) str
, _str_high
);
7512 while (((t
!= NULL
) && (j
> 0)) && ((str
[j
-1] == t
->codetext
.array
[k
-1]) || ((IsWhite (str
[j
-1])) && (IsWhite (t
->codetext
.array
[k
-1])))))
7518 /* found word remember position */
7524 k
= MaxCodeHunkLength
+1;
7537 return (t
== NULL
) && (j
== 0);
7538 /* static analysis guarentees a RETURN statement will be used before here. */
7539 __builtin_unreachable ();
7547 static void WriteUpto (pge_CodeHunk code
, pge_CodeHunk upto
, unsigned int limit
)
7551 WriteUpto (code
->next
, upto
, limit
);
7552 Output_WriteString ((const char *) &code
->codetext
.array
[0], MaxCodeHunkLength
);
7556 while ((limit
<= MaxCodeHunkLength
) && (code
->codetext
.array
[limit
] != ASCII_nul
))
7558 Output_Write (code
->codetext
.array
[limit
]);
7566 CheckForVar - checks for any local variables which need to be emitted during
7570 static void CheckForVar (pge_CodeHunk code
)
7576 if ((FindStr (&t
, &i
, (const char *) "VAR", 3)) && EmitCode
)
7582 IndentString ((const char *) "VAR", 3);
7587 WriteUpto (code
, t
, i
);
7596 static void VarFactor (pge_FactorDesc f
)
7611 VarExpression (f
->expr
);
7615 CheckForVar (f
->code
->code
);
7631 static void VarTerm (pge_TermDesc t
)
7635 VarFactor (t
->factor
);
7645 static void VarExpression (pge_ExpressionDesc e
)
7658 static void VarStatement (pge_StatementDesc s
)
7662 VarExpression (s
->expr
);
7668 VarProduction - writes out all variable declarations.
7671 static void VarProduction (pge_ProductionDesc p
)
7676 VarStatement (p
->statement
);
7682 In - returns TRUE if token, s, is already in the set, to.
7685 static unsigned int In (pge_SetDesc to
, NameKey_Name s
)
7692 if (s
== to
->ident
->name
)
7700 if (s
== to
->string
)
7708 PushBackInput_WarnError ((const char *) "internal error CASE type not known", 34);
7715 /* static analysis guarentees a RETURN statement will be used before here. */
7716 __builtin_unreachable ();
7721 IntersectionIsNil - given two set lists, s1, s2, return TRUE if the
7725 static unsigned int IntersectionIsNil (pge_SetDesc s1
, pge_SetDesc s2
)
7732 if (In (s2
, s1
->ident
->name
))
7740 if (In (s2
, s1
->string
))
7748 PushBackInput_WarnError ((const char *) "internal error CASE type not known", 34);
7755 /* static analysis guarentees a RETURN statement will be used before here. */
7756 __builtin_unreachable ();
7761 AddSet - adds a first symbol to a production.
7764 static void AddSet (pge_SetDesc
*to
, NameKey_Name s
)
7768 if (! (In ((*to
), s
)))
7771 d
->type
= pge_tokel
;
7784 static void OrSet (pge_SetDesc
*to
, pge_SetDesc from
)
7786 while (from
!= NULL
)
7791 AddSet (to
, from
->string
);
7795 AddSet (to
, SymbolKey_GetSymKey (Aliases
, from
->string
));
7799 PushBackInput_WarnError ((const char *) "not expecting ident in first symbol list", 40);
7805 Debug_Halt ((const char *) "unknown element in enumeration type", 35, 4122, (const char *) "m2/gm2-auto/pge.mod", 19);
7817 static void CalcFirstFactor (pge_FactorDesc f
, pge_ProductionDesc from
, pge_SetDesc
*to
)
7824 if (f
->ident
->definition
== NULL
)
7826 WarnError1 ((const char *) "no rule found for an 'ident' called '%s'", 40, f
->ident
->name
);
7828 __builtin_unreachable ();
7830 OrSet (to
, f
->ident
->definition
->first
);
7831 if ((GetReachEnd (f
->ident
->definition
->followinfo
)) == pge_false
)
7838 if ((SymbolKey_GetSymKey (Aliases
, f
->string
)) == SymbolKey_NulKey
)
7840 WarnError1 ((const char *) "unknown token for '%s'", 22, f
->string
);
7845 AddSet (to
, SymbolKey_GetSymKey (Aliases
, f
->string
));
7853 CalcFirstExpression (f
->expr
, from
, to
);
7872 static void CalcFirstTerm (pge_TermDesc t
, pge_ProductionDesc from
, pge_SetDesc
*to
)
7876 CalcFirstFactor (t
->factor
, from
, to
);
7883 CalcFirstExpression -
7886 static void CalcFirstExpression (pge_ExpressionDesc e
, pge_ProductionDesc from
, pge_SetDesc
*to
)
7890 CalcFirstTerm (e
->term
, from
, to
);
7896 CalcFirstStatement -
7899 static void CalcFirstStatement (pge_StatementDesc s
, pge_ProductionDesc from
, pge_SetDesc
*to
)
7903 CalcFirstExpression (s
->expr
, from
, to
);
7909 CalcFirstProduction - calculates all of the first symbols for the grammer
7912 static void CalcFirstProduction (pge_ProductionDesc p
, pge_ProductionDesc from
, pge_SetDesc
*to
)
7918 /* avoid gcc warning by using compound statement even if not strictly necessary. */
7927 CalcFirstProduction (s
->ident
->definition
, from
, to
);
7932 AddSet (to
, s
->string
);
7944 CalcFirstStatement (p
->statement
, from
, to
);
7949 static void WorkOutFollowFactor (pge_FactorDesc f
, pge_SetDesc
*followset
, pge_SetDesc after
)
7951 pge_TraverseResult foundepsilon
;
7952 pge_TraverseResult canreachend
;
7957 foundepsilon
= pge_true
;
7958 canreachend
= pge_true
;
7959 while ((f
!= NULL
) && (foundepsilon
== pge_true
))
7964 if (f
->ident
->definition
== NULL
)
7966 WarnError1 ((const char *) "no rule found for an 'ident' called '%s'", 40, f
->ident
->name
);
7968 __builtin_unreachable ();
7970 OrSet (followset
, f
->ident
->definition
->first
);
7974 AddSet (followset
, SymbolKey_GetSymKey (Aliases
, f
->string
));
7978 WorkOutFollowExpression (f
->expr
, followset
, NULL
);
7982 WorkOutFollowExpression (f
->expr
, followset
, NULL
);
7986 WorkOutFollowExpression (f
->expr
, followset
, NULL
);
7996 if ((GetEpsilon (f
->followinfo
)) == pge_unknown
)
7998 PushBackInput_WarnError ((const char *) "internal error: epsilon unknown", 31);
7999 PrettyCommentFactor (f
, 3);
8002 foundepsilon
= GetEpsilon (f
->followinfo
);
8003 canreachend
= GetReachEnd (f
->followinfo
); /* only goes from FALSE -> TRUE */
8004 f
= f
->next
; /* only goes from FALSE -> TRUE */
8006 if (canreachend
== pge_true
)
8008 OrSet (followset
, after
);
8017 static void WorkOutFollowTerm (pge_TermDesc t
, pge_SetDesc
*followset
, pge_SetDesc after
)
8023 WorkOutFollowFactor (t
->factor
, followset
, after
); /* { '|' Term } */
8024 t
= t
->next
; /* { '|' Term } */
8031 WorkOutFollowExpression -
8034 static void WorkOutFollowExpression (pge_ExpressionDesc e
, pge_SetDesc
*followset
, pge_SetDesc after
)
8038 WorkOutFollowTerm (e
->term
, followset
, after
);
8044 CollectFollow - collects the follow set from, f, into, to.
8047 static void CollectFollow (pge_SetDesc
*to
, pge_FollowDesc f
)
8049 OrSet (to
, f
->follow
);
8057 static void CalcFollowFactor (pge_FactorDesc f
, pge_SetDesc after
)
8064 WorkOutFollowFactor (f
->next
, &f
->followinfo
->follow
, after
);
8068 WorkOutFollowFactor (f
->next
, &f
->followinfo
->follow
, after
);
8073 CalcFirstFactor (f
->next
, NULL
, &f
->followinfo
->follow
);
8074 if ((f
->next
== NULL
) || ((GetReachEnd (f
->next
->followinfo
)) == pge_true
))
8076 OrSet (&f
->followinfo
->follow
, after
);
8077 CalcFollowExpression (f
->expr
, f
->followinfo
->follow
);
8081 CalcFollowExpression (f
->expr
, f
->followinfo
->follow
);
8086 CalcFirstFactor (f
, NULL
, &f
->followinfo
->follow
);
8087 /* include first as we may repeat this sentance */
8091 StrIO_WriteString ((const char *) "found mult: and first is: ", 26);
8092 EmitSet (f
->followinfo
->follow
, static_cast<unsigned int> (0), static_cast<unsigned int> (0));
8095 if ((f
->next
== NULL
) || ((GetReachEnd (f
->next
->followinfo
)) == pge_true
))
8097 OrSet (&f
->followinfo
->follow
, after
);
8098 CalcFollowExpression (f
->expr
, f
->followinfo
->follow
);
8102 CalcFollowExpression (f
->expr
, f
->followinfo
->follow
);
8119 static void CalcFollowTerm (pge_TermDesc t
, pge_SetDesc after
)
8125 CalcFollowFactor (t
->factor
, after
); /* { '|' Term } */
8126 t
= t
->next
; /* { '|' Term } */
8133 CalcFollowExpression -
8136 static void CalcFollowExpression (pge_ExpressionDesc e
, pge_SetDesc after
)
8140 CalcFollowTerm (e
->term
, after
);
8146 CalcFollowStatement - given a bnf statement generate the follow set.
8149 static void CalcFollowStatement (pge_StatementDesc s
)
8153 CalcFollowExpression (s
->expr
, NULL
);
8159 CalcFollowProduction -
8162 static void CalcFollowProduction (pge_ProductionDesc p
)
8166 CalcFollowStatement (p
->statement
);
8175 static void CalcEpsilonFactor (pge_FactorDesc f
)
8182 AssignEpsilon ((GetEpsilon (f
->ident
->definition
->followinfo
)) != pge_unknown
, f
->followinfo
, GetEpsilon (f
->ident
->definition
->followinfo
));
8186 AssignEpsilon (TRUE
, f
->followinfo
, pge_false
);
8190 CalcEpsilonExpression (f
->expr
);
8191 AssignEpsilon ((GetEpsilon (f
->expr
->followinfo
)) != pge_unknown
, f
->followinfo
, GetEpsilon (f
->expr
->followinfo
));
8195 AssignEpsilon (TRUE
, f
->followinfo
, pge_true
);
8200 CalcEpsilonExpression (f
->expr
);
8201 AssignEpsilon (TRUE
, f
->followinfo
, pge_true
);
8217 static void CalcEpsilonTerm (pge_TermDesc t
)
8223 if (t
->factor
!= NULL
)
8225 switch (GetReachEnd (t
->factor
->followinfo
))
8228 AssignEpsilon (TRUE
, t
->followinfo
, pge_true
);
8232 AssignEpsilon (TRUE
, t
->followinfo
, pge_false
);
8243 CalcEpsilonFactor (t
->factor
); /* { '|' Term } */
8251 CalcEpsilonExpression -
8254 static void CalcEpsilonExpression (pge_ExpressionDesc e
)
8257 pge_TraverseResult result
;
8261 CalcEpsilonTerm (e
->term
);
8262 if ((GetEpsilon (e
->followinfo
)) == pge_unknown
)
8264 result
= pge_unknown
;
8268 if ((GetEpsilon (t
->followinfo
)) != pge_unknown
)
8272 switch (GetEpsilon (t
->followinfo
))
8282 if (result
!= pge_true
)
8294 AssignEpsilon (result
!= pge_unknown
, e
->followinfo
, result
);
8301 CalcEpsilonStatement - given a bnf statement generate the follow set.
8304 static void CalcEpsilonStatement (pge_StatementDesc s
)
8308 if (s
->expr
!= NULL
)
8310 AssignEpsilon ((GetEpsilon (s
->expr
->followinfo
)) != pge_unknown
, s
->followinfo
, GetEpsilon (s
->expr
->followinfo
));
8312 CalcEpsilonExpression (s
->expr
);
8318 CalcEpsilonProduction -
8321 static void CalcEpsilonProduction (pge_ProductionDesc p
)
8326 IF p^.statement^.ident^.name=MakeKey('DefinitionModule')
8333 NameKey_WriteKey (p
->statement
->ident
->name
);
8334 StrIO_WriteString ((const char *) " calculating epsilon", 21);
8337 AssignEpsilon ((GetEpsilon (p
->statement
->followinfo
)) != pge_unknown
, p
->followinfo
, GetEpsilon (p
->statement
->followinfo
));
8338 CalcEpsilonStatement (p
->statement
);
8344 CalcReachEndFactor -
8347 static pge_TraverseResult
CalcReachEndFactor (pge_FactorDesc f
)
8349 pge_TraverseResult canreachend
;
8350 pge_TraverseResult result
;
8354 return pge_true
; /* we have reached the end of this factor list */
8358 /* we need to traverse all factors even if we can short cut the answer to this list of factors */
8359 result
= CalcReachEndFactor (f
->next
);
8363 if (f
->ident
->definition
== NULL
)
8365 WarnError1 ((const char *) "definition for %s is absent (assuming epsilon is false for this production)", 75, f
->ident
->name
);
8368 else if (result
!= pge_false
)
8370 /* avoid dangling else. */
8371 switch (GetReachEnd (f
->ident
->definition
->followinfo
))
8381 result
= pge_unknown
;
8396 CalcReachEndExpression (f
->expr
);
8397 if ((f
->expr
!= NULL
) && (result
== pge_true
))
8399 result
= GetReachEnd (f
->expr
->followinfo
);
8405 if (f
->expr
!= NULL
)
8407 /* not interested in the result as expression is optional */
8408 CalcReachEndExpression (f
->expr
);
8419 AssignReachEnd (result
!= pge_unknown
, f
->followinfo
, result
);
8422 /* static analysis guarentees a RETURN statement will be used before here. */
8423 __builtin_unreachable ();
8431 static pge_TraverseResult
CalcReachEndTerm (pge_TermDesc t
)
8433 pge_TraverseResult canreachend
;
8434 pge_TraverseResult result
;
8438 canreachend
= pge_false
;
8441 result
= CalcReachEndFactor (t
->factor
);
8442 AssignReachEnd (result
!= pge_unknown
, t
->followinfo
, result
);
8446 canreachend
= pge_true
;
8453 if (canreachend
== pge_false
)
8455 canreachend
= pge_unknown
;
8463 t
= t
->next
; /* { '|' Term } */
8467 /* static analysis guarentees a RETURN statement will be used before here. */
8468 __builtin_unreachable ();
8473 CalcReachEndExpression -
8476 static void CalcReachEndExpression (pge_ExpressionDesc e
)
8478 pge_TraverseResult result
;
8484 /* no expression, thus reached the end of this sentance */
8485 result
= CalcReachEndTerm (e
->term
);
8486 AssignReachEnd (result
!= pge_unknown
, e
->followinfo
, result
);
8492 CalcReachEndStatement -
8495 static void CalcReachEndStatement (pge_StatementDesc s
)
8499 if (s
->expr
!= NULL
)
8501 CalcReachEndExpression (s
->expr
);
8502 AssignReachEnd ((GetReachEnd (s
->expr
->followinfo
)) != pge_unknown
, s
->followinfo
, GetReachEnd (s
->expr
->followinfo
));
8509 CalcReachEndStatement -
8512 static void stop (void)
8518 CalcReachEndProduction -
8521 static void CalcReachEndProduction (pge_ProductionDesc p
)
8525 CalcReachEndStatement (p
->statement
);
8526 if ((GetReachEnd (p
->followinfo
)) != pge_unknown
)
8530 StrIO_WriteString ((const char *) "already calculated reach end for: ", 34);
8531 NameKey_WriteKey (p
->statement
->ident
->name
);
8532 StrIO_WriteString ((const char *) " its value is ", 14);
8533 if ((GetReachEnd (p
->followinfo
)) == pge_true
)
8535 StrIO_WriteString ((const char *) "reachable", 9);
8539 StrIO_WriteString ((const char *) "non reachable", 13);
8544 AssignReachEnd ((GetReachEnd (p
->statement
->followinfo
)) != pge_unknown
, p
->followinfo
, GetReachEnd (p
->statement
->followinfo
));
8553 static unsigned int EmptyFactor (pge_FactorDesc f
)
8560 if (! (EmptyProduction (f
->ident
->definition
)))
8571 if (! (EmptyExpression (f
->expr
)))
8592 /* static analysis guarentees a RETURN statement will be used before here. */
8593 __builtin_unreachable ();
8598 EmptyTerm - returns TRUE if the term maybe empty.
8601 static unsigned int EmptyTerm (pge_TermDesc t
)
8605 if (EmptyFactor (t
->factor
))
8615 /* static analysis guarentees a RETURN statement will be used before here. */
8616 __builtin_unreachable ();
8624 static unsigned int EmptyExpression (pge_ExpressionDesc e
)
8632 return EmptyTerm (e
->term
);
8634 /* static analysis guarentees a RETURN statement will be used before here. */
8635 __builtin_unreachable ();
8640 EmptyStatement - returns TRUE if statement, s, is empty.
8643 static unsigned int EmptyStatement (pge_StatementDesc s
)
8651 return EmptyExpression (s
->expr
);
8653 /* static analysis guarentees a RETURN statement will be used before here. */
8654 __builtin_unreachable ();
8659 EmptyProduction - returns if production, p, maybe empty.
8662 static unsigned int EmptyProduction (pge_ProductionDesc p
)
8666 PushBackInput_WarnError ((const char *) "unknown production", 18);
8669 else if (p
->firstsolved
&& (p
->first
!= NULL
))
8671 /* avoid dangling else. */
8672 /* predefined but first set to something - thus not empty */
8677 /* avoid dangling else. */
8678 return EmptyStatement (p
->statement
);
8680 /* static analysis guarentees a RETURN statement will be used before here. */
8681 __builtin_unreachable ();
8689 static void EmitFDLNotice (void)
8691 Output_WriteString ((const char *) "@c Copyright (C) 2000-2023 Free Software Foundation, Inc.", 57);
8694 Output_WriteString ((const char *) "@c This file is part of GCC.", 28);
8696 Output_WriteString ((const char *) "@c Permission is granted to copy, distribute and/or modify this document", 72);
8698 Output_WriteString ((const char *) "@c under the terms of the GNU Free Documentation License, Version 1.2 or", 72);
8700 Output_WriteString ((const char *) "@c any later version published by the Free Software Foundation.", 63);
8706 EmitRules - generates the BNF rules.
8709 static void EmitRules (void)
8711 if (Texinfo
&& FreeDocLicense
)
8715 ForeachRuleDo ((pge_DoProcedure
) {(pge_DoProcedure_t
) EmitRule
});
8723 static void DescribeElement (unsigned int name
)
8729 InitialElement
= FALSE
;
8733 Output_WriteString ((const char *) " |", 2);
8737 IndentString ((const char *) "", 0);
8738 Output_WriteKey (name
);
8739 Output_WriteString ((const char *) ": ", 2);
8740 lit
= static_cast<NameKey_Name
> (SymbolKey_GetSymKey (ReverseAliases
, name
));
8741 if ((NameKey_MakeKey ((const char *) "\"", 1)) == lit
)
8743 Output_WriteString ((const char *) "str := ConCat(ConCatChar(ConCatChar(InitString(\"syntax error, found ", 68);
8744 Output_Write ('\'');
8745 Output_WriteString ((const char *) "\"), ", 4);
8746 Output_Write ('\'');
8748 Output_Write ('\'');
8749 Output_WriteString ((const char *) "), ", 3);
8751 Output_Write ('\'');
8753 Output_WriteString ((const char *) "), Mark(str))", 13);
8755 else if ((NameKey_MakeKey ((const char *) "'", 1)) == lit
)
8757 /* avoid dangling else. */
8758 Output_WriteString ((const char *) "str := ConCat(ConCatChar(ConCatChar(InitString('syntax error, found ", 68);
8760 Output_WriteString ((const char *) "'), ", 4);
8762 Output_Write ('\'');
8764 Output_WriteString ((const char *) "), ", 3);
8765 Output_Write ('\'');
8767 Output_Write ('\'');
8768 Output_WriteString ((const char *) "), Mark(str))", 13);
8772 /* avoid dangling else. */
8773 Output_WriteString ((const char *) "str := ConCat(InitString(", 25);
8775 Output_WriteString ((const char *) "syntax error, found ", 20);
8777 Output_WriteString ((const char *) "\"), Mark(str))", 14);
8783 EmitInTestStop - construct a test for stop element, name.
8786 static void EmitInTestStop (NameKey_Name name
)
8791 if (LargestValue
<= MaxElementsInSet
)
8793 Output_WriteKey (name
);
8794 Output_WriteString ((const char *) " IN stopset", 11);
8795 ParametersUsed
|= (1 << (0 ));
8799 value
= static_cast<unsigned int> (SymbolKey_GetSymKey (Values
, name
));
8800 i
= value
/ MaxElementsInSet
;
8801 Output_WriteKey (name
);
8802 Output_WriteString ((const char *) " IN stopset", 11);
8803 Output_WriteCard (i
, 0);
8804 ParametersUsed
|= (1 << (i
));
8810 DescribeStopElement -
8813 static void DescribeStopElement (unsigned int name
)
8818 IndentString ((const char *) "IF ", 3);
8819 EmitInTestStop (name
);
8821 IndentString ((const char *) "THEN", 4);
8824 lit
= static_cast<NameKey_Name
> (SymbolKey_GetSymKey (ReverseAliases
, name
));
8825 if ((lit
== NameKey_NulName
) || (lit
== (NameKey_MakeKey ((const char *) "", 0))))
8827 IndentString ((const char *) "(* ", 3);
8828 Output_WriteKey (name
);
8829 Output_WriteString ((const char *) " has no token name (needed to generate error messages) *)", 57);
8831 else if ((NameKey_MakeKey ((const char *) "'", 1)) == lit
)
8833 /* avoid dangling else. */
8834 IndentString ((const char *) "message := ConCatChar(ConCatChar(ConCatChar(ConCatChar(ConCatChar(message, ", 75);
8835 Output_WriteString ((const char *) "' '), ", 6);
8836 Output_Write ('\'');
8838 Output_WriteString ((const char *) "'), ", 4);
8840 Output_Write ('\'');
8841 Output_WriteString ((const char *) "\"), ", 4);
8842 Output_Write ('\'');
8844 Output_WriteString ((const char *) "'), ',') ; INC(n) ; ", 20);
8846 else if ((NameKey_MakeKey ((const char *) "\"", 1)) == lit
)
8848 /* avoid dangling else. */
8849 IndentString ((const char *) "message := ConCatChar(ConCatChar(ConCatChar(ConCatChar(ConCatChar(message, ", 75);
8850 Output_WriteString ((const char *) "\" \"), ", 6);
8853 Output_WriteString ((const char *) "\"), ", 4);
8854 Output_Write ('\'');
8856 Output_WriteString ((const char *) "'), ", 4);
8858 Output_Write ('\'');
8859 Output_WriteString ((const char *) "\"), \",\") ; INC(n) ; ", 20);
8863 /* avoid dangling else. */
8864 IndentString ((const char *) "message := ConCat(ConCatChar(message, ' ", 40);
8865 Output_WriteString ((const char *) "'), ", 4);
8866 Output_WriteString ((const char *) "Mark(InitString(\"", 17);
8869 Output_WriteString ((const char *) "))) ; INC(n)", 12);
8873 IndentString ((const char *) "END ;", 5);
8882 static void EmitDescribeStop (void)
8884 DynamicStrings_String s
;
8888 IndentString ((const char *) "(*", 2);
8891 IndentString ((const char *) "DescribeStop - issues a message explaining what tokens were expected", 68);
8893 Output_WriteString ((const char *) "*)", 2);
8897 IndentString ((const char *) "PROCEDURE DescribeStop (", 24);
8898 ParametersUsed
= (unsigned int) 0;
8899 Output_StartBuffer ();
8900 Output_WriteString ((const char *) ") : String ;", 12);
8902 IndentString ((const char *) "VAR", 3);
8905 IndentString ((const char *) "n : CARDINAL ;", 19);
8907 IndentString ((const char *) "str,", 4);
8909 IndentString ((const char *) "message: String ;", 17);
8912 IndentString ((const char *) "BEGIN", 5);
8915 IndentString ((const char *) "n := 0 ;", 8);
8917 IndentString ((const char *) "message := InitString('') ;", 27);
8919 SymbolKey_ForeachNodeDo (Aliases
, (SymbolKey_PerformOperation
) {(SymbolKey_PerformOperation_t
) DescribeStopElement
});
8922 IndentString ((const char *) "IF n=0", 6);
8924 IndentString ((const char *) "THEN", 4);
8927 IndentString ((const char *) "str := InitString(' syntax error') ; ", 37);
8929 IndentString ((const char *) "message := KillString(message) ; ", 33);
8932 IndentString ((const char *) "ELSIF n=1", 9);
8934 IndentString ((const char *) "THEN", 4);
8937 IndentString ((const char *) "str := ConCat(message, Mark(InitString(' missing '))) ;", 55);
8940 IndentString ((const char *) "ELSE", 4);
8943 IndentString ((const char *) "str := ConCat(InitString(' expecting one of'), message) ;", 57);
8945 IndentString ((const char *) "message := KillString(message) ;", 32);
8948 IndentString ((const char *) "END ;", 5);
8950 IndentString ((const char *) "RETURN( str )", 13);
8953 IndentString ((const char *) "END DescribeStop ;", 18);
8956 s
= Output_EndBuffer ();
8957 EmitStopParameters (TRUE
);
8958 Output_KillWriteS (s
);
8966 static void EmitDescribeError (void)
8970 IndentString ((const char *) "(*", 2);
8973 IndentString ((const char *) "DescribeError - issues a message explaining what tokens were expected", 69);
8976 IndentString ((const char *) "*)", 2);
8979 IndentString ((const char *) "PROCEDURE DescribeError ;", 25);
8981 IndentString ((const char *) "VAR", 3);
8984 IndentString ((const char *) "str: String ;", 13);
8987 IndentString ((const char *) "BEGIN", 5);
8990 IndentString ((const char *) "str := InitString('') ;", 23);
8993 IndentString('str := DescribeStop(') ; EmitStopParameters(FALSE) ; Output.WriteString(') ;') ; Output.WriteLn ;
8995 IndentString ((const char *) "CASE ", 5);
8996 WriteGetTokenType ();
8997 Output_WriteString ((const char *) " OF", 3);
8999 InitialElement
= TRUE
;
9000 SymbolKey_ForeachNodeDo (Aliases
, (SymbolKey_PerformOperation
) {(SymbolKey_PerformOperation_t
) DescribeElement
});
9003 IndentString ((const char *) "ELSE", 4);
9005 IndentString ((const char *) "END ;", 5);
9007 IndentString ((const char *) "", 0);
9008 Output_WriteKey (ErrorProcString
);
9009 Output_WriteString ((const char *) "(str) ;", 7);
9012 IndentString ((const char *) "END DescribeError ;", 19);
9018 EmitSetTypes - write out the set types used during error recovery
9021 static void EmitSetTypes (void)
9028 Output_WriteString ((const char *) "(*", 2);
9030 Output_WriteString ((const char *) "expecting token set defined as an enumerated type", 49);
9032 Output_WriteString ((const char *) "(", 1);
9034 while (i
< LargestValue
)
9036 Output_WriteKey (SymbolKey_GetSymKey (ReverseValues
, (unsigned int ) (i
)));
9038 if (i
< LargestValue
)
9040 Output_WriteString ((const char *) ", ", 2);
9043 Output_WriteString ((const char *) ") ;", 3);
9045 Output_WriteString ((const char *) "*)", 2);
9047 Output_WriteString ((const char *) "TYPE", 4);
9049 if (LargestValue
> MaxElementsInSet
)
9052 n
= LargestValue
/ MaxElementsInSet
;
9055 j
= i
*MaxElementsInSet
;
9056 if (LargestValue
< (((i
+1)*MaxElementsInSet
)-1))
9062 m
= ((i
+1)*MaxElementsInSet
)-1;
9064 Output_WriteString ((const char *) "stop", 4);
9065 Output_WriteCard (i
, 0);
9066 Output_WriteString ((const char *) " = [", 4);
9067 Output_WriteKey (SymbolKey_GetSymKey (ReverseValues
, (unsigned int ) (j
)));
9068 Output_WriteString ((const char *) "..", 2);
9069 Output_WriteKey (SymbolKey_GetSymKey (ReverseValues
, (unsigned int ) (m
)));
9070 Output_WriteString ((const char *) "] ;", 3);
9072 Output_WriteString ((const char *) "SetOfStop", 9);
9073 Output_WriteCard (i
, 0);
9074 Output_WriteString ((const char *) " = SET OF stop", 14);
9075 Output_WriteCard (i
, 0);
9076 Output_WriteString ((const char *) " ;", 2);
9083 Output_WriteString ((const char *) "SetOfStop", 9);
9084 Output_WriteString ((const char *) " = SET OF [", 11);
9085 Output_WriteKey (SymbolKey_GetSymKey (ReverseValues
, (unsigned int ) (0)));
9086 Output_WriteString ((const char *) "..", 2);
9087 Output_WriteKey (SymbolKey_GetSymKey (ReverseValues
, (unsigned int ) (LargestValue
-1)));
9088 Output_WriteString ((const char *) "] ;", 3);
9095 EmitSupport - generates the support routines.
9098 static void EmitSupport (void)
9103 EmitDescribeStop ();
9104 EmitDescribeError ();
9110 DisposeSetDesc - dispose of the set list, s.
9113 static void DisposeSetDesc (pge_SetDesc
*s
)
9123 Storage_DEALLOCATE ((void **) &h
, sizeof (pge__T7
));
9129 } while (! (h
== NULL
));
9139 static unsigned int OptionalFactor (pge_FactorDesc f
)
9154 if (OptionalExpression (f
->expr
))
9170 /* static analysis guarentees a RETURN statement will be used before here. */
9171 __builtin_unreachable ();
9176 OptionalTerm - returns TRUE if the term maybe empty.
9179 static unsigned int OptionalTerm (pge_TermDesc t
)
9189 if (OptionalFactor (u
->factor
))
9195 CalcFirstFactor (u
->factor
, NULL
, &tou
);
9201 CalcFirstFactor (v
->factor
, NULL
, &tov
);
9202 if (IntersectionIsNil (tov
, tou
))
9204 DisposeSetDesc (&tov
);
9208 StrIO_WriteString ((const char *) "problem with two first sets. Set 1: ", 36);
9209 EmitSet (tou
, static_cast<unsigned int> (0), static_cast<unsigned int> (0));
9211 StrIO_WriteString ((const char *) " Set 2: ", 36);
9212 EmitSet (tov
, static_cast<unsigned int> (0), static_cast<unsigned int> (0));
9214 DisposeSetDesc (&tou
);
9215 DisposeSetDesc (&tov
);
9221 DisposeSetDesc (&tou
);
9225 /* static analysis guarentees a RETURN statement will be used before here. */
9226 __builtin_unreachable ();
9231 OptionalExpression -
9234 static unsigned int OptionalExpression (pge_ExpressionDesc e
)
9242 return OptionalTerm (e
->term
);
9244 /* static analysis guarentees a RETURN statement will be used before here. */
9245 __builtin_unreachable ();
9250 OptionalStatement - returns FALSE if statement, s, does not have a optional ambiguity.
9253 static unsigned int OptionalStatement (pge_StatementDesc s
)
9261 return OptionalExpression (s
->expr
);
9263 /* static analysis guarentees a RETURN statement will be used before here. */
9264 __builtin_unreachable ();
9269 OptionalProduction -
9272 static unsigned int OptionalProduction (pge_ProductionDesc p
)
9280 return OptionalStatement (p
->statement
);
9282 /* static analysis guarentees a RETURN statement will be used before here. */
9283 __builtin_unreachable ();
9291 static unsigned int CheckFirstFollow (pge_FactorDesc f
, pge_FactorDesc after
)
9297 CalcFirstFactor (f
, NULL
, &first
);
9299 follow
= GetFollow (f
->followinfo
);
9300 if (IntersectionIsNil (first
, follow
))
9302 DisposeSetDesc (&first
);
9303 DisposeSetDesc (&follow
);
9308 PrettyCommentFactor (f
, 3);
9310 StrIO_WriteString ((const char *) "first: ", 7);
9311 EmitSet (first
, static_cast<unsigned int> (0), static_cast<unsigned int> (0));
9313 StrIO_WriteString ((const char *) "follow: ", 8);
9314 EmitSet (follow
, static_cast<unsigned int> (0), static_cast<unsigned int> (0));
9316 DisposeSetDesc (&first
);
9317 DisposeSetDesc (&follow
);
9320 /* static analysis guarentees a RETURN statement will be used before here. */
9321 __builtin_unreachable ();
9326 ConstrainedEmptyFactor -
9329 static unsigned int ConstrainedEmptyFactor (pge_FactorDesc f
)
9344 if (ConstrainedEmptyExpression (f
->expr
))
9357 if (((f
->type
!= pge_m2
) && (EmptyFactor (f
))) && (CheckFirstFollow (f
, f
->next
)))
9364 /* static analysis guarentees a RETURN statement will be used before here. */
9365 __builtin_unreachable ();
9370 ConstrainedEmptyTerm - returns TRUE if the term maybe empty.
9373 static unsigned int ConstrainedEmptyTerm (pge_TermDesc t
)
9380 if (ConstrainedEmptyFactor (t
->factor
))
9384 else if (((t
->factor
->type
!= pge_m2
) && (EmptyFactor (t
->factor
))) && (CheckFirstFollow (t
->factor
, t
->factor
->next
)))
9386 /* avoid dangling else. */
9392 /* static analysis guarentees a RETURN statement will be used before here. */
9393 __builtin_unreachable ();
9398 ConstrainedEmptyExpression -
9401 static unsigned int ConstrainedEmptyExpression (pge_ExpressionDesc e
)
9409 return ConstrainedEmptyTerm (e
->term
);
9411 /* static analysis guarentees a RETURN statement will be used before here. */
9412 __builtin_unreachable ();
9417 ConstrainedEmptyStatement - returns FALSE if statement, s, does not have a optional ambiguity.
9420 static unsigned int ConstrainedEmptyStatement (pge_StatementDesc s
)
9428 return ConstrainedEmptyExpression (s
->expr
);
9430 /* static analysis guarentees a RETURN statement will be used before here. */
9431 __builtin_unreachable ();
9436 ConstrainedEmptyProduction - returns TRUE if a problem exists with, p.
9439 static unsigned int ConstrainedEmptyProduction (pge_ProductionDesc p
)
9447 return ConstrainedEmptyStatement (p
->statement
);
9449 /* static analysis guarentees a RETURN statement will be used before here. */
9450 __builtin_unreachable ();
9458 static void TestForLALR1 (pge_ProductionDesc p
)
9460 if (OptionalProduction (p
))
9462 WarnError1 ((const char *) "production %s has two optional sentances using | which both have the same start symbols", 87, p
->statement
->ident
->name
);
9464 PrettyCommentProduction (p
);
9470 DoEpsilon - runs the epsilon interrelated rules
9473 static void DoEpsilon (pge_ProductionDesc p
)
9475 CalcEpsilonProduction (p
);
9476 CalcReachEndProduction (p
);
9481 CheckComplete - checks that production, p, is complete.
9484 static void CheckComplete (pge_ProductionDesc p
)
9486 if ((GetReachEnd (p
->followinfo
)) == pge_unknown
)
9488 PrettyCommentProduction (p
);
9489 WarnError1 ((const char *) "cannot determine epsilon, probably a left recursive rule in %s and associated rules (hint rewrite using ebnf and eliminate left recursion)", 138, p
->statement
->ident
->name
);
9496 PostProcessRules - backpatch the ident to rule definitions and emit comments and code.
9499 static void PostProcessRules (void)
9501 ForeachRuleDo ((pge_DoProcedure
) {(pge_DoProcedure_t
) BackPatchIdentToDefinitions
});
9505 __builtin_unreachable ();
9507 WhileNotCompleteDo ((pge_DoProcedure
) {(pge_DoProcedure_t
) DoEpsilon
});
9511 __builtin_unreachable ();
9513 ForeachRuleDo ((pge_DoProcedure
) {(pge_DoProcedure_t
) CheckComplete
});
9517 __builtin_unreachable ();
9519 WhileNotCompleteDo ((pge_DoProcedure
) {(pge_DoProcedure_t
) CalculateFirstAndFollow
});
9523 __builtin_unreachable ();
9525 ForeachRuleDo ((pge_DoProcedure
) {(pge_DoProcedure_t
) TestForLALR1
});
9528 ForeachRuleDo ((pge_DoProcedure
) {(pge_DoProcedure_t
) PrettyCommentProduction
});
9534 DisplayHelp - display a summary help and then exit (0).
9537 static void DisplayHelp (void)
9539 StrIO_WriteString ((const char *) "Usage: pge [-l] [-c] [-d] [-e] [-k] [-t] [-k] [-p] [-x] [-f] [-o outputfile] filename", 85);
9541 StrIO_WriteString ((const char *) " -l suppress file and line source information", 59);
9543 StrIO_WriteString ((const char *) " -c do not generate any Modula-2 code within the parser rules", 75);
9545 StrIO_WriteString ((const char *) " -h or --help generate this help message", 44);
9547 StrIO_WriteString ((const char *) " -e do not generate a parser with error recovery", 62);
9549 StrIO_WriteString ((const char *) " -k generate keyword errors with GCC formatting directives", 72);
9551 StrIO_WriteString ((const char *) " -d generate internal debugging information", 57);
9553 StrIO_WriteString ((const char *) " -p only display the ebnf rules", 45);
9555 StrIO_WriteString ((const char *) " -t generate texinfo formating for pretty printing (-p)", 69);
9557 StrIO_WriteString ((const char *) " -x generate sphinx formating for pretty printing (-p)", 68);
9559 StrIO_WriteString ((const char *) " -f generate GNU Free Documentation header before pretty printing in texinfo", 90);
9561 StrIO_WriteString ((const char *) " -o write output to filename", 42);
9571 static void ParseArgs (void)
9576 ErrorRecovery
= TRUE
; /* DefaultRecovery ; */
9577 Debugging
= FALSE
; /* DefaultRecovery ; */
9578 PrettyPrint
= FALSE
;
9579 KeywordFormatting
= FALSE
;
9584 if (Args_GetArg ((char *) &ArgName
.array
[0], MaxFileName
, i
))
9586 /* avoid gcc warning by using compound statement even if not strictly necessary. */
9587 if (StrLib_StrEqual ((const char *) &ArgName
.array
[0], MaxFileName
, (const char *) "-e", 2))
9589 ErrorRecovery
= FALSE
;
9591 else if (StrLib_StrEqual ((const char *) &ArgName
.array
[0], MaxFileName
, (const char *) "-d", 2))
9593 /* avoid dangling else. */
9595 bnflex_SetDebugging (TRUE
);
9597 else if (StrLib_StrEqual ((const char *) &ArgName
.array
[0], MaxFileName
, (const char *) "-c", 2))
9599 /* avoid dangling else. */
9602 else if (StrLib_StrEqual ((const char *) &ArgName
.array
[0], MaxFileName
, (const char *) "-k", 2))
9604 /* avoid dangling else. */
9605 KeywordFormatting
= TRUE
;
9607 else if (StrLib_StrEqual ((const char *) &ArgName
.array
[0], MaxFileName
, (const char *) "-l", 2))
9609 /* avoid dangling else. */
9610 SuppressFileLineTag
= TRUE
;
9612 else if ((StrLib_StrEqual ((const char *) &ArgName
.array
[0], MaxFileName
, (const char *) "-h", 2)) || (StrLib_StrEqual ((const char *) &ArgName
.array
[0], MaxFileName
, (const char *) "--help", 6)))
9614 /* avoid dangling else. */
9617 else if (StrLib_StrEqual ((const char *) &ArgName
.array
[0], MaxFileName
, (const char *) "-p", 2))
9619 /* avoid dangling else. */
9622 else if (StrLib_StrEqual ((const char *) &ArgName
.array
[0], MaxFileName
, (const char *) "-t", 2))
9624 /* avoid dangling else. */
9627 else if (StrLib_StrEqual ((const char *) &ArgName
.array
[0], MaxFileName
, (const char *) "-x", 2))
9629 /* avoid dangling else. */
9632 else if (StrLib_StrEqual ((const char *) &ArgName
.array
[0], MaxFileName
, (const char *) "-f", 2))
9634 /* avoid dangling else. */
9635 FreeDocLicense
= TRUE
;
9637 else if (StrLib_StrEqual ((const char *) &ArgName
.array
[0], MaxFileName
, (const char *) "-o", 2))
9639 /* avoid dangling else. */
9641 if (Args_GetArg ((char *) &ArgName
.array
[0], MaxFileName
, i
))
9643 if (! (Output_Open ((const char *) &ArgName
.array
[0], MaxFileName
)))
9645 StrIO_WriteString ((const char *) "cannot open ", 12);
9646 StrIO_WriteString ((const char *) &ArgName
.array
[0], MaxFileName
);
9647 StrIO_WriteString ((const char *) " for writing", 12);
9653 else if (bnflex_OpenSource ((const char *) &ArgName
.array
[0], MaxFileName
))
9655 /* avoid dangling else. */
9656 StrLib_StrCopy ((const char *) &ArgName
.array
[0], MaxFileName
, (char *) &FileName
.array
[0], MaxFileName
);
9657 bnflex_AdvanceToken ();
9661 /* avoid dangling else. */
9662 StrIO_WriteString ((const char *) "cannot open ", 12);
9663 StrIO_WriteString ((const char *) &ArgName
.array
[0], MaxFileName
);
9664 StrIO_WriteString ((const char *) " for reading", 12);
9679 Init - initialize the modules data structures
9682 static void Init (void)
9687 FreeDocLicense
= FALSE
;
9690 HeadProduction
= NULL
;
9691 CurrentProduction
= NULL
;
9692 SymbolKey_InitTree (&Aliases
);
9693 SymbolKey_InitTree (&ReverseAliases
);
9694 SymbolKey_InitTree (&Values
);
9695 SymbolKey_InitTree (&ReverseValues
);
9697 CodePrologue
= NULL
;
9698 CodeEpilogue
= NULL
;
9699 CodeDeclaration
= NULL
;
9700 ErrorProcArray
= NameKey_MakeKey ((const char *) "Error", 5);
9701 ErrorProcString
= NameKey_MakeKey ((const char *) "ErrorS", 6);
9702 TokenTypeProc
= NameKey_MakeKey ((const char *) "GetCurrentTokenType()", 21);
9703 SymIsProc
= NameKey_MakeKey ((const char *) "SymIs", 5);
9706 Main (static_cast<pge_SetOfStop
> ((unsigned int) ((1 << (bnflex_eoftok
))))); /* this line will be manipulated by sed in buildpg */
9707 if (WasNoError
) /* this line will be manipulated by sed in buildpg */
9709 PostProcessRules ();
9712 /* avoid gcc warning by using compound statement even if not strictly necessary. */
9717 else if (PrettyPrint
)
9719 /* avoid dangling else. */
9724 /* avoid dangling else. */
9725 Output_WriteString ((const char *) "(* it is advisable not to edit this file as it was automatically generated from the grammer file ", 97);
9726 Output_WriteString ((const char *) &FileName
.array
[0], MaxFileName
);
9727 Output_WriteString ((const char *) " *)", 3);
9729 OnLineStart
= FALSE
;
9730 EmitFileLineTag (LinePrologue
);
9731 BeginningOfLine
= TRUE
;
9732 WriteCodeHunkList (CodePrologue
);
9734 EmitFileLineTag (LineDeclaration
);
9735 WriteCodeHunkList (CodeDeclaration
);
9738 EmitFileLineTag (LineEpilogue
);
9739 WriteCodeHunkList (CodeEpilogue
);
9746 extern "C" void _M2_pge_init (__attribute__((unused
)) int argc
,__attribute__((unused
)) char *argv
[],__attribute__((unused
)) char *envp
[])
9751 extern "C" void _M2_pge_finish (__attribute__((unused
)) int argc
,__attribute__((unused
)) char *argv
[],__attribute__((unused
)) char *envp
[])