Clarion Language and Clarion Template Language syntax grammars

I am studying about lexers and interpreters. A few years back, I took a lexer that @CarlBarnes did for Clarion Magazine and modified it to “sort” of tokenize Clarion code. That worked fine for what I was trying to do back then, but I would like to do a better job this time. For example, a couple of things that I did wrong were that I didn’t categorize the tokens, and also that I just ignored various language constructs (such as classes and interfaces)…

I think it was over 10 years ago that I read somewhere the syntax grammar (I guess it was BNF) for Topspeed C. I can’t recall where I saw it however, but I think it was in one of the Topspeed language manuals. That got me thinking, do any of you have the syntax grammar for Clarion Language and/or Clarion Template Language? Even if it is incomplete that would be great!

Thanks.

Maybe ask Ralf Schoeffler if his ClaScript would help you in your endeavors? Says there’s no black box.

https://www.schoeffler.biz/clarion/clascript/

5 and 5.5 came with the ConvSrc tool for moving to ABC. Inside CnvEng you’ll find the LexerClass class that I think was for parsing Clarion code. IIRC it had some bugs I fixed. it had improvements in 6.0 but SV did not include the source.

LexerClass          CLASS,TYPE,MODULE('CNVENG')
TokenList             &TokenQueue,PRIVATE

Init                  PROCEDURE
Kill                  PROCEDURE
FindToken             FUNCTION(STRING Token,USHORT StartPos=1),USHORT
GetEndChrPos          FUNCTION(USHORT TokenNumber),LONG
GetStartChrPos        FUNCTION(USHORT TokenNumber),LONG
GetToken              FUNCTION(USHORT TokenNumber),STRING
GetTokenCount         FUNCTION(),USHORT
TakeLine              PROCEDURE(*CSTRING TextLine)
TokenReplace          FUNCTION(*CSTRING cLine,*CSTRING[] TokenSequence,*CSTRING Replacement,FileQueue FileList,<USHORT NumberTokens>),BYTE
ViewTokens            PROCEDURE                       !Debug only
                    END

Attached is the original. It is a 16 bit hand code .PR project that will not compile in C8+. But the Lexer class may help you.

ConvSrc_55.zip (94.6 KB)


In 5.5 and 6 was an Example named CallTree that included ABSource.inc with ClarionSourceClass that appears to be for parsing code. I think it may be more limited to finding Procedures and Classes…

CallTree_c6.zip (35.1 KB)

ClarionSourceClass  CLASS,TYPE,MODULE('ABSOURCE.CLW'),LINK('ABSOURCE.CLW',_ABCLinkMode_),DLL(_ABCDllMode_)

Continued             BYTE,PRIVATE
DelimiterQ            &DelimiterQueue,PROTECTED
Delimiters            CSTRING(' ,.&()<<>[]{{}=~^+-*/%;?')
Debug                 BYTE
EndLabel              USHORT
Label                 STRING(LabelLength)
Line                  CSTRING(2000)           !copy of OriginalLine
LineLength            USHORT
ModuleName            STRING(LabelLength)     !filled when TakeLine returns Source:DeclaresClass
OriginalLine          &STRING,PRIVATE         !source file record buffer
Parameters            STRING(ParameterLength) !filled when TakeLine returns Source:DeclaresProcedure
ParentClass           STRING(LabelLength)     !filled when TakeLine returns Source:DeclaresClass
SourceType            BYTE                    !see Source EQUATEs above.
StartScan             USHORT
WordQ                 &WordQueue,PROTECTED

GetLeftDelimiter      PROCEDURE,STRING
GetRightDelimiter     PROCEDURE,STRING
GetLeftWord           PROCEDURE,STRING
GetRightWord          PROCEDURE,STRING
Init                  PROCEDURE(*STRING SourceLine)  !SourceLine: Clarion source file record buffer

Kill                  PROCEDURE
LoadQueues            PROCEDURE,PRIVATE    !loads the WordQueue & DelimiterQueue

NextDataLabelPair     PROCEDURE(*STRING DataType, *STRING Label),BYTE,PROC
!DataType: a variable to receive a datatype found in SourceCode
!Label: a variable to receive the label associated with the DataType
!Loads DataType and Label.
!Multiple calls to NextDataLabelPair progress from left to right.
!Returns True if pair found, otherwise returns false.

NextWord              PROCEDURE,STRING,PROC
!Returns next chunk of text in the source line.
!Multiple calls to NextWord progress from left to right.

NextWordDotWordPair   PROCEDURE(*STRING Word1, *STRING Word2),BYTE,PROC
!Word1: a variable to receive the word left of the next period
!Word2: a variable to receive the word right of the next period
!Multiple calls to NextWordDotWordPair progress from left to right.
!Returns True if pair found, otherwise returns false.

NextObjectReference PROCEDURE(*STRING Word1, *STRING Word2),BYTE,PROC
!Word1: a variable to receive the next SELF/PARENT[.property1.property2...] construction
!Word2: a variable to receive the property/method that terminates Word1
!Multiple calls to NextObjectReference progress from left to right.
!Returns True if pair found, otherwise returns false.

Reset                 PROCEDURE,PRIVATE
SetLabel              PROCEDURE,PRIVATE
SetModule             PROCEDURE,PRIVATE
SetParameters         PROCEDURE,PRIVATE
SetParentClass        PROCEDURE,PRIVATE

TakeLine              PROCEDURE(<*STRING SourceCode>),BYTE,PROC
!SourceCode: an optional line of Clarion source code. If omitted, the object
!operates on the current line->SELF.OriginalLine
!Initial scan of source line, loads properties and returns one of the following:
!Source:IsBlank
!Source:IsComment
!Source:DeclaresProcedure (SELF.Label, SELF.Parameters,SELF.WordQ, SELF.DelimiterQ are loaded)
!Source:DeclaresClass     (SELF.Label, SELF.ModuleName, SELF.ParentClass,SELF.WordQ, SELF.DelimiterQ are loaded)
!Source:Other             (SELF.WordQ, SELF.DelimiterQ are loaded)
!e.g.  CASE SourceObject.TakeLine
!      OF Source:DeclaresClass
!        DO SomethingWithLabelOrModule
!      OF Source:DeclaresProcedure
!        DO SomethingWithParameters
!      END
                    END
1 Like

Hi Jeff,
I have ClaScript, and I have looked at the code of what he’s doing.

Doesn’t help me much because it does a very specific tokenization of the clarion code for the type of scripts you would write with this.

Thanks anyway.

1 Like

Thanks Carl! Will look at this.

I was looking at the “convsrc” example. That is something quite interesting. It has a mechanism to load your own personal addins.
This builds a “ConversionEngine” DLL which I guess is called from an AppConvert program (which is not included in the example code). And to that ConversionEngine DLL you can add your own conversion addin DLLs. There is an addin example “cnvbeta.clw”. It is quite interesting I think!

Thanks for this. I don’t have Clarion 5.5 installed anymore, but it would be interesting to see if it has the “AppConvert.clw” source code.

My Zip was the entire project to make C55convc.exe and its DLL’s. Problem is it is a hand code 16-bit project.

C55conv.pr makes the C55conv.EXE

-- Clarion 5 Conversion Tool
#noedit
#system win
#model clarion dll
#pragma debug(vid=>full)

#include "cnveng.pr"
#include "cnvbeta.pr"
#include "cnvrules.pr"

#compile "Conv.clw" /define(maincode=>on)

#pragma link(c%V%cnven.lib)
#pragma link_option(icon=>"cwConv.ico")

#link "c%V%conv.exe"
#if '%action'='run' #or '%action'='debug' #then
  #error "You should not try to run this directly from the project, as the IDE is not ready to handle DDE requests"
#endif

CnvEng.PR makes the C55cnven.DLL

-- Convertor Engine
#noedit
#system win
#model clarion dll
#pragma define(maincode=>off)
#pragma debug(vid=>full)
#compile "cnveng.clw"
#pragma link("C%V%ASC%X%%L%.LIB")
#pragma link("C%V%DOS%X%%L%.LIB")
#pragma link("Conv_1m.bmp")  -- Note: Omitted 9 other Link BMP lines
#link "C%V%cnven.dll"

Cnvbeta.PR and Cnvrules.PR would make those DLLs.

If did have a Plug-In concept so the EXE would load other DLLs based on the Engine Class e.g. CnvBeta. the idea was 3rd party would make DLLs for their products.

Andrew Barnham produced a Clarion2Java compiler that would take Clarion source code files and produce working Java programs from it.

It’s not been updated for years but it is still there on SourceForge

Hit the Download button and it’ll get you the compiled Java sources ie .JAR executables.
Hit the Code button (far right-hand side) and it’s your entry into the full .JAVA source files of the Lexer, Compiler etc etc eg

https://sourceforge.net/p/clarion2java/code/HEAD/tree/compiler/trunk/src/main/java/org/jclarion/clarion/compile/grammar/

Far, Far too complex for me, not knowing JAVA, but maybe some of it is useful to you?

Hi Graham,
Thanks for the tip.

Also related to the conversion program, see David Bayliss’s article “Computer Aided Disaster” at Comp. Aided Disaster

In particular the last section: “The application converter”.

Also a handy pdf created by Carl from the online help is attached:

Legacy2ABC.pdf (46.4 KB)

and finally the “LearnABC.pdf” file https://www.icetips.com/ftp/clarion/learnabc.pdf has a chapter on the converter

1 Like

I do remember that the problem with the converter was that it only took a TXA, but did not know anything about the files, so it could not convert the simple code of a LOOP NEXT to use the Access class Next method.
Some 25 years ago I do remember adding the TXD support, so the code can be converted properly and get the tables and fields but lost that code when my laptop on that time stop working.
But the idea was to parse the TXD and load a queue with the names that can be used in the conversion of the code, not just moving it from one embed to other.

Hi Carl

It looks to have dated back even earlier to C4 when ABC was introduced.

see the attached article “Adding Rules to the C4 Conversion Wizard” by Mike Hanson:

98-03-conversionwiz.pdf (248.4 KB)

A version of this article was basically incorporated into that Learning Your ABCs
file https://www.icetips.com/ftp/clarion/learnabc.pdf mentioned above.

thanks as always to Dave Harms for allowing sharing.

2 Likes