PDA

View Full Version : Parser Fun


Bidoche
24th November 2002, 16:39
In attachement, the first version of a parser.
Currently it only handles expressions made of int, float and bool literals (with no size limit)

operations +, -, *, /, % allowed for int and floats and all the comparison operator
operations !, &&, || ( b && b || b interdit) for booleans and ==, !=

construction b ? e1 : e2 allowed if e1 and e2 of same type

the parser correctly recognize as float an expression than contains a float literal at any point
ie 1/2 -> int:0
but 1/2 + .5 -> float:1.0

Source is included (Do yourself a favor and don't look into parser and tokenizer code, rather get cppcc documentation and look into the grammar)

Edit:
NB: This is a debug version who will trace the parsing processus

WarpEnterprises
24th November 2002, 22:53
What shall this do?

Bidoche
25th November 2002, 00:49
Eventually it is supposed to grow to a complete avisynth parser, with greater possibilities.
Modify the Grammar is not that long, and it can handle almost everything you may want to add (Some wanted if, for and co, it can do it (not that hard in fact))

For now, it just parse literal expression because it is something that is independant from internal structure, and I add to start somewhere to learn how the generator works.

Next, I will try to add string support, and after variables :)

NB:
if your question is how the program is supposed to work:
launch it in a dos box,
type the expression you want,
finish input by CTRL Z
if your input is syntixacally correct, it will give the result (with the parsing logic trace on cerr)
otherwise abnormal termination
and if it is correct but the prog still fails, post the exp used
(I thinks it's works good but i didn't test everything)