Sie sind auf Seite 1von 2

SCI: CSC326: Assignment 1

Due 1 march 2013

In some hypothetical programming language a Function assumes the following form:

Identifier ( ) { Statement; Statement; . ; Statement };

A statement can assume any of the following two possible forms: if (Expr Lop Expr) then { assignmentStatement; assignmentStatement; } if (Expr Lop Expr) then { AssignStatement; AssignStatement; } else { AssignStatement; AssignStatement; } Identifier = Expr

Lop is a logical operator such as:

==, <, <=, >=, >

An Identifier: a string of lower-case letters. Expr is an algebraic expression such as: Identifier /( Identifier - Identifier ) Identifier - Identifier * Identifier +

AssignStatement: Identifier = AlgebraicExpression

The following is example of the (suggested) tokens of the language tokenCo de 1001 1002 tokenID ifTok Lparen tokenLex if (

1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016

Rparen equalsTok gtTok ltTok thenTok lBrace rBrace semicTok assignTok elseTok plusTok minusTok multTok divTok geTok leTok idTok

) == > < then { } ; = else + * / >= <= a string of lower-case letters

a) Develop a CFG grammar for the language of Function b) Develop a left linear regular grammar for the language (if not possible, you may modify the language slightly to make it possible). c) Develop a scanner (lexical analyzer) for a Function.

Das könnte Ihnen auch gefallen