我目前有一个方法
pMain
| parser |
parser := 'proc' asParser, #space asParser, "<---- im trying to use the method identifier here - so i tried self identifier, instead of 'proc' asParser
#letter asParser plus, $( asParser,
'int' asParser,#space asParser,
#letter asParser plus, $) asParser,
#space asParser, 'corp' asParser.
^ parser
我也有这两种方法
1-关键词法
keywords
^ keywords ifNil: [
keywords := Set newFrom: #(
proc corp
if then else fi
do od
print as
while
for from to by
return
int string real array format bool
true false
mutable static
)
]
2-标识符方法
identifier
^ ((#letter asParser , #word asParser star) flatten) >=> [ : ctxt : aBlock | | parse |
parse := aBlock value.
(self keywords includes: parse) ifTrue: [
PPFailure message: 'keyword matched' context: ctxt
] ifFalse: [
parse
]]
问题:pMain 中如何使用标识符解析器?
我喂它这条线
MyParser new pMain:= 'proc a( int a ) corp'