1

So far, I was able to use pyparsing to parse ebnf grammars. However, I wanted to try the following code sample but could not come up with a good grammar.

global radius = 5
DrawCircle(radius)
{
  radius = 10
  DrawCircle(radius)
}
DrawCircle(radius)

The value of radius with in the scope should be 10, 5 otherwise. Any help would be appreciated ?

Regards

Praveen

2
  • I think this question goes far beyond a basic parsing issue. Once you have this parsed, then you have to have a proper execution environment, which would respect the scoping of variables. That is where the work should go, I'd say.
    – PaulMcG
    Jun 8, 2015 at 3:19
  • Thanks Paul. Will do the same. Once parsed, I will leave it up to the parse action to actually distinguish the global and local variables. Jun 8, 2015 at 6:38

1 Answer 1

0

I was able to get the parser for the above code by running:

enclosed = Forward()
curls = nestedExpr('{', '}', content=enclosed)
enclosed << (OneOrMore(commands | ',' | curls))

I have a follow up question. I am used to write ebnf grammar using http://pyparsing.wikispaces.com/file/view/ebnf.py

Can I get some help identifying the ebnf for forward or equivalent of the above code ? or should I do outside ebnf ?

Regards

Praveen

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.