Skip to content

vlsi/iec61131-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Maven Central

IEC61131 parsers

About

This is a ANTLRv4 grammar for IEC61131-3 languages. The main aim is to parse ST grammar.

Usage

Add maven dependency:

<dependency>
    <groupId>com.github.vlsi.iec61131</groupId>
    <artifactId>parser</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</dependency>

Sample

ANTLRInputStream is = new ANTLRInputStream("FUNCTION abc : BOOL VAR_TEMP temp: INT; END_VAR");
IEC61131Lexer lex = new IEC61131Lexer(is);
CommonTokenStream ts = new CommonTokenStream(lex);
IEC61131Parser p = new IEC61131Parser(ts);

IEC61131Parser.FunctionContext function = p.function();

Assert.assertEquals(function.name.getText(), "abc", "function name");
Assert.assertEquals(function.var_block().size(), 1, "1 block with variables");
IEC61131Parser.Var_blockContext varBlock = function.var_block(0);

Assert.assertEquals(varBlock.temp, true, "var_temp -> temp.true");
Assert.assertEquals(varBlock.variable_declaration().size(), 1, "1 variable");

IEC61131Parser.Variable_declarationContext var =
    varBlock.variable_declaration(0);
Assert.assertEquals(var.name.getText(), "temp", "variable name");
Assert.assertEquals(var.type.getText(), "INT", "variable type");

License

This library is distributed under terms of MIT license.

Changelog

v1.0.0

  • Initial version

Author

Vladimir Sitnikov [email protected]

About

Parsers for IEC 61131-3 grammar

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published