

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Assignment; Class: Programming Languages; Subject: Computer Science; University: University of Alabama - Birmingham; Term: Spring 2007;
Typology: Assignments
1 / 2
This page cannot be seen from the preview
Don't miss anything!
Due Wednesday, January 31, 2007
Consider the following extended BNF grammar for a subset of the Perl programming language, called MicroPerl.
program ::= use strict ; require “list.pl” ; { sub-definition } { { declaration ; } { statement } } sub-definition ::= sub sub-identifier { my variable-identifier = @ ; { declaration ; } { statement } return ( expression ) ; } declaration ::= my variable-identifier statement ::= variable-identifier = expression ; | if ( expression ) statement-block [else statement-block ] | while ( expression ) statement-block | print variable-identifier ; statement-block ::= { statement { statement } } expression ::= term | expression binary-op expression term ::= primary-expression | unary-op term primary-expression ::= variable-identifier | integer | list-expression | sub-identifier list-expression | hd list-expression | tl list-expression | isNil list-expression list-expression ::= ( [ expression {, expression } ] )
Syntactic and Semantic Conventions The keywords and the token symbols in MicroPerl are in bold. Note that MicroPerl has symbols { and }, which are distinguished from grammar metasymbols { and }, respectively, by underlining. The unary operators are +, − and! (negation) Binary operators obey the customary precedence rules, from highest to lowest:
multiplicative ∗, / binary additive +, − relational ==,! =, <, >, <=, >= boolean &&, ‖
A MicroPerl sub identifier is a bare name, which consists of letters (only alphabetic characters), digits, and underscores ( ) with the restrictions that it must begin with a 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 6gh, two bad, and no end are not. A MicroPerl variable may be a scalar variable or a list variable. A scalar variable identifier begins with a $, followed by a bare name. A list variable identifier begins with a @, followed by a bare name. integer is an unsigned integer. MicroPerl comments are indicated by being preceded by # and terminated by the end of the line.
Suggestions: