Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions pmd-awl/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>pmd-awl</artifactId>
<name>PMD AWL</name>

<parent>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd</artifactId>
<version>7.6.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>antlr-cleanup</id>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<ant antfile="${antlr4.ant.wrapper}" target="cpd-language">
<property name="lang-name" value="AWL" />
<property name="lang-id" value="awl" />
</ant>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<useDefaultDelimiters>false</useDefaultDelimiters>
<delimiters>
<delimiter>${*}</delimiter>
</delimiters>
</configuration>
</plugin>
<plugin>
<groupId>com.github.siom79.japicmp</groupId>
<artifactId>japicmp-maven-plugin</artifactId>
<configuration>
<parameter>
<ignoreMissingOldVersion>true</ignoreMissingOldVersion>
</parameter>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-core</artifactId>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-lang-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
lexer grammar AWLLexer;

PARSERTOKEN : ';' | ':' | '{' | '}' | '=' | ':=' | '[' | ']' | '(' | ')' | '..' | ',' | '+' | '-' | '.' | '#' | '%' ;

INSTRUCTIONNAME : '<=' | '+AR1' | '+AR2' | '+D' | '-D' | '*D' | '/D' | '==D' | '>D' | '>=D' | '<D' | '<>D' |
'+I' | '-I' | '*I' | '/I' | '==I' | '>I' | '>=I' | '<I' | '<>I' | '+R' | '-R' | '*R' | '/R' | 'RND+' | 'RND-' ;

LOGICCOMPARISON : '==0' | '<>0' | '>0' | '<0' | '>=0' | '<=0' ;

TITLE : 'TITLE' [ \t]* '=' ~[\r\n]* ;

POINTER_OP : 'P#' 'DBX'? ;

ARRAY_INIT : Integer '(' '\'' AnyPrintChar '\'' ')' ;
fragment AnyPrintChar : [\u0040-\u007E] ;

ID : IdentifierStart IdentifierChar* ;
fragment IdentifierStart : '_' | 'a' .. 'z' | 'A' .. 'Z' ;
fragment IdentifierChar : IdentifierStart | Digit | '-' ;

StringConstant : DOUBLE_QUOTED_STRING | SINGLE_QUOTED_STRING ;
fragment DOUBLE_QUOTED_STRING : '"' AnyCharExceptDoubleQuoteNewline* '"' ;
fragment SINGLE_QUOTED_STRING : '\'' AnyCharExceptSingleQuoteNewline* '\'' ;
fragment AnyCharExceptDoubleQuoteNewline : [\u0000-\u0009] | [\u000B] | [\u000C] | [\u000E-\u0021] | [\u0023-\u007F] ;
fragment AnyCharExceptSingleQuoteNewline : [\u0000-\u0009] | [\u000B] | [\u000C] | [\u000E-\u0026] | [\u0028-\u007F] ;

REAL : Integer '.' Integer ;

INT : Integer ;

fragment Integer : Digit+ ;
fragment Digit : [0-9] ;

HEX_INT : '16#' HexDigit+ ;
fragment HexDigit : [0-9] | [A-F] | [_] ;

BIN_INT : '2#' BinDigit+ ;
BinDigit : [0-1] ;

TIME : 'S5'? ('t' | 'T') '#' Digit+ TimeUnit ;
fragment TimeUnit : 'H' | 'h' | 'M' | 'm' | 'S' | 's' | 'MS' | 'ms' ;

LineComment : '//' ~[\r\n]* -> channel(HIDDEN) ;
BlockComment : '(*' .*? '*)' -> channel(HIDDEN) ;
Whitespace : [ \t]+ -> skip ;
LineTerm : [\r\n]+ -> channel(HIDDEN) ;
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/

package net.sourceforge.pmd.lang.awl;

import net.sourceforge.pmd.cpd.CpdLexer;
import net.sourceforge.pmd.lang.LanguagePropertyBundle;
import net.sourceforge.pmd.lang.awl.cpd.AwlCpdLexer;
import net.sourceforge.pmd.lang.impl.CpdOnlyLanguageModuleBase;

public class AwlLanguageModule extends CpdOnlyLanguageModuleBase {
private static final String ID = "awl";

public AwlLanguageModule() {
super(LanguageMetadata.withId(ID).name("AWL").extensions("awl", "AWL"));
}

@Override
public CpdLexer createCpdLexer(LanguagePropertyBundle bundle) {
return new AwlCpdLexer();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/

package net.sourceforge.pmd.lang.awl.cpd;

import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Lexer;

import net.sourceforge.pmd.cpd.impl.AntlrCpdLexer;
import net.sourceforge.pmd.lang.awl.ast.AWLLexer;

public class AwlCpdLexer extends AntlrCpdLexer {

@Override
protected Lexer getLexerForSource(CharStream charStream) {
return new AWLLexer(charStream);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
net.sourceforge.pmd.lang.awl.AwlLanguageModule
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/

package net.sourceforge.pmd.lang.awl.cpd;

import org.junit.jupiter.api.Test;

import net.sourceforge.pmd.lang.test.cpd.CpdTextComparisonTest;

class AwlCpdLexerTest extends CpdTextComparisonTest {

AwlCpdLexerTest() {
super("awl", ".awl");
}

@Test
void examples() {
doTest("awl_examples");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Combined some publicly available AWL/STL examples (good enough for lexer-only test)
// from STL reference document 'Statement List (STL) for S7-300 and S7-400 Programming'
// https://cache.industry.siemens.com/dl/files/814/109751814/att_933093/v1/STEP_7_-_Statement_List_for_S7-300_and_S7-400.pdf

FUNCTION_BLOCK "fb1"
TITLE = %version: 1 % Title information is present here % $ ^ \
{ this_is_false := 'FALSE' }
FAMILY : Fam1
VERSION : 0.0

// Input variables
VAR_INPUT
i_ID : DWord; // Var 1
CFG_Position_node : Int;
END_VAR

// Output variables
VAR_OUTPUT
output_var_1 : Bool;
output_var_2 : Int;
output_var_3 : Bool;
END_VAR

// Example: Statement List to control the Conveyor Belt
O I 1.1 //Pressing either start switch turns the motor on.
O I 1.3
S Q 4.0
O I 1.2 //Pressing either stop switch or opening the normally closed contact at
//the end of the belt turns the motor off.
O I 1.4
ON I 1.5
R Q 4.0

// Example: Statement List to Generate a Clock Pulse (pulse duty factor 1:1)
AN T1 //If timer T 1 has expired,
L S5T#250ms //load the time value 250 ms into T 1 and
SV T1 //start T 1 as an extended-pulse timer.
NOT //Negate (invert) the result of logic operation.
BEB //If the timer is running, end the current block.
L MB100 //If the timer has expired, load the contents of memory byte MB100,
INC 1 //increment the contents by 1,
T MB100 //and transfer the result to memory byte MB100.

L ID20 //Load contents of ID20 into ACCU 1.
L ID24 //Load contents of ACCU 1 into ACCU 2. Load contents of ID24 into ACCU
1.
AD //Combine bits from ACCU 1 with ACCU 2 by AND, store result in ACCU
1.
T MD8 //Transfer result to MD8.

L ID 20 //Load contents of ID20 into ACCU 1.
AD DW#16#0FFF_EF21 //Combine bits of ACCU 1 with bit pattern of 32-bit constant
(0000_1111_1111_1111_1110_1111_0010_0001) by AND; store result in
ACCU 1.
>=I
JP NEXT //Jump to NEXT jump label if result is unequal to zero, (CC 1 = 1).

END_FUNCTION_BLOCK
Loading