Comments (8)
part of iec-61131-3 ?
from matiec.
‘continue’ is part of iec-61131 of ST, i desire ‘jmp’ in st ,becuase 'jmp to some of label' is in LD. beremiz transfer LD to ST ,so i need the jmp in ST . And some of commercial PLC IDE has label and jmp in ST
from matiec.
I add 'continue' in matiec ,it works looks like not corret in 'for-statement'. it transter 'for-statement' to 'while-statment' with C. Continue make s it skip 'by-expression'
from matiec.
please provide failing ST code
from matiec.
PROGRAM program0
VAR
sum : DINT;
count : DINT;
END_VAR
FOR count:=0 TO 20 BY 2 DO
IF count>10 THEN
CONTINUE;
END_IF;
sum:= sum+count;
END_FOR;
END_PROGRAM
CONFIGURATION Config0
RESOURCE Res0 ON PLC
TASK task0(INTERVAL := T#20ms,PRIORITY := 0);
PROGRAM instance0 WITH task0 : program0;
END_RESOURCE
END_CONFIGURATION
from matiec.
/*absyntax.def*/
////////////////////
/* continue */
SYM_REF0(continue_statement_c)
/*flex.ll*/
/////////////////////////////////
CONTINUE return CONTINUE
/*bison,yy*/
//////////////////////////////////////
%type <leaf> continue_statement
%token CONTINUE
/********************************/
/* B 3.2.4 Iteration Statements */
/********************************/
iteration_statement:
for_statement
| while_statement
| repeat_statement
| exit_statement
| continue_statement
;
continue_statement:
CONTINUE {$$ = new continue_statement_c(locloc(@$));}
;
/*accessor.h*/
//////////////////////////////
#define __SET_EXTERNAL_FB(prefix, name, suffix, new_value)\
__SET_VAR((*(prefix name)), suffix, new_value)
#define __SET_LOCATED(prefix, name, suffix, new_value)\
if (!(prefix name.flags & __IEC_FORCE_FLAG)) *(prefix name.value) suffix = new_value
#define __SET_VAR(prefix, name, suffix, new_value)\
!(prefix name.flags & __IEC_FORCE_FLAG) ? (prefix name.value suffix = (new_value),0) : 0
#define __SET_EXTERNAL(prefix, name, suffix, new_value)\
!(prefix name.flags & __IEC_FORCE_FLAG || __IS_GLOBAL_##name##_FORCED())?((*(prefix name.value)) suffix = new_value,0):0
/*generate_c_st.cc*/
//////////////////////////////
void * print_external_extern(symbol_c* symbol) {
unsigned int vartype = analyse_variable_c::first_nonfb_vardecltype(symbol, scope_);
symbol_c* first_nonfb = analyse_variable_c::find_first_nonfb(symbol);
if (vartype == search_var_instance_decl_c::external_vt)
{
if (!get_datatype_info_c::is_type_valid(first_nonfb->datatype)) ERROR;
if (!get_datatype_info_c::is_function_block(first_nonfb->datatype))
{
s4o.print("extern IEC_BYTE __IS_GLOBAL_");
s4o.printupper((symbol)->token->value);
s4o.print("_FORCED(void);\n");
}
}
return NULL;
}
/********************************/
/* B 3.2.4 Iteration Statements */
/********************************/
void *visit(for_statement_c *symbol) {
s4o.print("/* FOR ... */\n" + s4o.indent_spaces);
/* For the initialization part, we create an assignment_statement_c */
/** and have this visitor visit it! */
assignment_statement_c ini_assignment(symbol->control_variable, symbol->beg_expression);
ini_assignment.accept(*this);
s4o.print(";\n");
/* declare global iterator */
print_external_extern(symbol->control_variable);
s4o.print("for( \n;\n");
if (symbol->by_expression == NULL) {
/* increment by 1 */
symbol->control_variable->accept(*this);
s4o.print(" <= ");
symbol->end_expression->accept(*this);
} else {
/* increment by user defined value */
/* The user defined increment value may be negative, in which case
* the expression to determine whether we have reached the end of the loop
* changes from a '<=' to a '>='.
* Since the increment value may change during runtime (remember, it is
* an expression, so may contain variables), choosing which test
* to use has to be done at runtime.
*/
s4o.print("((");
symbol->by_expression->accept(*this);
s4o.print(") > 0)? (");
symbol->control_variable->accept(*this);
s4o.print(" <= (");
symbol->end_expression->accept(*this);
s4o.print(")) : (");
symbol->control_variable->accept(*this);
s4o.print(" >= (");
symbol->end_expression->accept(*this);
s4o.print(")) ");
}
s4o.print(" ;\n");
/* increment part */
if (symbol->by_expression == NULL) {
/* increment by 1 */
/* For the increment part, we create an add_expression_c and assignment_statement_c */
/* and have this visitor vist the latter! */
integer_c integer_oneval("1");
add_expression_c add_expression(symbol->control_variable, &integer_oneval);
assignment_statement_c inc_assignment(symbol->control_variable, &add_expression);
integer_oneval.const_value._int64 .set(1); // set the stage3 anottation we need
integer_oneval.const_value._uint64.set(1); // set the stage3 anottation we need
integer_oneval.datatype = symbol->control_variable->datatype; // set the stage3 anottation we need
add_expression.datatype = symbol->control_variable->datatype; // set the stage3 anottation we need
inc_assignment.accept(*this);
//symbol->control_variable->accept(*this); // this does not work for VAR_GLOBAL variables
//s4o.print("++");
} else {
/* increment by user defined value */
/* For the increment part, we create an add_expression_c and assignment_statement_c */
/* and have this visitor vist the latter! */
add_expression_c add_expression(symbol->control_variable, symbol->by_expression);
assignment_statement_c inc_assignment(symbol->control_variable, &add_expression);
add_expression.datatype = symbol->control_variable->datatype; // set the stage3 anottation we need
inc_assignment.accept(*this);
//symbol->control_variable->accept(*this); // this does not work for VAR_GLOBAL variables
//s4o.print(" += (");
//symbol->by_expression->accept(*this);
//s4o.print(")");
}
s4o.print("\n){\n");
/* the body part */
s4o.indent_right();
symbol->statement_list->accept(*this);
s4o.indent_left();
s4o.print(";\n" + s4o.indent_spaces + "} /* END_FOR */");
return NULL;
}
void *visit(while_statement_c *symbol) {
s4o.print("while (");
symbol->expression->accept(*this);
s4o.print(") {\n");
s4o.indent_right();
symbol->statement_list->accept(*this);
s4o.indent_left();
s4o.print(s4o.indent_spaces); s4o.print("}");
return NULL;
}
from matiec.
What are theses code fragments supposed to be ? Beware that Markdown syntax broke copy-pasted code. If you are proposing some changes then please attach a patch or make a pull request.
from matiec.
Your implementation was having many adverse side effects, I had to redo it.
See 8a06b3b.
from matiec.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from matiec.