1 // Run-time for grammars
3 typedef struct ParseValue ParseValue
;
4 typedef struct Gram Gram
;
5 typedef struct GramPrec GramPrec
;
6 typedef struct Ast Ast
;
7 typedef struct Line Line
;
10 typedef ParseValue CfgValue
;
11 typedef void SlrLexerArg
;
17 #define RgTokenL GlrTokenL
18 #define RgToken GlrToken
19 #define RgParse GlrParse
20 #define mkRgTokenL mkGlrTokenL
21 #define revRgTokenL revGlrTokenL
22 #define RgTokenLL GlrTokenLL
23 #define mkRgTokenLL mkGlrTokenLL
24 #define revRgTokenLL revGlrTokenLL
25 #define rgnewparse glrnewparse
26 #define rgfreeparse (void)
27 #define rgnewtoken glrnewtoken
28 #define rgparse glrparse
39 typedef CfgSymL DKeyL
;
65 Gram
* mkGram(Name name
);
66 void gramaddrule(Type
*, GramPrec
*, CfgSym
*, CfgSymL
*);
67 CfgSym
* gramsym(Type
*, Name
);
68 CfgSym
* gramliteral(Type
*, Name
);
69 CfgSym
* gramregexp(Type
*, Name
, int regexpflags
, int canfail
);
70 GramPrec
* gramprec(Gram
*, Name
, CfgAssoc
, CfgPrecKind
, int creat
);
71 CfgSym
* gramlooksym(Gram
*, Name
);
72 CfgRule
* gramlookrule(Gram
*, Name
);
73 CfgSym
* gramunlistsym(Gram
*, CfgSym
*);
75 int gramignoring(Gram
*, CfgSym
*);
76 CfgSym
* gramignore(Gram
*, Name
, int, int);
77 int grampriority(Gram
*, Name
, Name
, int);
87 // TODO: Replace ParseValue with Ast.
90 int ref
; // reference count during parsing
95 ParseValue
*mkParseValue(Ast
*);
96 void pvfree(CfgSym
*, CfgValue
*);
97 void pvdup(CfgSym
*, CfgValue
**, CfgValue
*);
99 Ast
*parsetext(Type
*, Name
);
102 // Abstract syntax trees
103 #define NoParentYet ((Ast*)-1)
105 typedef struct Attr Attr
;
131 Ast
*mkastrule(CfgRule
*, Ast
**);
132 Ast
*mkaststring(CfgSym
*, Name
);
133 Ast
*mkastmerge(Ast
*, Ast
*);
134 Ast
*mkastslot(Type
*, CfgSym
*, int);
135 Ast
*mkAst(AstOp
, CfgSym
*);
137 Ast
*asttoquestion(Ast
*, CfgSym
*); /* sym is ? type */
138 Ast
*astfromquestion(Ast
*, CfgSym
*); /* sym is ? type */
139 Ast
*astlisttostar(Zlist
*, CfgSym
*); /* sym is * type */
140 Ast
*astlisttoplus(Zlist
*, CfgSym
*); /* sym is + type */
141 int aststartolist(Ast
*, CfgSym
*, Zlist
**); /* sym is * type */
142 int astplustolist(Ast
*, CfgSym
*, Zlist
**); /* sym is + type */
143 Zlist
*asttolist(Ast
*);
144 Zarray
*astsplit(Ast
*);
145 void astremovecopiedfrom(Ast
*);
146 Ast
*astjoin(Ast
*, Zarray
*);
148 Ast
*astlastkid(Ast
*);
151 Name
asttostring(Ast
*);
153 int astslotted(Ast
*);
156 void astrefcheck(Ast
*, int);
158 Ast
*astright(Ast
*, int);
159 Zpoly
* astline(Ast
*);
160 Ast
*astcanonicalize(Ast
*);
162 Ast
*astparent(Ast
*, Type
*);
163 Ast
*astcvtslot(Ast
*, Type
*);
165 void astswap(Ast
*, Ast
*);
167 int astsame(Ast
*, Ast
*);
169 #define astparent_attr(a) astparent(a, 0)
170 Ast
*astprev_attr(Ast
*);
171 Ast
*astnext_attr(Ast
*);
172 Ast
*astcopiedfrom_attr(Ast
*);
173 int parseaction(CfgGram
*, CfgRule
*, ParseValue
**, ParseValue
**);
175 // Attributes on ASTs
177 typedef struct AttrInfo AttrInfo
;
189 typedef enum AttrState
201 void regattr(AttrInfo
*);
202 void attrstats(void);
203 void attrloop(AttrInfo
*);
205 void set_attribute(Ast
*, AttrInfo
*, Zpoly
);
206 Attr
*get_attribute(Ast
*, AttrInfo
*);
207 //Zpoly attribute(Ast*, AttrInfo*);
209 typedef struct AttrLink AttrLink
;
217 extern AttrLink
*attrlinks
;
225 extern AttrInfo
**attrinfo
;
229 static CfgSym *sym; \
232 sym = gramlooksym(__tgram__->gram, x); \
234 panic("no symbol %s in %s", x, __tgram__->name); \
241 static CfgRule *rule; \
244 rule = gramlookrule(__tgram__->gram, x); \
246 panic("no rule %s in %s", x, __tgram__->name); \