Jump to content

activex GOLD parser in autoit, is this possible?


Go to solution Solved by mLipok,

Recommended Posts

hi everyone ;)

i have an interesting question about the gold parser:

info:

http://www.goldparser.org/index.htm

download (regsvr32 to register):

http://www.goldparser.org/engine/1/vb6/index.htm

on the website it seems that this dll can be used as an activex object,

does that mean that it can be used in autoit to?

help for the activeX dll:

http://www.goldparser.org/engine/1/vb6/doc/index.htm

it gives me error code '4' if i try to use it...  :mellow:

Const $gpMsgAccept = 3
Const $gpMsgCommentBlockRead = 9
Const $gpMsgCommentError = 7
Const $gpMsgCommentLineRead = 10
Const $gpMsgInternalError = 8
Const $gpMsgLexicalError = 5
Const $gpMsgNotLoadedError = 4
Const $gpMsgReduction = 2
Const $gpMsgSyntaxError = 6
Const $gpMsgTokenRead = 1

$Parser = ObjCreate("goldparserengine.goldparser")

$Parser.LoadCompiledGrammar("test_script.cgt")
$Parser.OpenFile("Program.txt")

$Response = $Parser.Parse()
MsgBox(0,'test',$Response)

If there are people interested in answering or helping feel free to reply and then i will upload the "test_script.cgt" somewhere if you want :)

i know this question is a bit specific but you never know..  :whistle:

Thanks for reading!

TheAutomator.

Edited by TheAutomator
Link to comment
Share on other sites

gpMsgNotLoadedError 4 Before any parsing can take place, a Compiled Grammar Table file must be loaded.

 

can you post here:

test_script.cgt

Program.txt

?

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

  • Solution

Working example:

;~ http://www.goldparser.org/doc/templates/example-vb-activex.htm

Global Const $__eGOLDPARSER_gpMsgTokenRead = 1 ; Each time a token is read, this message is generated.
Global Const $__eGOLDPARSER_gpMsgReduction = 2 ; When the engine is able to reduce a rule, this message is returned. The rule that was reduced is set in the GOLDParser's ReduceRule property. The tokens that are reduced and correspond the rule's definition are stored in the Tokens() property.
Global Const $__eGOLDPARSER_gpMsgAccept = 3 ; The engine will returns this message when the source text has been accepted as both complete and correct. In other words, the source text was successfully analyzed.
Global Const $__eGOLDPARSER_gpMsgNotLoadedError = 4 ; Before any parsing can take place, a Compiled Grammar Table file must be loaded.
Global Const $__eGOLDPARSER_gpMsgLexicalError = 5 ; The tokenizer will generate this message when it is unable to recognize a series of characters as a valid token. To recover, pop the invalid token from the input queue.
Global Const $__eGOLDPARSER_gpMsgSyntaxError = 6 ; Often the parser will read a token that is not expected in the grammar. When this happens, the Tokens() property is filled with tokens the parsing engine expected to read. To recover: push one of the expected tokens on the input queue.
Global Const $__eGOLDPARSER_gpMsgCommentError = 7 ; The parser reached the end of the file while reading a comment. This is caused when the source text contains a "run-away" comment, or in other words, a block comment that lacks the delimiter.
Global Const $__eGOLDPARSER_gpMsgInternalError = 8 ; Something is wrong, very wrong.
Global Const $__eGOLDPARSER_gpMsgCommentBlockRead = 9 ; Added in version 2.4. This message is returned anytime a block comment is read by the system. When the system is reading a block comment, line comments are  completely ignored. The content of the block comment is stored in the CurrentComment( ) method.
Global Const $__eGOLDPARSER_gpMsgCommentLineRead = 10 ; Added In version 2.4. Each time the system reads a line comment, this message is returned. The content of the line comment is stored In the CurrentComment() method.

Global Const $__eGOLDPARSER_SymbolTypeNonterminal = 0 ; A normal nonterminal.
Global Const $__eGOLDPARSER_SymbolTypeTerminal = 1 ; A normal terminal.
Global Const $__eGOLDPARSER_SymbolTypeWhitespace = 2 ; This Whitespace symbols is a special terminal that is automatically ignored the the parsing engine. Any text accepted as whitespace is considered to be inconsequential and "meaningless".
Global Const $__eGOLDPARSER_SymbolTypeEnd = 3 ; The End symbol is generated when the tokenizer reaches the end of the source text.
Global Const $__eGOLDPARSER_SymbolTypeCommentStart = 4 ; This type of symbol designates the start of a block quote.
Global Const $__eGOLDPARSER_SymbolTypeCommentEnd = 5 ; This type of symbol designates the end of a block quote.
Global Const $__eGOLDPARSER_SymbolTypeCommentLine = 6 ; When the engine reads a token that is recognized as a line comment, the remaining characters on the line are automatically ignored by the parser.
Global Const $__eGOLDPARSER_SymbolTypeError = 7 ; The Error symbol is a general-purpose means of representing characters that were not recognized by the tokenizer. In other words, when the tokenizer reads a series of characters that is not accepted by the DFA engine, a token of this type is created.

_GP_Example_1()

Func _GP_Example_1()
    Local $oParser = ObjCreate("goldparserengine.goldparser") ; http://www.goldparser.org/engine/1/vb6/doc/object-goldparser.htm


    Local $iLoadStatus = $oParser.LoadCompiledGrammar(@ScriptDir & "\test_script.cgt")
    MsgBox(0, '$iLoadStatus', $iLoadStatus)

    Local $iOpenStatus = $oParser.OpenFile("Program.txt")
    MsgBox(0, '$iOpenStatus', $iOpenStatus)

    Local $iResponse = $oParser.Parse()
    MsgBox(0, '$iResponse', $iResponse)

    Switch $iResponse
        Case $__eGOLDPARSER_gpMsgTokenRead
            MsgBox(0, '$iResponse = $__eGOLDPARSER_gpMsgTokenRead', 'make some task..')

        Case Else
            ; .......

    EndSwitch

    ; CleanUp
    $oParser = ''
EndFunc   ;==>_GP_Example_1
Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

Now, my request to you:

Make a very little interesting example of how to use the "GOLD Parser" in practice.

edit:

of course make a litle description.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

(so the problem was that i must use the full path of the cgt file)

Now, my request to you:

Make a very little interesting example of how to use the "GOLD Parser" in practice.

 

well, i'm as far as knowing the basics of how to make a grammar and compile it to a cgt-file, load it into my script

and now i'm trying to use the documentation and good examples (if i find those) to make my test language work..

as soon as i have something working i will post it here (yes with comments or a description ;) ) but don't expect it to be done tomorrow  :)

i wanna thank you mlipok for the quick response,

i did't expect an answer because my question was so specific  :)

if there are people who can learn me about this things i wont hesitate to read all about it and in the meantime i'm coding in autoit to make a good test script.

regards!

Link to comment
Share on other sites

(so the problem was that i must use the full path of the cgt file)

 

 

well, i'm as far as knowing the basics of how to make a grammar and compile it to a cgt-file, load it into my script

and now i'm trying to use the documentation and good examples (if i find those) to make my test language work..

 

as soon as i have something working i will post it here (yes with comments or a description ;) ) but don't expect it to be done tomorrow  :)

 

Good.

I be waiting.

i wanna thank you mlipok for the quick response,

i did't expect an answer because my question was so specific  :)

 

You're welcome.

It seemed interesting so I got involved :)

 

If there are people who can learn me about this things i wont hesitate to read all about it and in the meantime i'm coding in autoit to make a good test script.

 

"about this things"

Can you be more specyfic ?

This time I gave a helping hand, I think only of you and your attitude depends on how many other / further hand you will be given.

Best regards,

mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

mlipok,

"about this things"

Can you be more specyfic ?

yes, sorry, about how to use the gold parser i mean  :)

at the moment i'm reading this:

http://www.goldparser.org/engine/1/vb6/doc/index.htm

and this:

http://www.codeproject.com/Articles/10492/Introduction-to-GOLD-Parser

and i am also trying to "decode" what's happening in the vb6 example project from here, i'm not a pro vb6 programmer:

http://www.goldparser.org/engine/1/vb6/index.htm

download: cook-project-simple-interpreter-v3.0.0

Link to comment
Share on other sites

sigh! had a long day today  :sweating:

i want to give the possible readers (especially mlipok) a quick update about today:

since my last answer i made a script to test if it is possible to use the gold parser engine in autoit.

the website says "All languages that support ActiveX" can use the gold parser so i did take a look

into the source code of an example interpreter made in vb6 using the activeX gold parser dll.

so far i have only created a skeleton program (that i will post here in a minute) and from that point ... i got stuck, which was a bit disappointing because

i didn't want to go back here until i got something working..  >_<

one of the problems is that vb6 is object-oriented and autoit is not, so i can't just copy and past most of the code because it works differently,

for example, this is a bit of vb code found back in "Allen-Benton-Simple-Interpreter-rev1.3":

...    With TheReduction
        Select Case .ParentRule.TableIndex
        Case Rule_Statements                 ' <Statements> ::= <Statement> <Statements>
            Set NewSimpleObject = New SimpleStmList
            Call NewSimpleObject.Init(.Tokens(0).Data, .Tokens(1).Data)
        
        Case Rule_Statements2                ' <Statements> ::= <Statement>
            Set NewSimpleObject = New SimpleStmList
            Call NewSimpleObject.Init(.Tokens(0).Data)
...

at this point even after all the research i have done i really don't know what is going on in the vb6 code  :wacko:

for every rule there is a new object made and initialized, and after that the "init" sub for that object is called, then there are a few tokens i think passed trough to that object?

i don't get how that can execute code that for example does this:

assign test = 1 + 2 * 3

which part of the code does the actual math on the resulting tokens and how does it know what to do with what?

i have a lot of questions so if someone can help me that would be very appreciated but i can't expect any help because this questions are not that autoit related..

at least here is the code i already have:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Debug.au3>

#Region GoldParser - Variables
Global Const $g__gpMsgTokenRead = 1 ; Each time a token is read, this message is generated.
Global Const $g__gpMsgReduction = 2 ; When the engine is able to reduce a rule, this message is returned. The rule that was reduced is set in the GOLDParser's ReduceRule property. The tokens that are reduced and correspond the rule's definition are stored in the Tokens() property.
Global Const $g__gpMsgAccept = 3 ; The engine will returns this message when the source text has been accepted as both complete and correct. In other words, the source text was successfully analyzed.
Global Const $g__gpMsgNotLoadedError = 4 ; Before any parsing can take place, a Compiled Grammar Table file must be loaded.
Global Const $g__gpMsgLexicalError = 5 ; The tokenizer will generate this message when it is unable to recognize a series of characters as a valid token. To recover, pop the invalid token from the input queue.
Global Const $g__gpMsgSyntaxError = 6 ; Often the parser will read a token that is not expected in the grammar. When this happens, the Tokens() property is filled with tokens the parsing engine expected to read. To recover: push one of the expected tokens on the input queue.
Global Const $g__gpMsgCommentError = 7 ; The parser reached the end of the file while reading a comment. This is caused when the source text contains a "run-away" comment, or in other words, a block comment that lacks the delimiter.
Global Const $g__gpMsgInternalError = 8 ; Something is wrong, very wrong.
Global Const $g__gpMsgCommentBlockRead = 9 ; Added in version 2.4. This message is returned anytime a block comment is read by the system. When the system is reading a block comment, line comments are  completely ignored. The content of the block comment is stored in the CurrentComment( ) method.
Global Const $g__gpMsgCommentLineRead = 10 ; Added In version 2.4. Each time the system reads a line comment, this message is returned. The content of the line comment is stored In the CurrentComment() method.

Global Const $g__gpSymbolTypeNonterminal = 0 ; A normal nonterminal.
Global Const $g__gpSymbolTypeTerminal = 1 ; A normal terminal.
Global Const $g__gpSymbolTypeWhitespace = 2 ; This Whitespace symbols is a special terminal that is automatically ignored the the parsing engine. Any text accepted as whitespace is considered to be inconsequential and "meaningless".
Global Const $g__gpSymbolTypeEnd = 3 ; The End symbol is generated when the tokenizer reaches the end of the source text.
Global Const $g__gpSymbolTypeCommentStart = 4 ; This type of symbol designates the start of a block quote.
Global Const $g__gpSymbolTypeCommentEnd = 5 ; This type of symbol designates the end of a block quote.
Global Const $g__gpSymbolTypeCommentLine = 6 ; When the engine reads a token that is recognized as a line comment, the remaining characters on the line are automatically ignored by the parser.
Global Const $g__gpSymbolTypeError = 7 ; The Error symbol is a general-purpose means of representing characters that were not recognized by the tokenizer. In other words, when the tokenizer reads a series of characters that is not accepted by the DFA engine, a token of this type is created.

Global Const $g__gpRule_Statements1 = 0 ; <statements>  ::= <statement> <statements>
Global Const $g__gpRule_Statements2 = 1 ; <statements>  ::= <statement>
Global Const $g__gpRule_Statement_NameIsExpression = 2 ; <statement>   ::= name '=' <expression>
Global Const $g__gpRule_Statement_MsgExpression = 3 ; <statement>   ::= msg <expression>
Global Const $g__gpRule_Statement_IfThenEnd = 4 ; <statement>   ::= if <expression> then <statements> end
Global Const $g__gpRule_Statement_IfThenElseEnd = 5 ; <statement>   ::= if <expression> then <statements> else <statements> end
Global Const $g__gpRule_Expression_BiggerThen = 6 ; <expression>  ::= <expression> '>' <add exp>
Global Const $g__gpRule_Expression_SmallerThen = 7 ; <expression>  ::= <expression> '<' <add exp>
Global Const $g__gpRule_Expression_BiggerEqualThen1 = 8 ; <expression>  ::= <expression> '<=' <add exp>
Global Const $g__gpRule_Expression_BiggerEqualThen2 = 9 ; <expression>  ::= <expression> '>=' <add exp>
Global Const $g__gpRule_Expression_SmallerEqualThen1 = 10; <expression>  ::= <expression> '=>' <add exp>
Global Const $g__gpRule_Expression_SmallerEqualThen2 = 11; <expression>  ::= <expression> '=<' <add exp>
Global Const $g__gpRule_Expression_EqualThen = 12 ; <expression>  ::= <expression> '=' <add exp>
Global Const $g__gpRule_Expression_NotEqualThen = 13 ; <expression>  ::= <expression> '!' <add exp>
Global Const $g__gpRule_Expression = 14 ; <expression>  ::= <add exp>
Global Const $g__gpRule_Add_Plus = 15 ; <add exp>     ::= <add exp> '+' <mult exp>
Global Const $g__gpRule_Add_Minus = 16 ; <add exp>     ::= <add exp> '-' <mult exp>
Global Const $g__gpRule_Add_Amp = 17 ; <add exp>     ::= <add exp> '&' <mult exp>
Global Const $g__gpRule_Add_Expression = 18 ; <add exp>     ::= <mult exp>
Global Const $g__gpRule_Mult_Mult = 19 ; <mult exp>    ::= <mult exp> '*' <value>
Global Const $g__gpRule_Mult_Div = 20 ; <mult exp>    ::= <mult exp> '/' <value>
Global Const $g__gpRule_Mult_Value = 21 ; <mult exp>    ::= <value>
Global Const $g__gpRule_Value_Name = 22 ; <value>       ::= name
Global Const $g__gpRule_Value_String = 23 ; <value>       ::= string
Global Const $g__gpRule_Value_Number = 24 ; <value>       ::= number
Global Const $g__gpRule_Value_GroupedExpression = 25 ; <value>       ::= '(' <expression> ')'
#EndRegion GoldParser - Variables

_DebugSetup(Default, True, 1, Default, True) ; 1 = GUI output with timestamping

Global $oVariables = ObjCreate("scripting.dictionary")
$oVariables.CompareMode = 1

Example()

Func Example()
    ; Set up the COM error handler to write error messages using a GUI and exit on error
    _DebugCOMError(1)

    Local $hGUI = GUICreate("Form", 611, 431, 100, 0)
    WinMove($__gsReportTitle_Debug, '', 611 + 106, 0)
    #forceref $hGUI

    Local $idEdit_In = GUICtrlCreateEdit("a = 1", 10, 10, 301, 411)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0x00FF00)
    GUICtrlSetBkColor(-1, 0x464646)
    GUICtrlSetCursor(-1, 5)

;~  $idEdit_Out = GUICtrlCreateEdit("", 320, 210, 281, 211, BitOR($ES_READONLY,$ES_WANTRETURN)) ; for some reason i hear windows ding.wav going of like crazy if i push the run button with this rule of code?
    Local $idEdit_Out = GUICtrlCreateEdit("", 320, 210, 281, 211)
    GUICtrlSetColor(-1, 0xFF0000)
    GUICtrlSetBkColor(-1, 0x000000)

    Local $idButton_Test = GUICtrlCreateButton("test", 320, 10, 281, 41)
    Local $idButton_Run = GUICtrlCreateButton("run", 320, 60, 281, 41)
    Local $idButton_Clean = GUICtrlCreateButton("clean", 320, 110, 281, 41)
    Local $idButton_Quit = GUICtrlCreateButton("quit", 320, 160, 281, 41)

    GUISetState(@SW_SHOW)


    Local $oParser = ObjCreate("goldparserengine.goldparser")
    Local $bLoadStatus = $oParser.LoadCompiledGrammar(@ScriptDir & "\test_script.cgt");~ $OpenStatus = $oParser.OpenFile("Program.txt")
    _DebugOut('$bLoadStatus=' & $bLoadStatus)
    $oParser.TrimReductions = True

    Local $iResponse
    Local $bDone, $bReadStatus
    While True
        Switch GUIGetMsg()

            Case $GUI_EVENT_CLOSE, $idButton_Quit
                ExitLoop

            Case $idButton_Clean
                GUICtrlSetData($idEdit_Out, '')

            Case $idButton_Test
                GUICtrlSetData($idEdit_Out, '')
                $bDone = False
                $bReadStatus = $oParser.OpenTextString(GUICtrlRead($idEdit_In))
                _DebugOut('$bReadStatus=' & $bReadStatus)
                Do
                    $iResponse = $oParser.Parse()

                    Switch $iResponse
                        Case $g__gpMsgLexicalError
                            _DebugOut('Illegal or unrecognized token!', True)
                        Case $g__gpMsgSyntaxError
                            _DebugOut('Token not expected!', True)
                        Case $g__gpMsgCommentError
                            _DebugOut('Comment was not terminated!', True)
                        Case $g__gpMsgInternalError
                            _DebugOut('Something horrid happened inside the parser!', True)
                        Case $g__gpMsgNotLoadedError
                            _DebugOut('Compiled grammar not loaded!', True)

                        Case $g__gpMsgTokenRead
                            _DebugOut('[CURRENT TOKEN]=[' & $oParser.CurrentToken.Name & ']')
                        Case $g__gpMsgCommentBlockRead
                            _DebugOut("This script can't contain block comments!", True)
                        Case $g__gpMsgCommentLineRead
                            ;comment line read..
                        Case $g__gpMsgReduction
;~                      _DebugOut('$g__gpMsgReduction='& $oParser.CurrentReduction.ParentRule.TableIndex)

                            Switch $oParser.CurrentReduction.ParentRule.TableIndex ;stuck here
                                Case $g__gpRule_Statements1

                                Case $g__gpRule_Statements2

                                Case $g__gpRule_Statement_NameIsExpression

                                Case $g__gpRule_Statement_MsgExpression

                                Case $g__gpRule_Statement_IfThenEnd

                                Case $g__gpRule_Statement_IfThenElseEnd

                                Case $g__gpRule_Expression_BiggerThen, $g__gpRule_Expression_SmallerThen, $g__gpRule_Expression_BiggerEqualThen1, $g__gpRule_Expression_BiggerEqualThen2, $g__gpRule_Expression_SmallerEqualThen1, $g__gpRule_Expression_SmallerEqualThen2, $g__gpRule_Expression_EqualThen, $g__gpRule_Expression_NotEqualThen

                                Case $g__gpRule_Add_Plus

                                Case $g__gpRule_Add_Minus

                                Case $g__gpRule_Add_Amp

                                Case $g__gpRule_Mult_Mult

                                Case $g__gpRule_Mult_Div

                                Case $g__gpRule_Mult_Value

                                Case $g__gpRule_Value_Name

                                Case $g__gpRule_Value_String

                                Case $g__gpRule_Value_Number

                                Case $g__gpRule_Value_GroupedExpression
                                    ; this 2 case options are ignored because of "TrimReductions = True"
                                    ; Case $g__gpRule_Expression
                                    ; Case $g__gpRule_Add_Expression
                            EndSwitch

                        Case $g__gpMsgAccept
                            _DebugOut('Done!')
                            $bDone = True

                    EndSwitch

                Until $bDone = True

            Case $idButton_Run
                ;...
        EndSwitch
    WEnd

    ; CleanUp
    WinClose($__gsReportTitle_Debug)
    _DebugCOMError(0)
    $oParser = ''

EndFunc   ;==>Example

TheAutomator.

Edited by TheAutomator
Link to comment
Share on other sites

  • 2 weeks later...

It is good news.

So keep on.
And I'm keeping my fingers crossed.
 
mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

Update:

I maybe have some bad news...

I successfully wrote a programming language grammar in 'BNF' and i also made a working interpreter for it in vbscript.

The way you have to work with the activeX version of the gold parser:

load gold parser object.

load grammar.

load test script you made for the grammar.

gold parser makes AST.

you have to map every node of the AST by replacing it with your own customized class.

when done execute the class code of the root node.

 

      Case gpMsgReduction
         'This message is returned when a rule was reduced by the parse engine.
        'The CurrentReduction property is assigned a Reduction object
        'containing the rule and its related tokens. You can reassign this
        'property to your own customized class. If this is not the case,
         'this message can be ignored and the Reduction object will be used
        'to store the parse tree.       
         Select Case Parser.CurrentReduction.ParentRule.TableIndex
           ...
         End Select

         Parser.CurrentReduction = 'Object you created to store the rule

 

AutoIt is not able to make its own classes so i guess it ends here?

[EDIT:]

I'm not saying i give up on this.

Maybe there is some way to fill a customized AST (some array or something) with references to functions.  :think:

Let me think about it, do some tests if i have time, ill post when i know something more  :)

Regards,

TheAutomator

Edited by TheAutomator
Link to comment
Share on other sites

  • 2 weeks later...

Ok, for people that want to make a more advanced interpreter i recommend vb6 or vbscript or any other language that is object-oriented...

I made the most useless scripting language in the world (i guess) as an example, its called "TO TINY" and that's what it is  :D.

you can only assign numeric variables and show them in a message.

here an example script:

test = 5
lol = 100

msg test
msg lol

source code is in the attachments  :)

(rename "TOTINY.cgt.txt" to "TOTINY.cgt")

If someone finds a way to make a more advanced language without classes then please let me know  ;)

regards

TheAutomator.

INTERPRETER.au3

totiny.ico

TOTINY.cgt.txt

Edited by TheAutomator
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...