[clean-list] is my lazy parsing effective?
Jigang Sun
Jigang.Sun at student.paisley.ac.uk
Fri Oct 27 09:41:59 MEST 2006
Hi,
I am writing parser by hand. I want to be lazy, i.e. I write less code. For example, for the
following grammar
SpecialExpression = BasicValue
| List
BasicValue = INT
|BOOL
|REAL
List = ListDenotation
| DotDotexpression
ListDenotation = "["[ListKind] [{LGraphExpr}-list [: GraphExpr]] [SpineStrictness] "]"
LGraphExpr = GraphExpr| CharsDenotation
DotDotexpression = "["[ListKind] GraphExpr [,GraphExpr]..[GraphExpr] [SpineStrictness] "]"
the best parsing method is, at each level, to decide exactly the next route to go, for
SpecialExpression = BasicValue
| List
the usual method is: when the parser is at a point to parse SpecialExpression, the parser should
check the first token type met,if the token is a token that starts BasicValue(is of INT, REAL or
BOOL) then parse BasicValue, if the first token is "[" then parse List.
The method I want to adopt is not do token type checking, instead go straight to parse BasicValue,
let BasicValue parsing method check if the first token is of INT, REAL or BOOL, if not then return
null; then parse List. The token type checking is done at lowerest level, and only once.
The advantage is that the program code is short, because I ommit the token type checking that is
repeatedly done at a further lower levels, e.g. at List parsing and further down List, i.e.
ListDenotation and DotDotexpression.
Maybe the disadvantage is slower speed.
I am sure if the parsing efficiency is a main concern to a compiler overall performance.
How about the method?
Thanks.
Jigang
More information about the clean-list
mailing list