

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Due Wednesday, February 6, 2008
Consider the following extended BNF grammar for a subset of the Ruby programming language, called MicroRuby.
program ::= require โlistโ { funcdef } function-identifier ( ) funcdef ::= def function-identifier ( [ variable-identifier { , variable-identifier } ] ) suite return add-expr end suite ::= statement { statement } statement ::= variable-identifier = add-expr | if or-test suite [else suite] end | while or-test suite end | puts add-expr or-test ::= and-test { || and-test } and-test ::= not-test { && not-test } not-test ::= comparison |! ( not-test ) comparison ::= add-expr comp-operator add-expr comp-operator ::= < | > | == | >= | <= |! = add-expr ::= mult-expr { add-operator mult-expr } add-operator ::= + | โ mult-expr ::= unary-expr { mult-operator unary-expr } mult-operator ::= โ | / unary-expr ::= [add-operator] primary primary ::= variable-identifier | integer | ( add-expr ) | function-identifier ( [ add-expr-list ] ) | list-expr | cons ( add-expr , add-expr ) | head ( add-expr ) | tail ( add-expr ) list-expr ::= [ [ add-expr-list ] ] add-expr-list ::= add-expr {, add-expr }
Syntactic and Semantic Conventions The keywords and the token symbols in MicroRuby are in bold. Note that MicroRuby has symbols [ and ], which are distinguished from grammar metasymbols [ and ], respectively, by bold face type. A MicroRuby identifier (called a function- identifier or variable-identifier) is a name, which consists of letters (only alphabetic characters), digits, and underscores ( ) with the restrictions that it must begin with a lowercase letter, cannot end with an underscore and cannot have two consecutive underscores. For example, give 2 Joe, tell me and a45Asm3 are valid bare names, but Fgh, two bad, and no end are not. integer is an unsigned integer. MicroRuby comments are indicated by being preceded by # and terminated by the end of the line.
Suggestions: