.TH TERMINAL 2 "30 March 1992" "Demeter" "Demeter Software" .SH NAME Terminal \- Abstract class, root of the hierarchy of terminal classes. .SH DESCRIPTION Class Terminal has five subclasses: DemIdent, DemNumber, DemReal, DemString and DemText. Terminal class objects support the following methods. .TP 10 int get_line_number() const; This method returns the number of the line in the input file to .I g_parse where a terminal was found. .LP .SH SUBCLASSES .IP .SH DemNumber Objects of class DemNumber contain integer numbers. The printed representation of a DemNumber object is a string of digits representing the integer stored in the object. Class DemNumber supports the standard arithmetic operators by providing an int coercion operator and the corresponding assignment operators. A list of the arithmetic operators implemented by class DemNumber follows. .KS operator int() const .br DemNumber& operator=( const int n ) .br DemNumber* operator+=( const int i ) .br DemNumber* operator+=( const DemNumber* n ) .br DemNumber* operator-=( const int i ) .br DemNumber* operator-=( const DemNumber* n ) .br DemNumber* operator*=( const int i ) .br DemNumber* operator*=( const DemNumber* n ) .br DemNumber* operator/=( const int i ) .br DemNumber* operator/=( const DemNumber* n ) .br DemNumber* operator%=( const int i ) .br DemNumber* operator%=( const DemNumber* n ) .KE With these operators it is not only possible to operate DemNumber objects but also operate them in combination with integer numbers as the following example illustrates. .KS DemNumber* iDemNumber1 = new DemNumber( 3 ); .br DemNumber* iDemNumber2 = new DemNumber( 7 ); .br DemNumber* iDemNumber3 = new DemNumber( 9 ); .br iDemNumber3 += *iDemNumber1 + 8 + *iDemNumber2; .KE After the last assignment, iDemNumber3 should contain the integer number 27. Notice how the objects iDemNumber1 and iDemNumber2 are dereferenced when used as operands in the last assignment. This invokes the int() operator that coerces them into integer numbers. From then on, the integer + operator is used until the += operator is invoked, which is the one attached to DemNumber. .SH DemReal Objects of class DemReal contain floating point numbers. The printed representation of a DemReal object is the integer part, followed by a decimal point, followed by the decimal part of the number stored in the object. Parsing a legal DemReal object requires the presence of the decimal point. Class DemReal supports the standard arithmetic operators by providing double coercion operator and the corresponding assignment operators. A list of the arithmetic operators implemented by class DemReal follows. .KS operator double() const .br DemReal& operator=( const double d ) .br DemReal* operator+=( const double d ) .br DemReal* operator+=( const DemReal* r ) .br DemReal* operator-=( const double d ) .br DemReal* operator-=( const DemReal* r ) .br DemReal* operator*=( const double d ) .br DemReal* operator*=( const DemReal* r ) .br DemReal* operator/=( const double d ) .br DemReal* operator/=( const DemReal* r ) .KE With these operators it is not only possible to operate DemReal objects but also operate them in combination with double numbers as the following example illustrates. .KS DemReal* iDemReal1 = new DemReal( 3.0 ); .br DemReal* iDemReal2 = new DemReal( 7.0 ); .br DemReal* iDemReal3 = new DemReal( 9.0 ); .br iDemReal3 += *iDemReal1 + 8.0 + *iDemReal2; .KE After the last assignment, iDemReal3 should contain the double number 27.0. Notice how the objects iDemReal1 and iDemReal2 are dereferenced when used as operands in the last assignment. This invokes the double() operator that coerces them into double numbers. From then on, the double + operator is used until the += operator is invoked, which is the one attached to DemReal. .SH DemIdent Objects of class DemIdent contain strings of alphanumeric characters which start with an alphabetic character. Class DemIdent supports the comparison operators == and != by providing a char* coercion operator as described by the following interfaces. .KS operator char*() const .br int operator==( const char* str ) .br int operator==( const DemIdent& other ) .br int operator!=( const char* str ) .br int operator!=( const DemIdent& other ) .KE With these operators it is possible to operate DemIdent objects with other DemIdent objects as well as with character strings as the following example illustrates. .KS DemIdent* iDemIdent1 = new DemIdent( "Id1" ); .br DemIdent* iDemIdent2 = new DemIdent( "Id2" ); .br char* str = "Id1"; .br if( *iDemIdent1 == str && *iDemIdent1 != *DemIdent2 && strcmp( str,*DemIdent2 ) ) cout << "Success"; .KE After this program segment is executed, the string "Success" should be printed. Notice how the objects iDemIdent1 and iDemIdent2 are dereferenced when used as operands in the comparison. This ensures that the appropriate operators are invoked, and that the char*() operator is invoked to coerce iDemIdent2 into a character string. .SH DemString Objects of class DemString contain strings of any character, except for quotation marks (") and new line characters. The printed representation of a DemString object is "", where is the contents of the DemString object. Parsing a legal DemString object requires the presence of the delimiting quotation marks, although the marks are not stored in the object. Class DemString supports the comparison operators == and != by providing a char* coercion operator as described by the following interfaces. .KS operator char*() const .br int operator==( const char* str ) .br int operator==( const DemString& other ) .br int operator!=( const char* str ) .br int operator!=( const DemString& other ) .KE With these operators it is possible to operate DemString objects with other DemString objects as well as with character strings as the following example illustrates. .KS DemString* iDemString1 = new DemString( "Str1" ); .br DemString* iDemString2 = new DemString( "Str2" ); .br char* str = "Str1"; .br if( *iDemString1 == str && *iDemString1 != *DemString2 && strcmp( str,*DemString2 ) ) cout << "Success"; .KE After this program segment is executed, the string "Success" should be printed. Notice how the objects iDemString1 and iDemString2 are dereferenced when used as operands in the comparison. This ensures that the appropriate operators are invoked, and that the char*() operator is invoked to coerce iDemString2 into a character string. .SH DemText Objects of class DemText contain strings of up to 10k characters which can include any character (blanks, tabs, new lines, etc.) The printed representation of a DemText object is (@ @), where is the contents of the DemText object. Parsing a legal DemText object requires the presence of the delimiters (@ and @), although the delimiters are not stored in the object. Also, cannot contain the character "@" since it will confuse the scanner. For efficiency, the length of is also stored in the object, and can be accessed with the get\_len() method. Class DemText supports the comparison operators == and != by providing a char* coercion operator as described by the following interfaces. .KS operator char*() const .br int operator==( const char* str ) .br int operator==( const DemText& other ) .br int operator!=( const char* str ) .br int operator!=( const DemText& other ) .KE With these operators it is possible to operate DemText objects with other DemText objects as well as with character strings as the following example illustrates. .KS DemText* iDemText1 = new DemText( "Text1" ); .br DemText* iDemText2 = new DemText( "Text2" ); .br char* str = "Text1"; .br if( *iDemText1 == str && *iDemText1 != *DemText2 && strcmp( str,*DemText2 ) ) cout << "Success"; .KE After this program segment is executed, the string "Success" should be printed. Notice how the objects iDemText1 and iDemText2 are dereferenced when used as operands in the comparison. This ensures that the appropriate operators are invoked, and that the char*() operator is invoked to coerce iDemText2 into a character string. .SH EXAMPLE The following class dictionary illustrates the use of the terminal classes DemIdent and DemText. CodeFragment = CFKind DemIdent DemText. .br CFKind : Primary | Before | After. .br Primary = "*primary*". .br Before = "*before*". .br After = "*after*". .br *terminal_sets* DemIdent, DemNumber, DemReal, DemString, DemText. The following object is a legal CodeFragment object containing an DemIdent and a DemText nested objects. *primary* Adjacency .br (@ .br if( this->g_equal( adj ) ) .br result = this; .br @) Notice that the class dictionary in this example is actually a legal object of yet another class dictionary which uses the terminal classes DemIdent and DemString. The subobjects "*primary*", "*before*", and "*after*" are objects of class DemString, nested in this class dictionary object. .SH SEE ALSO g_parse(2)