Jan 9, 2012

Lexical and Syntax errors in Macros


When you are developing code that contains macros, you must understand whether an error message is generated during the precompile or the compile phase. The two key words to look for are:
            
                           Lexical – This indicates a precompile error.
                           Syntax – This indicates a compile error.

#define.MyMacro1(info("Hello");)  -  Lexical error caused by the first closing parenthesis, which marks the end of the directive. Therefore the precompiler is confused by the last two characters ;)

#define.MyMacro2(++++iTest;)  (or) #MyMacro2  -  A Syntax error caused by using the non-existent ++++ operator. The X++ compiler encounters this operator after #MyMacro2 is replaced by the macro value.
The macro definition is correct even though its value is not accepted X++ syntax.

No comments: