stage1_2/iec.flex
changeset 1 5d893a68be6e
parent 0 fb772792efd1
child 3 38850ee685e6
equal deleted inserted replaced
0:fb772792efd1 1:5d893a68be6e
   274  *                    and followed by a VAR declaration)
   274  *                    and followed by a VAR declaration)
   275  *   INITIAL -> body (when a FUNCTION, FUNCTION_BLOCK, or PROGRAM is found,
   275  *   INITIAL -> body (when a FUNCTION, FUNCTION_BLOCK, or PROGRAM is found,
   276  *                    and _not_ followed by a VAR declaration)
   276  *                    and _not_ followed by a VAR declaration)
   277  *   INITIAL -> config (when a CONFIGURATION is found)
   277  *   INITIAL -> config (when a CONFIGURATION is found)
   278  *   decl    -> body (when the last END_VAR is found, i.e. the function body starts)
   278  *   decl    -> body (when the last END_VAR is found, i.e. the function body starts)
       
   279  *   body    -> sfc (when it figures out it is parsing sfc language)
   279  *   body    -> st (when it figures out it is parsing st language)
   280  *   body    -> st (when it figures out it is parsing st language)
   280  *   body    -> il (when it figures out it is parsing il language)
   281  *   body    -> il (when it figures out it is parsing il language)
   281  *   decl    -> INITIAL (when a END_FUNCTION, END_FUNCTION_BLOCK, or END_PROGRAM is found)
   282  *   decl    -> INITIAL (when a END_FUNCTION, END_FUNCTION_BLOCK, or END_PROGRAM is found)
   282  *   st      -> INITIAL (when a END_FUNCTION, END_FUNCTION_BLOCK, or END_PROGRAM is found)
   283  *   st      -> INITIAL (when a END_FUNCTION, END_FUNCTION_BLOCK, or END_PROGRAM is found)
       
   284  *   sfc     -> INITIAL (when a END_FUNCTION, END_FUNCTION_BLOCK, or END_PROGRAM is found)
   283  *   il      -> INITIAL (when a END_FUNCTION, END_FUNCTION_BLOCK, or END_PROGRAM is found)
   285  *   il      -> INITIAL (when a END_FUNCTION, END_FUNCTION_BLOCK, or END_PROGRAM is found)
   284  *   config  -> INITIAL (when a END_CONFIGURATION is found)
   286  *   config  -> INITIAL (when a END_CONFIGURATION is found)
   285  */
   287  */
   286 /* we are parsing a configuration. */
   288 /* we are parsing a configuration. */
   287 %s config
   289 %s config
   296 %s il
   298 %s il
   297 
   299 
   298 /* we are parsing st code -> flex must not return the EOL tokens!   */
   300 /* we are parsing st code -> flex must not return the EOL tokens!   */
   299 %s st
   301 %s st
   300 
   302 
       
   303 /* we are parsing sfc code -> flex must not return the EOL tokens!   */
       
   304 %s sfc
   301 
   305 
   302 
   306 
   303 
   307 
   304 /*******************/
   308 /*******************/
   305 /* File #include's */
   309 /* File #include's */
   688 			    yy_delete_buffer(YY_CURRENT_BUFFER);
   692 			    yy_delete_buffer(YY_CURRENT_BUFFER);
   689 			    yy_switch_to_buffer((include_stack[include_stack_ptr]).buffer_state);
   693 			    yy_switch_to_buffer((include_stack[include_stack_ptr]).buffer_state);
   690 			    yylineno = include_stack[include_stack_ptr].lineno;
   694 			    yylineno = include_stack[include_stack_ptr].lineno;
   691 			      /* removing constness of char *. This is safe actually,
   695 			      /* removing constness of char *. This is safe actually,
   692 			       * since the only real const char * that is stored on the stack is
   696 			       * since the only real const char * that is stored on the stack is
   693 			       * the first one (i.e. the opne that gets stored in include_stack[0],
   697 			       * the first one (i.e. the one that gets stored in include_stack[0],
   694 			       * which is never free'd!
   698 			       * which is never free'd!
   695 			       */
   699 			       */
   696 			    free((char *)current_filename);
   700 			    free((char *)current_filename);
   697 			    current_filename = include_stack[include_stack_ptr].filename;
   701 			    current_filename = include_stack[include_stack_ptr].filename;
   698 			    yy_push_state(include_end);
   702 			    yy_push_state(include_end);
   743 <decl>{
   747 <decl>{
   744 END_VAR{st_whitespace}VAR			unput_text(strlen("END_VAR")); return END_VAR;
   748 END_VAR{st_whitespace}VAR			unput_text(strlen("END_VAR")); return END_VAR;
   745 END_VAR{st_whitespace}				unput_text(strlen("END_VAR")); BEGIN(body); return END_VAR;
   749 END_VAR{st_whitespace}				unput_text(strlen("END_VAR")); BEGIN(body); return END_VAR;
   746 }
   750 }
   747 
   751 
   748 	/* body -> (il | st) */
   752 	/* body -> (il | st | sfc) */
       
   753 <body>INITIAL_STEP				unput_text(0); BEGIN(sfc);
       
   754 
   749 <body>{
   755 <body>{
   750 {qualified_identifier}{st_whitespace}":="	unput_text(0); BEGIN(st);
   756 {qualified_identifier}{st_whitespace}":="	unput_text(0); BEGIN(st);
   751 {qualified_identifier}"["			unput_text(0); BEGIN(st);
   757 {qualified_identifier}"["			unput_text(0); BEGIN(st);
   752 
   758 
   753 RETURN						unput_text(0); BEGIN(st);
   759 RETURN						unput_text(0); BEGIN(st);
   770 		}
   776 		}
   771 .		unput_text(0); BEGIN(il);
   777 .		unput_text(0); BEGIN(il);
   772 
   778 
   773 }	/* end of body lexical parser */
   779 }	/* end of body lexical parser */
   774 
   780 
   775 	/* (decl | body | il | st) -> INITIAL */
   781 	/* (decl | body | il | st | sfc) -> INITIAL */
   776 END_FUNCTION		BEGIN(INITIAL); return END_FUNCTION;
   782 END_FUNCTION		BEGIN(INITIAL); return END_FUNCTION;
   777 END_FUNCTION_BLOCK	BEGIN(INITIAL); return END_FUNCTION_BLOCK;
   783 END_FUNCTION_BLOCK	BEGIN(INITIAL); return END_FUNCTION_BLOCK;
   778 END_PROGRAM		BEGIN(INITIAL); return END_PROGRAM;
   784 END_PROGRAM		BEGIN(INITIAL); return END_PROGRAM;
   779 
   785 
   780 	/* config -> INITIAL */
   786 	/* config -> INITIAL */
   785 	/***************************************/
   791 	/***************************************/
   786 	/* Next is to to remove all whitespace */
   792 	/* Next is to to remove all whitespace */
   787 	/***************************************/
   793 	/***************************************/
   788 	/* NOTE: pragmas are handled right at the beginning... */
   794 	/* NOTE: pragmas are handled right at the beginning... */
   789 
   795 
   790 <INITIAL,config,decl,st,body>{st_whitespace_no_pragma}	/* Eat any whitespace */
   796 <INITIAL,config,decl,st,sfc,body>{st_whitespace_no_pragma}	/* Eat any whitespace */
   791 <il,body>{il_whitespace_no_pragma}		/* Eat any whitespace */
   797 <il,body>{il_whitespace_no_pragma}		/* Eat any whitespace */
   792 
   798 
   793 
   799 
   794 	/*****************************************/
   800 	/*****************************************/
   795 	/* B.1.1 Letters, digits and identifiers */
   801 	/* B.1.1 Letters, digits and identifiers */
   991 	/* NOTE: the following identifiers/tokens clash with the R and S IL operators, as well
   997 	/* NOTE: the following identifiers/tokens clash with the R and S IL operators, as well
   992 	.* as other identifiers that may be used as variable names inside IL and ST programs.
   998 	.* as other identifiers that may be used as variable names inside IL and ST programs.
   993 	 * They will have to be handled when we include parsing of SFC... For now, simply
   999 	 * They will have to be handled when we include parsing of SFC... For now, simply
   994 	 * ignore them!
  1000 	 * ignore them!
   995 	 */
  1001 	 */
   996 	 /*
  1002 	 
       
  1003 <sfc>{
   997 ACTION		return ACTION;
  1004 ACTION		return ACTION;
   998 END_ACTION	return END_ACTION;
  1005 END_ACTION	return END_ACTION;
   999 
  1006 
  1000 TRANSITION	return TRANSITION;
  1007 TRANSITION	return TRANSITION;
  1001 END_TRANSITION	return END_TRANSITION;
  1008 END_TRANSITION	return END_TRANSITION;
  1016 N		return N;
  1023 N		return N;
  1017 P		return P;
  1024 P		return P;
  1018 
  1025 
  1019 R		return R;
  1026 R		return R;
  1020 S		return S;
  1027 S		return S;
  1021 	*/
  1028 }
  1022 
  1029 
  1023 
  1030 
  1024 	/********************************/
  1031 	/********************************/
  1025 	/* B 1.7 Configuration elements */
  1032 	/* B 1.7 Configuration elements */
  1026 	/********************************/
  1033 	/********************************/