






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
The mid-term examination material for the compiler construction course, focusing on the grammar specification language. It includes the grammar rules for expressions and jw pascal programming language, as well as the terminal symbols and examples. Students are expected to understand the structure of the grammar and its application in compiler design.
Typology: Exams
1 / 12
This page cannot be seen from the preview
Don't miss anything!
CS
CS
Analysis
Example grammars
1 Expr --> Expr plus Term 2 | Expr minus Term 3 | Term 4 Term --> Term times Factor 5 | Term divide Factor 6 | Factor 7 Factor --> lpar Expr rpar 8 | num 9 | id
1 program --> program_heading block full_stop 2 3 program_heading --> program_keyword identifier 4 left_parenthesis file_identifier_list 5 right_parenthesis semicolon 6 7 file_identifier_list --> file_identifier comma 8 file_identifier_list | 9 file_identifier 10 11 file_identifier --> identifier 12 13 block --> label_declaration_part constant_definition_part 14 type_definition_part variable_declaration_part 15 procedure_and_function_declaration_part 16 statement_part 17 18 label_declaration_part --> label_keyword label_list semicolon | 19 20 21 label_list --> label comma label_list | 22 label 23 24 label --> unsigned_integer 25 26 constant_definition_part --> const_keyword 27 constant_definition_list 28 semicolon | 29 30 constant_definition_list --> constant_definition semicolon 31 constant_definition_list | 32 constant_definition
CS
95 fixed_part | 96 variant_part | 97 98 fixed_part --> record_section_list 99 100 record_section_list --> record_section semicolon 101 record_section_list | 102 record_section 103 104 record_section --> field_identifier_list colon type 105 106 field_identifier_list --> field_identifier comma 107 field_identifier_list | 108 field_identifier 109 110 field_identifier --> identifier 111 112 variant_part --> case_keyword tag_field type_identifier 113 of_keyword variant_list 114 115 variant_list --> variant semicolon variant_list | 116 variant 117 118 tag_field --> field_identifier colon | 119 120 121 variant --> case_label_list colon left_parenthesis 122 field_list right_parenthesis 123 124 case_label_list --> case_label comma case_label_list | 125 case_label 126 127 case_label --> constant 128 129 set_type --> set_keyword of_keyword base_type 130 131 base_type --> simple_type 132 133 file_type --> file_keyword of_keyword type 134 135 pointer_type --> up_arrow type_identifier 136 137 variable_declaration_part --> var_keyword 138 variable_declaration_list 139 semicolon | 140 141 variable_declaration_list --> variable_declaration semicolon 142 variable_declaration_list | 143 variable_declaration 144 145 variable_declaration --> identifier_list colon type 146 147 procedure_and_function_declaration_part --> 148 procedure_or_function_declaration_list 149 150 procedure_or_function_declaration_list --> 151 procedure_or_function_declaration semicolon 152 procedure_or_function_declaration_list | 153 154 procedure_or_function_declaration --> procedure_declaration | 155 function_declaration 156
CS
157 procedure_declaration --> procedure_heading block 158 159 procedure_heading --> procedure_keyword identifier semicolon | 160 procedure_keyword identifier 161 left_parenthesis 162 formal_parameter_section_list 163 right_parenthesis semicolon 164 165 formal_parameter_section_list --> formal_parameter_section 166 semicolon 167 formal_parameter_section_list | 168 formal_parameter_section 169 170 formal_parameter_section --> parameter_group | 171 var_keyword parameter_group | 172 function_keyword parameter_group | 173 procedure_keyword 174 identifier_list 175 176 parameter_group --> identifier_list colon type_identifier 177 178 function_declaration --> function_heading block 179 180 function_heading --> function_keyword identifier colon 181 result_type semicolon | 182 function_keyword identifier 183 left_parenthesis 184 formal_parameter_section_list 185 right_parenthesis 186 colon result_type semicolon 187 188 result_type --> type_identifier 189 190 statement_part --> compound_statement 191 192 statement --> label colon unlabelled_statement | 193 unlabelled_statement 194 195 unlabelled_statement --> structured_statement | 196 simple_statement 197 198 simple_statement --> assignment_statement | 199 procedure_statement | 200 go_to_statement | 201 empty_statement 202 203 assignment_statement --> variable assignment_sign expression | 204 function_identifier assignment_sign 205 expression 206 207 variable --> entire_variable specifier_list | 208 entire_variable 209 210 entire_variable --> identifier 211 212 specifier_list --> specifier specifier_list | 213 specifier 214 215 specifier --> up_arrow | 216 record_field | 217 array_index 218
CS
282 procedure_identifier --> identifier 283 284 actual_parameter_list --> actual_parameter comma 285 actual_parameter_list | 286 actual_parameter 287 288 actual_parameter --> expression | 289 procedure_identifier | 290 function_identifier 291 292 go_to_statement --> goto_keyword label 293 294 empty_statement --> 295 296 structured_statement --> compound_statement | 297 conditional_statement | 298 repetitive_statement | 299 with_statement 300 301 compound_statement --> begin_keyword statement_list 302 end_keyword 303 304 conditional_statement --> if_statement | 305 case_statement 306 307 if_statement --> if_keyword expression then_keyword 308 statement else_keyword statement | 309 if_keyword expression then_keyword 310 statement 311 312 case_statement --> case_keyword expression of_keyword 313 case_list end_keyword 314 315 case_list --> case_list_element semicolon case_list | 316 case_list_element 317 318 case_list_element --> case_label_list colon statement | 319 320 repetitive_statement --> while_statement | 321 repeat_statement | 322 for_statement 323 324 while_statement --> while_keyword expression do_keyword 325 statement 326 327 repeat_statement --> repeat_keyword statement_list 328 until_keyword expression 329 330 statement_list --> statement semicolon statement_list | 331 statement 332 333 for_statement --> for_keyword control_variable 334 assignment_sign for_list do_keyword 335 statement 336 337 for_list --> initial_value to_keyword final_value | 338 initial_value downto_keyword final_value 339 340 control_variable --> identifier 341 342 initial_value --> expression
CS
344 final_value --> expression 345 346 with_statement --> with_keyword record_variable_list 347 do_keyword statement 348 349 record_variable_list --> variable comma 350 record_variable_list | 351 variable 352 353 sign --> plus_sign | 354 minus_sign
1 Program 2 --> Module 3 4 Module 5 --> module identifier 6 semi BlockNoScope identifier dot 7 8 Block 9 --> 10 BlockNoScope 11 12 BlockNoScope 13 --> OptDecls begin Stmts end 14 15 OptDecls 16 --> 17 | Decls 18 19 Decls 20 --> Declaration 21 | Decls Declaration 22 23 Declaration 24 --> const OptConstDecls 25 | type OptTypeDecls 26 | typerec RecTypeDecls 27 | var OptVarDecls 28 | ProcDecl 29 30 RecTypeDecls 31 --> TypeDecl 32 | RecTypeDecls and TypeDecl 33 34 OptConstDecls 35 --> 36 | ConstDecls 37 38 OptTypeDecls 39 --> 40 | TypeDecls 41 42 OptVarDecls 43 --> 44 | VarDecls 45 46 ConstDecls
CS
109 | AssignStmt 110 | CallStmt 111 | ExitStmt 112 | EvalStmt 113 | ForStmt 114 | IfStmt 115 | LoopStmt 116 | ReadStmt 117 | RepeatStmt 118 | ReturnStmt 119 | WhileStmt 120 | WriteStmt 121 122 AssignStmt 123 --> Expr coloneq Expr 124 125 CallStmt 126 --> ProcCall 127 128 ExitStmt 129 --> exit 130 131 EvalStmt 132 --> eval Expr 133 134 ForStmt 135 --> for identifier coloneq Expr to Expr OptBy do 136 Stmts end 137 138 OptBy 139 --> 140 | by Expr 141 142 IfStmt 143 --> IfHead end 144 | IfHead else 145 Stmts end 146 147 IfHead 148 --> if Expr then 149 Stmts 150 | IfHead elsif 151 Expr then 152 Stmts 153 154 LoopStmt 155 --> loop 156 Stmts end 157 158 ReadStmt 159 --> read lpar text comma ReadList rpar 160 161 ReadList 162 --> Expr 163 | Expr comma ReadList 164 165 RepeatStmt 166 --> repeat 167 Stmts until Expr 168 169 ReturnStmt 170 --> return
CS
171 | return Expr 172 173 WhileStmt 174 --> while 175 Expr do 176 Stmts end 177 178 WriteStmt 179 --> write lpar text WriteList rpar 180 181 WriteList 182 --> 183 | comma Expr WriteList 184 185 Type 186 --> ArrayType 187 | RecordType 188 | SubrangeType 189 | identifier 190 | lpar Type rpar 191 | ref Type 192 193 ArrayType 194 --> array OptTypeList of Type 195 196 OptTypeList 197 --> 198 | TypeList 199 200 TypeList 201 --> Type 202 | TypeList comma Type 203 204 RecordType 205 --> record OptFields end 206 207 OptFields 208 --> 209 | Fields 210 | Fields semi 211 212 Fields 213 --> IDList colon Type 214 | Fields semi IDList colon Type 215 216 SubrangeType 217 --> lbrack Expr dotdot Expr rbrack 218 219 Expr 220 --> Expr or Expr 221 | Expr and Expr 222 | not Expr 223 | Expr Relop Expr 224 | Expr Addop Expr 225 | Expr Mulop Expr 226 | Sign Expr 227 | Primary 228 229 Relop 230 --> equal 231 | nequal 232 | less