Grammar for expression...?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Grammar for expression...?

Morten Aune Lyrstad
I have downloaded Grammatica for use with my scripting language
Storyteller. I have serious problems understanding the more advanced
grammar. I need to extend the expression grammar you have given in your
example:

Expression = Term [ExpressionTail] ;

ExpressionTail = "+" Expression
              | "-" Expression ;

Term = Factor [TermTail] ;
    TermTail = "*" Term
        | "/" Term ;

Factor = Atom
      | "(" Expression ")" ;

Atom = NUMBER
    | IDENTIFIER ;


into one that is capable of handling all of a programming language's
common operators, like 'and', 'or', > etc. However, I don't really
understand what is going on here, and because of that I cannot extend
it. Why are the operators divided into two "tails"? And does this
support unary operators? Where should I add my other operators?

I was hoping you could give me a hand?

Thank you,
Morten


_______________________________________________
Grammatica-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/grammatica-users
Reply | Threaded
Open this post in threaded view
|

Re: Grammar for expression...?

Yakov Keselman
If I understand your difficulties correctly, you're unable to come up with a BNF grammar for your scripting language. My suggestion is to learn from "realistic" examples. For example, here is a link to a specificiation of the Java programming language in BNF: http://www.csm.astate.edu/java-grammar.html
 
You can also try finding similar specs for other programming languages that you know.
 
I don't know of any general technique that would allow generating a BNF grammar out of an existing language.
 
= Yakov


Morten Aune Lyrstad <[hidden email]> wrote:
I have downloaded Grammatica for use with my scripting language
Storyteller. I have serious problems understanding the more advanced
grammar. I need to extend the expression grammar you have given in your
example:

Expression = Term [ExpressionTail] ;

ExpressionTail = "+" Expression
| "-" Expression ;

Term = Factor [TermTail] ;
TermTail = "*" Term
| "/" Term ;

Factor = Atom
| "(" Expression ")" ;

Atom = NUMBER
| IDENTIFIER ;


into one that is capable of handling all of a programming language's
common operators, like 'and', 'or', > etc. However, I don't really
understand what is going on here, and because of that I cannot extend
it. Why are the operators divided into two "tails"? And does this
support unary operators? Where should I add my other operators?

I was hoping you could give me a hand?

Thank you,
Morten


_______________________________________________
Grammatica-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/grammatica-users



http://www.kinderspirit.org/yakovkeselman/

====

Nothing is so firmly believed as that which we least know.
-- Michel de Montaigne

_______________________________________________
Grammatica-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/grammatica-users