Description for Building a Parser Flashcards

(36 cards)

1
Q

What is the language definition for PROG?

A

PROG ::= PROGRAM IDENT ; Block

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the language definition for BLOCK?

A

Block ::= [ DeclPart ] CompStmt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the language definition for DeclPart?

A

DeclPart ::= [ ConstPart ] [ VarPart ]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the language definition for ConstPart?

A

ConstPart ::= CONST ConstDef { , ConstDef } ;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the language definition for ConstDef?

A

ConstDef ::= IDENT = Expr

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the language definition for VarPart?

A

VarPart ::= VAR DeclStmt { , IDENT } ;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the language definition for DeclStmt?

A

DeclStmt ::= IDENT { , IDENT } : Type [:== Exp]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the language definition for Type?

A

Type ::= INTEGER | REAL | BOOLEAN | CHAR | STRING

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the language definition for Stmt?

A

Stmt ::= SimpleStmt | StructuredStmt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the language definition for SimpleStmt

A

SimpleStmt ::= AssignStmt | ReadLnStmt | WriteLnStmt | WriteStmt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the language definition for StructuredStmt?

A

StructuredStmt ::= IfStmt | CompStmt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the language definition for CompStmt?

A

CompStmt ::= BeginStmt { ; Stmt } END

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the language definition for WriteLnStmt?

A

WriteLnStmt ::= WRITELN ( ExprList )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the language definition for WriteStmt?

A

WriteStmt ::= Write( ExprList )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the language definition for Variable?

A

Variable ::= IDENT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the language definition for IfStmt?

A

IfStmt ::= IF Expr THEN Stmt [ ELSE Stmt ]

16
Q

What is the language definition for AssignStmt?

A

AssignStmt ::= Variable ::= Expr

17
Q

What is the language definition for ReadLnStmt?

A

ReadLnStmt ::= ReadLn ( VarList )

18
Q

What is the language definition for ExprList?

A

ExprList ::= Expr { , Expr }

19
Q

What is the language definition for VarList?

A

VarList ::= Variable { , Variable }

20
Q

What is the language definition for Expr?

A

Expr ::= RealExp ::= SimpleExpr [ ( = | < | > ) SimpleExpr ]

21
Q

What is the language definition for SimpleExpr?

A

SimpleExpr ::= Term { ( + | - | OR ) Term }

22
Q

What is the language definition for Term?

A

Term ::= SFactor { ( * | / | DIV | MOD | And ) SFactor }

23
Q

What is the language definition for SFactor?

A

SFactor ::= [ ( - | + | NOT ) ] Factor

24
What is the language definition for Factor?
Factor ::= IDENT | ICONST | RCONST | SCONST | BCONST | CCONST | (Expr)
25
What operators have precedence level 1?
Unary plus, minus, and NOT. Has right-to-left associativity.
26
What operators have precedence level 2?
Multiplication, division, integer division, modulus, and logical AND. Has left-to-right associaitivity.
27
What operators have precedence level 4?
Equality, less than, and greater than. Has left-to-right associativity.
27
What operators have precedence level 3?
Addition, subtraction, and logical OR. Has left-to-right associativity.
28
When can a variable be used in a Pascal-Like language?
Once it is defined in a declaration statement.
29
What is the five basic data types of a Pascal-Like language?
Integer, real, string, char, boolean.
30
How do if statements work in a Pascal-Like language?
If logical expression value is true, then the Then-clause statement is executed. If there is an Else-clause (optional), then it is executed when the logical expression is false.
31
How does WriteStmt/WriteLnStmt work in a Pascal-Like language?
When called, the write statements will evaluate a list of expressions and print their values in order from left to right. WriteLnStmt will create a newline after printing. If there is a boolean expression, the write statements will write "true" or "false".
32
How does the ASSOP operator work in a Pascal-Like language?
ASSOP evaluates an expression on the right side, storing the value in a memory location associated with a variable on the right side. A real variable can be assigned an integer or real value, but an integer value must be assigned an integer value. Moreover, a character variable cannot be assigned a null string.
33
Recursive-Descent Parser
A parser which includes one function per syntactic rule or non-terminal. If the function needs to read a token, it calls the wrapper function GetNextToken(). When the function needs a nonterminal symbol, it calls the function designated for that nonterminal symbol.
34
Does a recursive-descent parser generate a parse tree?
There is no explicit generation of a parse tree, however the parser traces the parse tree implicitly for the input program.