Semantic Error Ss
Semantic Error Ss
Semantic Error Ss
Semantic Error
Semantic error is a logical error happens due to wrong logical statements. Semantics is the interpretations of and meanings derived from the sentence transmission and understanding of the message. Semantics errors are Logical, while Syntax errors are code errors.
Examples: Example 1: Use of a non-initialized variable: int i; i++; // the variable i is not initialized
Example 2: Type incompatibility: int a = "hello"; // the types String and int are not compatible
Example 3: Errors in expressions: string s = "..."; int a = 5 - s; // the - operator does not support arguments of type String
Example 5: Array index out of range (dynamic semantic error) int[] v = new int[10]; v[10] = 100; // 10 is not a legal index for an array of 10 elements
The array v has been created with 10 elements (with indexes ranging from 0 to 9), and we are trying to access the element with index 10, which does not exist. This type of error is not caught during compilation, but causes an exception to be thrown at runtime.
Syntax Errors
In computer science a syntax error refers to an error in the syntax of a sequence of characters or tokens that is intended to be written in a particular programming language.
If a syntax error is encountered during compilation it must be corrected if the source code is to be successfully compiled. An attribute that often separates commercial quality compilers from academic projects is the extent to which an attempt is made to automatically correct the error and continue processing the source code.
Syntax errors may also occur when an invalid equation is entered into a calculator. This can be caused by opening brackets without closing them, or less commonly, using several decimal points in one number. The compiler detects syntax errors and display error massage to describe the cause of error.
There can be many causes of syntax error; some important causes are as follows:
The statement terminator is missing at the end of statement like coma, semicolon ( ); etc.
int a = 5 // semicolon is missing Compiler message: Error: Statement; missing in function main ()
x = ( 3 + 5; // missing closing parenthesis ') y = 3 + * 5; // missing argument between '+' and '*'
Example 3:
void main() { cout<<hello World } When trying to compile this program in C++ compiler, the compiler will display the familiar error message Error: Statement; missing in function main () Since because as per the C language grammar parser will look for a ; symbol as a terminator after or end of each executable statement in this case delimiter ; is missing and hence its termed as syntax error . /* ; Statement missing */
Unlike syntax error which get trapped during compilation, runtime error is smart enough to get through the compilation process, and get unleashed during the execution
Example 4:
when compiling the above program it won't show an error, but there is a serious error which the compiler could not identify >> i / 0 this would generate a divide by 0 error and terminate the application without any consideration
Example 5:
when trying to compile the above program the compiler will try to convert the int to char* to make room for the string hello World but it will fail !! Hence it will report you with an error message Cannot convert int to char*
Semantic and Syntax Errors Syntax and semantic errors typically occur in the source program. When one of these errors is encountered, the compiler attempts to recover from the error and continue processing the source file. As more errors are encountered, the compiler outputs additional error messages. However, no object file is produced. Syntax and semantic errors produce a message in the list file. These error messages are in the following format:
ERROR number IN LINE line OF file: error message Number line file detected. error message encountered. is the error number. corresponds to the line number in the source file or include file. is the name of the source or include file in which the error was
Following are syntax and semantic errors by error number. The error message displayed is listed along with a brief description and possible cause and correction.
100
An illegal character was found in the source file. (Note that characters inside a comment are not checked.) 101
unclosed string
102
A string may not contain more than 1024 characters. Use the concatenation symbol (\) to logically continue strings longer than 1024 characters. Lines terminated in this fashion are concatenated during lexical analysis.
103
A character constant has an invalid format. The notation \c is valid only when c is any printable ASCII character.
125
The declaration of an object may contain a maximum of 20 type modifiers ([ ], *, ()). This error is almost always followed by error 126.
126
typestack underflow
The type declaration stack has under flowed. This error is usually a side-effect of error 125.
127
An object was declared with an invalid memory space specification. This occurs if an object is declared with storage-class of auto or register outside of a function.
129
This error usually indicates that a semicolon is missing from the previous line. When this error occurs, the compiler may generate an excess of error messages.
130
The numerical argument after a using or interrupt specifier is invalid. The using specifier requires a register bank number between 0 and 3. The interrupt specifier requires an interrupt vector number between 0 and 15.
131
duplicate functionparameter
A formal parameter name exists more than once within a function. The formal parameter names must be unique in function declarations.
132
The parameter declarations inside a function use a name not present in the parameter name list. For example: char function (v0, v1, v2) char *v0, *v1, *v5; /* 'v5' is unknown in the formal list */ { /* ... */ }
134
Functions always reside in code memory and cannot be executed out of other memory areas. Functions are implicitly defined as memory type code.
135
Declarations of bit-scalars may include one of the static or extern storage classes. The register or alien classes are invalid.
136
'void' on variable
The type void is only allowed as a non-existent return value or an empty argument list for functions (void func (void)), or in combination with a pointer (void *).
138
An interrupt function was defined with one or more formal parameters or with a return value. Interrupt functions may not contain invocation parameters or return values.
140
Definitions of bit scalars may contain the optional memory type data. If the memory type is missing then the type data is assumed, because bits always reside in the internal data memory. This error can occur when an attempt is made to use another data type with a bit-scalar definition.
141
The token as seen by the compiler is wrong. If token is one of less than four tokens, an optional display of expected tokens may follow.
142
The base-address of a sfr or sbit declaration is in error. Valid bases are values in the range of 0x80 to 0xFF. If the declaration uses the notation base^pos, then the base address must also be a multiple of eight.
143
144
The definition of the bit position within an sbit declaration must be in range 0 to 7.
145 146
The declaration of an absolute bit (base^pos) contains an invalid basespecification. The base must be the name of a previously declared sfr. Any other names are invalid.
147
The size of a single object may not exceed the absolute limit of 65535 64K-1 bytes.
149
A struct or union may not contain a function-type member. However, pointers to functions are perfectly valid.
150
A union-aggregate may not contain members of type bit. This restriction is imposed due to the architecture of the 8051.
151
152
The number of bits specified in the bit-field declaration exceeds the number of bits in the given base type.
153
The named field had a zero width. Only unnamed bit-fields are allowed to have zero width.
154
ptr to field
155
The base type for bit-fields requires one of the types char or int. unsigned char and unsigned int types are also valid.
156 157
alien permitted on functions onlyVar_parms on alien function
The storage class alien is allowed only for external PL/M-51 functions. The formal notation (char *, ...) is not legal on alien functions. PL/M-51 functions always require a fixed number of parameters.
158
The parameter list of a function definition contains an unnamed abstract type definition. This notation is permitted only in function prototypes.
159
Prototype declarations of functions may contain an empty parameter list (e.g., int func (void)). This notation may not contain further type definitions after void.
160
void invalid
The void type is legal only in combination with pointers or as the non-existent return value of a function.
161
A declaration of an external function inside a function used a parameter name list without any type specification (e.g., extern yylex(a,b,c);).
162
duplicate functionparameter
The name of a defined object inside a function duplicates the name of a parameter.
163
In general, single or multi-dimensional arrays, and external arrays are not required to have a formal size specifier. Typically, the size is calculated by the compiler at initialization time or, as is the case with the external arrays, is simply of no great interest. This error is the result of attempting to use the sizeof operator on an undimensioned array or on a multi-dimensional array with undefined element sizes.
164
ptr to nul
This error is usually the result of a previous error for a pointer declaration.
165
ptr to bit
166
array of functions
Arrays cannot contain functions; however, they may contain pointers to functions.
167
array of fields
168
array of bit
An array may not have type bit as its basic-type. This limitation is imposed by the architecture of the 8051.
169
A function cannot return a function; however, a function may return a pointer to a function.
170
171
A break or continue statement may occur only within a for, while, do, or switch statement.
172
173
missing returnexpression
A function which returns a value of any type but int, must contain a return statement including an expression. Because of compatibility to older programs, no check is done on functions which return an int value.
174
returnexpression on voidfunction
A void function cannot return a value and thus may not contain a return statement.
175
Each case statement must contain a constant expression as its argument. The value must not occur more than once in the given level of the switch statement.
176
A switch statement may not contain more than one default statement.
177
different struct/union
178
179
180
181
incompatible operand
At least one operand-type is not valid with the given operator (e.g., ~float_type).
183
unmodifiable lvalue
The object to be changed resides in code memory and therefore cannot be modified.
184
185
The memory space of an object declaration differs from the memory space of a prior declaration for the same object.
186
invalid dereference
This error message may be caused by an internal compiler problem. Please contact technical support if this error is repeated.
187
not an lvalue
The needed argument must be the address of an object that can be modified.
188
The size of an object cannot be computed because of a missing dimension size on an array or indirection via a void pointer.
189
190
193
illegal optype(s) illegal add/sub on ptr illegal operation on bit(s) bad operand type
This error results when an expression uses illegal operand-types with the given operator. Examples of invalid expressions are bit * bit, ptr + ptr, or ptr * any. The error message includes the operator which caused the error. The following operations may be executed with bit-type operands: Assignment (=) OR / Compound OR (|, |=) AND / Compound AND (&, &=) XOR / Compound XOR (^, ^=) Compare bit with bit or constant (==, !=) Negation (~) bit operands may be used in expressions with other data types. In this case a type-cast is automatically performed.
194
The indirection operator * may not be used with void pointers because the object size, which the pointer refers to, is unknown.
195
198
199
The argument on the left side of the > operator must be a struct pointer or a union pointer.
200
The argument on the left side of the . operator must have type struct or union.
201
202
undefined identifier
203
This error indicates a problem within the compiler. Please contact technical support if this error is repeated.
204
undefined member
205
An interrupt function should not be called like a normal function. The entry and exit code for these functions is specially coded for interrupts.
207
A function declared with a void parameter list cannot receive parameters from the caller.
208
209
211
The term of a function call does not evaluate to a function or pointer to function.
212
An indirect function call through a pointer cannot contain actual parameters. An exception to this rule is when all parameters can be passed in registers. This is due to the method of parameter passing employed by C51. The name of the called function must be known because parameters are written into the data segment of the called function. For indirect calls, however, the name of the called function is unknown.
213
The address of a changeable object is required at the right side of the assignment operator.
214
215
216
An array reference contained either too many dimension specifiers or the object was not an array.
217
nonintegral index
The dimension expression of an array must be of the type char, unsigned char, int, or unsigned int. All other types are illegal.
218
219
The value of a constant expression must be capable of being represented by an int type.
220
A constant expression is expected. Object names, variables or functions, are not allowed in constant expressions.
221
225
An expression is too complex and must be broken into two or more sub expressions.
226
The name for a struct, union, or enum is already defined within current scope.
227
228
229
230
231
redefinition
233
undefined label
This message indicates a label that was accessed but was not defined. Sometimes this message appears several lines after the actual label reference. This is caused by the method used to search for undefined labels.
234
The maximum of 31 nested blocks has been exceeded. Additional levels of nested blocks are ignored.
235
Parameter types in the function declaration are different from those in the function prototype.
236
The number of parameters in the function declaration is different from the number of parameters in the function prototype.
237
238 239
duplicate member duplicate parameter
An attempt was made to define an already defined struct member or function parameter.
240
241
The required space for local objects exceeds the model-dependent maximum. The maximum segment sizes are defined as follows: SMALL 128 bytes COMPACT LARGE 256 bytes
64 KBytes
242
243
The number of characters in the string exceeds the number of characters required to initialize the array of characters.
244
245
246
This error occurs when a floating point argument lies outside of the valid range for 32-bit floating values. The numeric range of the 32-bit IEEE values is: 1.175494E-38 to 3.402823E+38.
247
nonaddress/constant initialize
A valid initializer expression must evaluate to a constant value or the name of an object plus or minus a constant.
248
The braces ({}) around the given struct or union initializer were missing.
249
The compiler detected a data segment that was too large. The maximum size of a data segment depends on memory space.
250
An escape sequence in a string constant exceeds the valid value range. The maximum value is 255.
251
252
Primary controls must be specified at the start of the C module before any #include directives or declarations.
253
This error can occur under the following circumstances: An intrinsic function (e.g., _testbit_) was activated incorrectly. This is the case when no prototype of the function exists and the number of actual parameters or their type is incorrect. For this reason, the appropriate declaration files must always be used (intrins.h, string.h). C51 recognized an internal consistency problem. Please contact technical support if this error occurs.
255
The expression in a switch statement must be one of the following types: char unsigned char unsigned int int
256
A function which contains the alien attribute may contain only the model specification small. The parameters of the function must lie in internal data memory. This applies to all external alien declarations and alien functions. For example: alien plm_func (char c) large { ... } generates error 256.
257
A function that contains the alien attribute cannot simultaneously contain the attribute reentrant. The parameters of the function cannot be passed via the virtual stack. This applies to all external alien declarations and alien functions.
258
A member of a struct may not contain the specification of a memory type. The object to which the pointer refers may, however, contain a memory type. For example:
struct vp { char code c; int xdata i; };
259
A spaced pointer has been assigned another spaced pointer with a different memory space. For Example: char xdata *p1; char idata *p2; p1=p2; /* different memory spaces */
260
pointer truncation
A spaced pointer has been assigned some constant value which exceeds the range covered by the pointers memory space. For Example: char idata *p1=0x1234; /* result is 0x34 */
261
bit(s) in reentrant ()
A function with the attribute reentrant cannot have bit objects declared inside the function. For Example: int func1 (int I1) reentrant { bit b1, b2; /* not allowed */
262
Functions declared with the using attribute and functions which rely on disabled interrupts (#pragma disable) cannot return a bit value to the caller. For example: bit test (void) using 3 { bit b0; return (b0); } produces error 262.
263
savestack overflow/underflow
The maximum nesting depth #pragma save comprises eight levels. The pragmas save and restore work with a stack according to the LIFO (last in, first out) principal.
264
This error indicates that an intrinsic function was defined incorrectly (parameter number or ellipsis notation). This error should not occur if you are using the standard .H files. Make sure that you are using the .H files that were included with C51. Do not try to define your own prototypes for intrinsic library functions.
265
A direct recursion to a non-reentrant function was discovered. This can be intentional, but is to be functionally checked in individual cases by means of the generated code. Indirect recursion is discovered by L51.
267
A function was invoked with parameters but the declaration specifies an empty parameter list. The prototype should be completed with the parameter types in order to give the compiler the opportunity to pass parameters in registers and have the calling mechanism consistent over the application.
268
271
The asm and endasm statements may not be nested. Endasm requires that an asm block was opened by a previous asm statement. For example:
272
The use of asm and endasm in a source file requires that the file is compiled using the SRC directive. The compiler then generates an assembly source file which may then be assembled with A51.
273
The use of asm and endasm is not permitted within include files. For debug reasons executable code should be avoided in include files anyway.
274
The absolute address specification is not allowed on bit objects and functions. The address must conform to the memory space of the object. For example, the following declaration is invalid because the range of the indirectly addressable data space is 0x00 to 0xFF.
278
constant to big
This error occurs when a floating-point argument lies outside of the valid range for 32-bit floating values. The numeric range of the 32-bit IEEE values -
279
multiple initialization
An attempt has been made to initialize some object more than once.
300
unterminated comment
This message occurs when a comment does not have a closing delimiter (*/).
301
identifier expected
302
misused # operator
303
This message occurs if the stringize operator # is not followed by an identifier representing a formal parameter name of the macro currently being defined.
304
The macro parameter list does not represent a brace enclosed, comma separated list of identifiers.
305
A string or character constant is invalid. Typically, this error is encountered if the closing quote is missing.
306
The end of the input file was reached while the preprocessor was collecting and expanding actual parameters of a macro call.
307
The number of actual parameters in a macro call doesnt match the number of parameters of the macro definition. This error indicates that too few parameters were specified.
308
309
310
The source file contains too many nested directives for conditional compilation. The maximum nesting level allowed is 20. 311 312
misplaced elif-else control misplaced endif control
The directives elif, else, and endif are legal only within an if, ifdef, or ifndef directive.