Docsity

Compiler Organization and Error Handling, Study notes of Computer Science

Toggle sidebar
bg1
1
Compiler Organization
- single pass compilation
o load compiler
o read source code
o output object code
- multi-pass compilation
o loading time for each modules (lexical analysis, syntax analysis, etc.)
o symbol and name tables must be distributed correctly
o compiler administration (error handling, supporting routines)
- environment settings
o default output code name, error message file and source file extension
o environment variable parsing
o argument parsing (getopt())
o getenv() and putenv()
- file manipulations
o FILE *fopen(const char *filename, const char *mode);
§ r or rb
§ Open file for reading.
§
§ w or wb
§ Truncate to zero length or create file for writing.
§
§ a or ab
§ Append; open or create file for writing at end-of-
§ file.
§
§ r+ or rb+ or r+b
§ Open file for update (reading and writing).
§
§ w+ or wb+ or w+b
§ Truncate to zero length or create file for update.
§
§ a+ or ab+ or a+b
§ Append; open or create file for update, writing at
§ end-of-file.
§
o int fclose(FILE *stream);
o int feof(FILE *stream);
- error report (e.g., “Error: line 123 invalid syntax.”)
o Types of errors
§ Ambiguous name: a name is defined two or more times in a block.
§ Invalid comment: a closing comment delimiter is missing.
§ Invalid name kind: a wrong kind of name is used.
§ Invalid numeral: a numeral is overflowed.
§ Invalid index range: array index is out of bound.
§ Invalid syntax: violation of syntactic rules.
pf2

Partial preview of the text

Download Compiler Organization and Error Handling and more Study notes Computer Science in PDF only on Docsity!

Compiler Organization

  • single pass compilation o load compiler o read source code o output object code
  • multi-pass compilation o loading time for each modules (lexical analysis, syntax analysis, etc.) o symbol and name tables must be distributed correctly o compiler administration (error handling, supporting routines)
  • environment settings o default output code name, error message file and source file extension o environment variable parsing o argument parsing (getopt()) o getenv() and putenv()
  • file manipulations o FILE *fopen(const char *filename, const char *mode); ß r or rb ß Open file for reading. ß ß w or wb ß Truncate to zero length or create file for writing. ß ß a or ab ß Append; open or create file for writing at end-of- ß file. ß ß r+ or rb+ or r+b ß Open file for update (reading and writing). ß ß w+ or wb+ or w+b ß Truncate to zero length or create file for update. ß ß a+ or ab+ or a+b ß Append; open or create file for update, writing at ß end-of-file. ß o int fclose(FILE *stream); o int feof(FILE *stream);
  • error report (e.g., “Error: line 123 invalid syntax.”) o Types of errors ß Ambiguous name: a name is defined two or more times in a block. ß Invalid comment: a closing comment delimiter is missing. ß Invalid name kind: a wrong kind of name is used. ß Invalid numeral: a numeral is overflowed. ß Invalid index range: array index is out of bound. ß Invalid syntax: violation of syntactic rules.

ß Invalid type: wrong type of an operand is used. ß Undefined name: a name is used without defined. ß … o Error message should be put in a file, standard output or both, controlled by environment settings or command line switches. o Further error message s should be suppressed after one occurs in a line to make things clear. o Runtime checking for storage, e.g., table limit

Software Development Techniques

  • Divide and conquer
  • Reusability
  • Testing
  • Maintenance
  • Documentation

Software Development Tools

  • Make utility
  • Debugging tools (dbx, gdb, etc.)
  • Automake and Autoconf