You are on page 1of 4

Béla Tamás 932/1 Lab 1

Language Specification: 1. Language Definition: 1) Alphabet: a. Upper (A-Z) and lower case letters (a-z) of the English alphabet b. Underline character '_'; c. Decimal digits (0-9);

2) Lexic: a. Special symbols, representing: operators + - * / = < <= == != >= separators () [ ] { } , : ; space \n \t reserved words:  char bool int string if else while read write b. Identifiers identifier ::= letter | letter{letter}{digit} letter ::= “a” | “b” | … | “z” | "A" | "B" | …| "Z" digit ::= "0" | "1" |...| "9"

c. Constants i. integer SignedIntegerConstant ::= + IntegerConstant | - IntegerConstant | IntegerConstant IntegerConstant ::= Digit| NonZeroDigit {Number} NonZeroDigit ::= “1” | … | “9” Number ::=Digit | Digit Number ii. character Character:= Letter |Digit iii. string

Constchar ::=string String ::=Char{String} Char ::= Letter|Digit 2 Syntax:The words - predefined tokens are specified between " and ":

A. Sintactical rules: program ::= decllist ";" cmpdstmt decllist ::= declaration “;” | declaration “,” decllist declaration ::= type IDENTIFIER type ::= type1|arraydecl type1 ::= "BOOL" | "CHAR" | "INT" | "STRING" arraydecl ::= type1 “[“ Number “]” cmpdstmt ::= "{" stmtlist "}" stmtlist ::= stmt | stmt ";" stmtlist stmt ::= simplstmt | structstmt simplstmt ::= assignstmt | iostmt assignstmt ::= IDENTIFIER "=" expression expression ::= expression "+" term | term term ::= term "*" factor | term “/” factor | factor factor ::= "(" expression ")" | IDENTIFIER iostmt ::= "READ" | "WRITE" "(" IDENTIFIER ")" structstmt ::= cmpdstmt | ifstmt | whilestmt ifstmt ::= "IF" condition stmt ["ELSE" stmt] whilestmt ::= "WHILE" condition stmt switch ::= “SWITCH” “(“ expression “)” cases “END” cases ::= case | cases case ::= “CASE” IntegerConst “:” stmt [“BREAK”;] condition ::= expression RELATION expression b) lexical rules:

IDENTIFIER ::= (letter| “_”) | {letter|digit| “_”} letter ::= "A" | "B" | . ..| "Z" digit ::= "0" | "1" |...| "9" RELATION ::= "<" | "<=" | "==" | “!=” | ">=" | ">"

The tokens are codified according to the following table: - identifiers - constants - code 0 - code 1

- reserved words: each word has its own code - operators: each operator has its own code - separators: each separator has its own code 3 Codification:

Token type Identifier Constant Char Bool Int String If Else While Read Write + * / = < <= ==

Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

!= >= ( ) [ ] { } , : ; Space Newline Tab

20 21 22 23 24 25 26 27 28 29 30 31 32 33